Lines Matching +full:uart +full:- +full:routing
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) by Paul Barton-Davis 1998-1999
8 * Note that there is also an MPU-401 emulation (actually, a UART-401
12 * The interface is essentially just a UART-401, but is has the
22 * MIDI routing, 16 to the WaveFront synth and 16 to the external MIDI
25 * something other than 0 and 1 if the CS4232 UART/MPU-401 interface
40 * completely independent 16-channel MIDI buses, one to the
58 return inb (midi->mpu_status_port); in wf_mpu_status()
79 return inb (midi->mpu_data_port); in read_data()
86 outb (byte, midi->mpu_data_port); in write_data()
96 if (substream == NULL || substream->rmidi == NULL) in get_wavefront_midi()
99 card = substream->rmidi->card; in get_wavefront_midi()
104 if (card->private_data == NULL) in get_wavefront_midi()
107 acard = card->private_data; in get_wavefront_midi()
109 return &acard->wavefront.midi; in get_wavefront_midi()
114 snd_wavefront_midi_t *midi = &card->wavefront.midi; in snd_wavefront_midi_output_write()
132 if (midi->substream_output[midi->output_mpu] == NULL) { in snd_wavefront_midi_output_write()
138 /* XXX fix me - no hard timing loops allowed! */ in snd_wavefront_midi_output_write()
140 for (timeout = 30000; timeout > 0; timeout--) { in snd_wavefront_midi_output_write()
145 spin_lock_irqsave (&midi->virtual, flags); in snd_wavefront_midi_output_write()
146 if ((midi->mode[midi->output_mpu] & MPU401_MODE_OUTPUT) == 0) { in snd_wavefront_midi_output_write()
147 spin_unlock_irqrestore (&midi->virtual, flags); in snd_wavefront_midi_output_write()
151 if (snd_rawmidi_transmit(midi->substream_output[midi->output_mpu], &midi_byte, 1) == 1) { in snd_wavefront_midi_output_write()
152 if (!midi->isvirtual || in snd_wavefront_midi_output_write()
156 max--; in snd_wavefront_midi_output_write()
158 if (midi->istimer) { in snd_wavefront_midi_output_write()
159 if (--midi->istimer <= 0) in snd_wavefront_midi_output_write()
160 del_timer(&midi->timer); in snd_wavefront_midi_output_write()
162 midi->mode[midi->output_mpu] &= ~MPU401_MODE_OUTPUT_TRIGGER; in snd_wavefront_midi_output_write()
163 spin_unlock_irqrestore (&midi->virtual, flags); in snd_wavefront_midi_output_write()
167 spin_unlock_irqrestore (&midi->virtual, flags); in snd_wavefront_midi_output_write()
170 spin_unlock_irqrestore (&midi->virtual, flags); in snd_wavefront_midi_output_write()
175 if (midi->substream_output[!midi->output_mpu] == NULL) { in snd_wavefront_midi_output_write()
181 /* XXX fix me - no hard timing loops allowed! */ in snd_wavefront_midi_output_write()
183 for (timeout = 30000; timeout > 0; timeout--) { in snd_wavefront_midi_output_write()
188 spin_lock_irqsave (&midi->virtual, flags); in snd_wavefront_midi_output_write()
189 if (!midi->isvirtual) in snd_wavefront_midi_output_write()
191 mpu = midi->output_mpu ^ mask; in snd_wavefront_midi_output_write()
193 if ((midi->mode[mpu] & MPU401_MODE_OUTPUT) == 0) { in snd_wavefront_midi_output_write()
194 spin_unlock_irqrestore (&midi->virtual, flags); in snd_wavefront_midi_output_write()
197 if (snd_rawmidi_transmit_empty(midi->substream_output[mpu])) in snd_wavefront_midi_output_write()
200 if (mpu != midi->output_mpu) { in snd_wavefront_midi_output_write()
204 midi->output_mpu = mpu; in snd_wavefront_midi_output_write()
205 } else if (snd_rawmidi_transmit(midi->substream_output[mpu], &midi_byte, 1) == 1) { in snd_wavefront_midi_output_write()
206 if (!midi->isvirtual || in snd_wavefront_midi_output_write()
210 max--; in snd_wavefront_midi_output_write()
213 if (midi->istimer) { in snd_wavefront_midi_output_write()
214 if (--midi->istimer <= 0) in snd_wavefront_midi_output_write()
215 del_timer(&midi->timer); in snd_wavefront_midi_output_write()
217 midi->mode[mpu] &= ~MPU401_MODE_OUTPUT_TRIGGER; in snd_wavefront_midi_output_write()
218 spin_unlock_irqrestore (&midi->virtual, flags); in snd_wavefront_midi_output_write()
222 spin_unlock_irqrestore (&midi->virtual, flags); in snd_wavefront_midi_output_write()
225 spin_unlock_irqrestore (&midi->virtual, flags); in snd_wavefront_midi_output_write()
235 if (snd_BUG_ON(!substream || !substream->rmidi)) in snd_wavefront_midi_input_open()
236 return -ENXIO; in snd_wavefront_midi_input_open()
237 if (snd_BUG_ON(!substream->rmidi->private_data)) in snd_wavefront_midi_input_open()
238 return -ENXIO; in snd_wavefront_midi_input_open()
240 mpu = *((snd_wavefront_mpu_id *) substream->rmidi->private_data); in snd_wavefront_midi_input_open()
244 return -EIO; in snd_wavefront_midi_input_open()
246 spin_lock_irqsave (&midi->open, flags); in snd_wavefront_midi_input_open()
247 midi->mode[mpu] |= MPU401_MODE_INPUT; in snd_wavefront_midi_input_open()
248 midi->substream_input[mpu] = substream; in snd_wavefront_midi_input_open()
249 spin_unlock_irqrestore (&midi->open, flags); in snd_wavefront_midi_input_open()
260 if (snd_BUG_ON(!substream || !substream->rmidi)) in snd_wavefront_midi_output_open()
261 return -ENXIO; in snd_wavefront_midi_output_open()
262 if (snd_BUG_ON(!substream->rmidi->private_data)) in snd_wavefront_midi_output_open()
263 return -ENXIO; in snd_wavefront_midi_output_open()
265 mpu = *((snd_wavefront_mpu_id *) substream->rmidi->private_data); in snd_wavefront_midi_output_open()
269 return -EIO; in snd_wavefront_midi_output_open()
271 spin_lock_irqsave (&midi->open, flags); in snd_wavefront_midi_output_open()
272 midi->mode[mpu] |= MPU401_MODE_OUTPUT; in snd_wavefront_midi_output_open()
273 midi->substream_output[mpu] = substream; in snd_wavefront_midi_output_open()
274 spin_unlock_irqrestore (&midi->open, flags); in snd_wavefront_midi_output_open()
285 if (snd_BUG_ON(!substream || !substream->rmidi)) in snd_wavefront_midi_input_close()
286 return -ENXIO; in snd_wavefront_midi_input_close()
287 if (snd_BUG_ON(!substream->rmidi->private_data)) in snd_wavefront_midi_input_close()
288 return -ENXIO; in snd_wavefront_midi_input_close()
290 mpu = *((snd_wavefront_mpu_id *) substream->rmidi->private_data); in snd_wavefront_midi_input_close()
294 return -EIO; in snd_wavefront_midi_input_close()
296 spin_lock_irqsave (&midi->open, flags); in snd_wavefront_midi_input_close()
297 midi->mode[mpu] &= ~MPU401_MODE_INPUT; in snd_wavefront_midi_input_close()
298 spin_unlock_irqrestore (&midi->open, flags); in snd_wavefront_midi_input_close()
309 if (snd_BUG_ON(!substream || !substream->rmidi)) in snd_wavefront_midi_output_close()
310 return -ENXIO; in snd_wavefront_midi_output_close()
311 if (snd_BUG_ON(!substream->rmidi->private_data)) in snd_wavefront_midi_output_close()
312 return -ENXIO; in snd_wavefront_midi_output_close()
314 mpu = *((snd_wavefront_mpu_id *) substream->rmidi->private_data); in snd_wavefront_midi_output_close()
318 return -EIO; in snd_wavefront_midi_output_close()
320 spin_lock_irqsave (&midi->open, flags); in snd_wavefront_midi_output_close()
321 midi->mode[mpu] &= ~MPU401_MODE_OUTPUT; in snd_wavefront_midi_output_close()
322 spin_unlock_irqrestore (&midi->open, flags); in snd_wavefront_midi_output_close()
332 if (substream == NULL || substream->rmidi == NULL) in snd_wavefront_midi_input_trigger()
335 if (substream->rmidi->private_data == NULL) in snd_wavefront_midi_input_trigger()
338 mpu = *((snd_wavefront_mpu_id *) substream->rmidi->private_data); in snd_wavefront_midi_input_trigger()
344 spin_lock_irqsave (&midi->virtual, flags); in snd_wavefront_midi_input_trigger()
346 midi->mode[mpu] |= MPU401_MODE_INPUT_TRIGGER; in snd_wavefront_midi_input_trigger()
348 midi->mode[mpu] &= ~MPU401_MODE_INPUT_TRIGGER; in snd_wavefront_midi_input_trigger()
350 spin_unlock_irqrestore (&midi->virtual, flags); in snd_wavefront_midi_input_trigger()
356 snd_wavefront_card_t *card = midi->timer_card; in snd_wavefront_midi_output_timer()
359 spin_lock_irqsave (&midi->virtual, flags); in snd_wavefront_midi_output_timer()
360 mod_timer(&midi->timer, 1 + jiffies); in snd_wavefront_midi_output_timer()
361 spin_unlock_irqrestore (&midi->virtual, flags); in snd_wavefront_midi_output_timer()
371 if (substream == NULL || substream->rmidi == NULL) in snd_wavefront_midi_output_trigger()
374 if (substream->rmidi->private_data == NULL) in snd_wavefront_midi_output_trigger()
377 mpu = *((snd_wavefront_mpu_id *) substream->rmidi->private_data); in snd_wavefront_midi_output_trigger()
383 spin_lock_irqsave (&midi->virtual, flags); in snd_wavefront_midi_output_trigger()
385 if ((midi->mode[mpu] & MPU401_MODE_OUTPUT_TRIGGER) == 0) { in snd_wavefront_midi_output_trigger()
386 if (!midi->istimer) { in snd_wavefront_midi_output_trigger()
387 timer_setup(&midi->timer, in snd_wavefront_midi_output_trigger()
390 mod_timer(&midi->timer, 1 + jiffies); in snd_wavefront_midi_output_trigger()
392 midi->istimer++; in snd_wavefront_midi_output_trigger()
393 midi->mode[mpu] |= MPU401_MODE_OUTPUT_TRIGGER; in snd_wavefront_midi_output_trigger()
396 midi->mode[mpu] &= ~MPU401_MODE_OUTPUT_TRIGGER; in snd_wavefront_midi_output_trigger()
398 spin_unlock_irqrestore (&midi->virtual, flags); in snd_wavefront_midi_output_trigger()
401 snd_wavefront_midi_output_write((snd_wavefront_card_t *)substream->rmidi->card->private_data); in snd_wavefront_midi_output_trigger()
415 midi = &card->wavefront.midi; in snd_wavefront_midi_interrupt()
422 spin_lock_irqsave (&midi->virtual, flags); in snd_wavefront_midi_interrupt()
423 while (--max) { in snd_wavefront_midi_interrupt()
428 if (midi->isvirtual) { in snd_wavefront_midi_interrupt()
430 substream = midi->substream_input[external_mpu]; in snd_wavefront_midi_interrupt()
433 substream = midi->substream_output[internal_mpu]; in snd_wavefront_midi_interrupt()
437 substream = midi->substream_input[internal_mpu]; in snd_wavefront_midi_interrupt()
445 if (midi->mode[mpu] & MPU401_MODE_INPUT_TRIGGER) { in snd_wavefront_midi_interrupt()
452 spin_unlock_irqrestore (&midi->virtual, flags); in snd_wavefront_midi_interrupt()
463 spin_lock_irqsave (&card->wavefront.midi.virtual, flags); in snd_wavefront_midi_enable_virtual()
464 card->wavefront.midi.isvirtual = 1; in snd_wavefront_midi_enable_virtual()
465 card->wavefront.midi.output_mpu = internal_mpu; in snd_wavefront_midi_enable_virtual()
466 card->wavefront.midi.input_mpu = internal_mpu; in snd_wavefront_midi_enable_virtual()
467 spin_unlock_irqrestore (&card->wavefront.midi.virtual, flags); in snd_wavefront_midi_enable_virtual()
476 spin_lock_irqsave (&card->wavefront.midi.virtual, flags); in snd_wavefront_midi_disable_virtual()
477 // snd_wavefront_midi_input_close (card->ics2115_external_rmidi); in snd_wavefront_midi_disable_virtual()
478 // snd_wavefront_midi_output_close (card->ics2115_external_rmidi); in snd_wavefront_midi_disable_virtual()
479 card->wavefront.midi.isvirtual = 0; in snd_wavefront_midi_disable_virtual()
480 spin_unlock_irqrestore (&card->wavefront.midi.virtual, flags); in snd_wavefront_midi_disable_virtual()
492 dev = &card->wavefront; in snd_wavefront_midi_start()
493 midi = &dev->midi; in snd_wavefront_midi_start()
495 /* The ICS2115 MPU-401 interface doesn't do anything in snd_wavefront_midi_start()
496 until its set into UART mode. in snd_wavefront_midi_start()
499 /* XXX fix me - no hard timing loops allowed! */ in snd_wavefront_midi_start()
504 dev_err(card->wavefront.card->dev, in snd_wavefront_midi_start()
506 return -1; in snd_wavefront_midi_start()
513 dev->interrupts_are_midi = 1; in snd_wavefront_midi_start()
515 outb (UART_MODE_ON, midi->mpu_command_port); in snd_wavefront_midi_start()
517 for (ok = 0, i = 50000; i > 0 && !ok; i--) { in snd_wavefront_midi_start()
527 dev_err(card->wavefront.card->dev, in snd_wavefront_midi_start()
528 "cannot set UART mode for MIDI interface"); in snd_wavefront_midi_start()
529 dev->interrupts_are_midi = 0; in snd_wavefront_midi_start()
530 return -1; in snd_wavefront_midi_start()
536 dev_warn(card->wavefront.card->dev, in snd_wavefront_midi_start()
537 "can't enable MIDI-IN-2-synth routing.\n"); in snd_wavefront_midi_start()
553 dev_warn(card->wavefront.card->dev, in snd_wavefront_midi_start()
561 dev_warn(card->wavefront.card->dev, in snd_wavefront_midi_start()