^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) by Paul Barton-Davis 1998-1999
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) /* The low level driver for the WaveFront ICS2115 MIDI interface(s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Note that there is also an MPU-401 emulation (actually, a UART-401
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * emulation) on the CS4232 on the Tropez and Tropez Plus. This code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * has nothing to do with that interface at all.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * The interface is essentially just a UART-401, but is has the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * interesting property of supporting what Turtle Beach called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * "Virtual MIDI" mode. In this mode, there are effectively *two*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * MIDI buses accessible via the interface, one that is routed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * solely to/from the external WaveFront synthesizer and the other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * corresponding to the pin/socket connector used to link external
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * MIDI devices to the board.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * This driver fully supports this mode, allowing two distinct MIDI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * busses to be used completely independently, giving 32 channels of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * MIDI routing, 16 to the WaveFront synth and 16 to the external MIDI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * bus. The devices are named /dev/snd/midiCnD0 and /dev/snd/midiCnD1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * where `n' is the card number. Note that the device numbers may be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * something other than 0 and 1 if the CS4232 UART/MPU-401 interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * is enabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * Switching between the two is accomplished externally by the driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * using the two otherwise unused MIDI bytes. See the code for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * NOTE: VIRTUAL MIDI MODE IS ON BY DEFAULT (see lowlevel/isa/wavefront.c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * The main reason to turn off Virtual MIDI mode is when you want to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * tightly couple the WaveFront synth with an external MIDI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * device. You won't be able to distinguish the source of any MIDI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * data except via SysEx ID, but thats probably OK, since for the most
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * part, the WaveFront won't be sending any MIDI data at all.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * The main reason to turn on Virtual MIDI Mode is to provide two
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * completely independent 16-channel MIDI buses, one to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * WaveFront and one to any external MIDI devices. Given the 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * voice nature of the WaveFront, its pretty easy to find a use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * for all 16 channels driving just that synth.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #include <linux/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #include <linux/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #include <sound/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #include <sound/snd_wavefront.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) wf_mpu_status (snd_wavefront_midi_t *midi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) return inb (midi->mpu_status_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) input_avail (snd_wavefront_midi_t *midi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) return !(wf_mpu_status(midi) & INPUT_AVAIL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) output_ready (snd_wavefront_midi_t *midi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) return !(wf_mpu_status(midi) & OUTPUT_READY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) read_data (snd_wavefront_midi_t *midi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) return inb (midi->mpu_data_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) write_data (snd_wavefront_midi_t *midi, unsigned char byte)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) outb (byte, midi->mpu_data_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) static snd_wavefront_midi_t *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) get_wavefront_midi (struct snd_rawmidi_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) struct snd_card *card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) snd_wavefront_card_t *acard;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) if (substream == NULL || substream->rmidi == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) card = substream->rmidi->card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) if (card == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) if (card->private_data == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) acard = card->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) return &acard->wavefront.midi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static void snd_wavefront_midi_output_write(snd_wavefront_card_t *card)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) snd_wavefront_midi_t *midi = &card->wavefront.midi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) snd_wavefront_mpu_id mpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) unsigned char midi_byte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) int max = 256, mask = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) int timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) /* Its not OK to try to change the status of "virtuality" of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) the MIDI interface while we're outputting stuff. See
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) snd_wavefront_midi_{enable,disable}_virtual () for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) other half of this.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) The first loop attempts to flush any data from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) current output device, and then the second
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) emits the switch byte (if necessary), and starts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) outputting data for the output device currently in use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) if (midi->substream_output[midi->output_mpu] == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) goto __second;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) while (max > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) /* XXX fix me - no hard timing loops allowed! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) for (timeout = 30000; timeout > 0; timeout--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) if (output_ready (midi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) spin_lock_irqsave (&midi->virtual, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) if ((midi->mode[midi->output_mpu] & MPU401_MODE_OUTPUT) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) spin_unlock_irqrestore (&midi->virtual, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) goto __second;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) if (output_ready (midi)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) if (snd_rawmidi_transmit(midi->substream_output[midi->output_mpu], &midi_byte, 1) == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) if (!midi->isvirtual ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) (midi_byte != WF_INTERNAL_SWITCH &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) midi_byte != WF_EXTERNAL_SWITCH))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) write_data(midi, midi_byte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) max--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) if (midi->istimer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) if (--midi->istimer <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) del_timer(&midi->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) midi->mode[midi->output_mpu] &= ~MPU401_MODE_OUTPUT_TRIGGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) spin_unlock_irqrestore (&midi->virtual, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) goto __second;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) spin_unlock_irqrestore (&midi->virtual, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) spin_unlock_irqrestore (&midi->virtual, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) __second:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) if (midi->substream_output[!midi->output_mpu] == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) while (max > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) /* XXX fix me - no hard timing loops allowed! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) for (timeout = 30000; timeout > 0; timeout--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) if (output_ready (midi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) spin_lock_irqsave (&midi->virtual, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) if (!midi->isvirtual)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) mask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) mpu = midi->output_mpu ^ mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) mask = 0; /* don't invert the value from now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) if ((midi->mode[mpu] & MPU401_MODE_OUTPUT) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) spin_unlock_irqrestore (&midi->virtual, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) if (snd_rawmidi_transmit_empty(midi->substream_output[mpu]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) goto __timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) if (output_ready (midi)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) if (mpu != midi->output_mpu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) write_data(midi, mpu == internal_mpu ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) WF_INTERNAL_SWITCH :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) WF_EXTERNAL_SWITCH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) midi->output_mpu = mpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) } else if (snd_rawmidi_transmit(midi->substream_output[mpu], &midi_byte, 1) == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) if (!midi->isvirtual ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) (midi_byte != WF_INTERNAL_SWITCH &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) midi_byte != WF_EXTERNAL_SWITCH))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) write_data(midi, midi_byte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) max--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) __timer:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) if (midi->istimer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) if (--midi->istimer <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) del_timer(&midi->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) midi->mode[mpu] &= ~MPU401_MODE_OUTPUT_TRIGGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) spin_unlock_irqrestore (&midi->virtual, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) spin_unlock_irqrestore (&midi->virtual, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) spin_unlock_irqrestore (&midi->virtual, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) static int snd_wavefront_midi_input_open(struct snd_rawmidi_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) snd_wavefront_midi_t *midi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) snd_wavefront_mpu_id mpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) if (snd_BUG_ON(!substream || !substream->rmidi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) if (snd_BUG_ON(!substream->rmidi->private_data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) mpu = *((snd_wavefront_mpu_id *) substream->rmidi->private_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) if ((midi = get_wavefront_midi (substream)) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) spin_lock_irqsave (&midi->open, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) midi->mode[mpu] |= MPU401_MODE_INPUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) midi->substream_input[mpu] = substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) spin_unlock_irqrestore (&midi->open, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) static int snd_wavefront_midi_output_open(struct snd_rawmidi_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) snd_wavefront_midi_t *midi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) snd_wavefront_mpu_id mpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) if (snd_BUG_ON(!substream || !substream->rmidi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) if (snd_BUG_ON(!substream->rmidi->private_data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) mpu = *((snd_wavefront_mpu_id *) substream->rmidi->private_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) if ((midi = get_wavefront_midi (substream)) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) spin_lock_irqsave (&midi->open, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) midi->mode[mpu] |= MPU401_MODE_OUTPUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) midi->substream_output[mpu] = substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) spin_unlock_irqrestore (&midi->open, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) static int snd_wavefront_midi_input_close(struct snd_rawmidi_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) snd_wavefront_midi_t *midi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) snd_wavefront_mpu_id mpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) if (snd_BUG_ON(!substream || !substream->rmidi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) if (snd_BUG_ON(!substream->rmidi->private_data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) mpu = *((snd_wavefront_mpu_id *) substream->rmidi->private_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) if ((midi = get_wavefront_midi (substream)) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) spin_lock_irqsave (&midi->open, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) midi->mode[mpu] &= ~MPU401_MODE_INPUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) spin_unlock_irqrestore (&midi->open, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) static int snd_wavefront_midi_output_close(struct snd_rawmidi_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) snd_wavefront_midi_t *midi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) snd_wavefront_mpu_id mpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) if (snd_BUG_ON(!substream || !substream->rmidi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) if (snd_BUG_ON(!substream->rmidi->private_data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) mpu = *((snd_wavefront_mpu_id *) substream->rmidi->private_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) if ((midi = get_wavefront_midi (substream)) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) spin_lock_irqsave (&midi->open, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) midi->mode[mpu] &= ~MPU401_MODE_OUTPUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) spin_unlock_irqrestore (&midi->open, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) static void snd_wavefront_midi_input_trigger(struct snd_rawmidi_substream *substream, int up)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) snd_wavefront_midi_t *midi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) snd_wavefront_mpu_id mpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) if (substream == NULL || substream->rmidi == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) if (substream->rmidi->private_data == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) mpu = *((snd_wavefront_mpu_id *) substream->rmidi->private_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) if ((midi = get_wavefront_midi (substream)) == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) spin_lock_irqsave (&midi->virtual, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) if (up) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) midi->mode[mpu] |= MPU401_MODE_INPUT_TRIGGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) midi->mode[mpu] &= ~MPU401_MODE_INPUT_TRIGGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) spin_unlock_irqrestore (&midi->virtual, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) static void snd_wavefront_midi_output_timer(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) snd_wavefront_midi_t *midi = from_timer(midi, t, timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) snd_wavefront_card_t *card = midi->timer_card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) spin_lock_irqsave (&midi->virtual, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) mod_timer(&midi->timer, 1 + jiffies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) spin_unlock_irqrestore (&midi->virtual, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) snd_wavefront_midi_output_write(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) static void snd_wavefront_midi_output_trigger(struct snd_rawmidi_substream *substream, int up)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) snd_wavefront_midi_t *midi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) snd_wavefront_mpu_id mpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) if (substream == NULL || substream->rmidi == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) if (substream->rmidi->private_data == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) mpu = *((snd_wavefront_mpu_id *) substream->rmidi->private_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) if ((midi = get_wavefront_midi (substream)) == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) spin_lock_irqsave (&midi->virtual, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) if (up) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) if ((midi->mode[mpu] & MPU401_MODE_OUTPUT_TRIGGER) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) if (!midi->istimer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) timer_setup(&midi->timer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) snd_wavefront_midi_output_timer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) mod_timer(&midi->timer, 1 + jiffies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) midi->istimer++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) midi->mode[mpu] |= MPU401_MODE_OUTPUT_TRIGGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) midi->mode[mpu] &= ~MPU401_MODE_OUTPUT_TRIGGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) spin_unlock_irqrestore (&midi->virtual, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) if (up)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) snd_wavefront_midi_output_write((snd_wavefront_card_t *)substream->rmidi->card->private_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) snd_wavefront_midi_interrupt (snd_wavefront_card_t *card)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) snd_wavefront_midi_t *midi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) static struct snd_rawmidi_substream *substream = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) static int mpu = external_mpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) int max = 128;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) unsigned char byte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) midi = &card->wavefront.midi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) if (!input_avail (midi)) { /* not for us */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) snd_wavefront_midi_output_write(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) spin_lock_irqsave (&midi->virtual, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) while (--max) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) if (input_avail (midi)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) byte = read_data (midi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) if (midi->isvirtual) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) if (byte == WF_EXTERNAL_SWITCH) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) substream = midi->substream_input[external_mpu];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) mpu = external_mpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) } else if (byte == WF_INTERNAL_SWITCH) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) substream = midi->substream_output[internal_mpu];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) mpu = internal_mpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) } /* else just leave it as it is */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) substream = midi->substream_input[internal_mpu];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) mpu = internal_mpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) if (substream == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) if (midi->mode[mpu] & MPU401_MODE_INPUT_TRIGGER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) snd_rawmidi_receive(substream, &byte, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) spin_unlock_irqrestore (&midi->virtual, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) snd_wavefront_midi_output_write(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) snd_wavefront_midi_enable_virtual (snd_wavefront_card_t *card)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) spin_lock_irqsave (&card->wavefront.midi.virtual, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) card->wavefront.midi.isvirtual = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) card->wavefront.midi.output_mpu = internal_mpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) card->wavefront.midi.input_mpu = internal_mpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) spin_unlock_irqrestore (&card->wavefront.midi.virtual, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) snd_wavefront_midi_disable_virtual (snd_wavefront_card_t *card)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) spin_lock_irqsave (&card->wavefront.midi.virtual, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) // snd_wavefront_midi_input_close (card->ics2115_external_rmidi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) // snd_wavefront_midi_output_close (card->ics2115_external_rmidi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) card->wavefront.midi.isvirtual = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) spin_unlock_irqrestore (&card->wavefront.midi.virtual, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) snd_wavefront_midi_start (snd_wavefront_card_t *card)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) int ok, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) unsigned char rbuf[4], wbuf[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) snd_wavefront_t *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) snd_wavefront_midi_t *midi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) dev = &card->wavefront;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) midi = &dev->midi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) /* The ICS2115 MPU-401 interface doesn't do anything
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) until its set into UART mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) /* XXX fix me - no hard timing loops allowed! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) for (i = 0; i < 30000 && !output_ready (midi); i++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) if (!output_ready (midi)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) snd_printk ("MIDI interface not ready for command\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) /* Any interrupts received from now on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) are owned by the MIDI side of things.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) dev->interrupts_are_midi = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) outb (UART_MODE_ON, midi->mpu_command_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) for (ok = 0, i = 50000; i > 0 && !ok; i--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) if (input_avail (midi)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) if (read_data (midi) == MPU_ACK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) ok = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) if (!ok) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) snd_printk ("cannot set UART mode for MIDI interface");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) dev->interrupts_are_midi = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) /* Route external MIDI to WaveFront synth (by default) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) if (snd_wavefront_cmd (dev, WFC_MISYNTH_ON, rbuf, wbuf)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) snd_printk ("can't enable MIDI-IN-2-synth routing.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) /* XXX error ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) /* Turn on Virtual MIDI, but first *always* turn it off,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) since otherwise consecutive reloads of the driver will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) never cause the hardware to generate the initial "internal" or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) "external" source bytes in the MIDI data stream. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) is pretty important, since the internal hardware generally will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) be used to generate none or very little MIDI output, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) thus the only source of MIDI data is actually external. Without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) the switch bytes, the driver will think it all comes from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) the internal interface. Duh.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) if (snd_wavefront_cmd (dev, WFC_VMIDI_OFF, rbuf, wbuf)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) snd_printk ("virtual MIDI mode not disabled\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) return 0; /* We're OK, but missing the external MIDI dev */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) snd_wavefront_midi_enable_virtual (card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) if (snd_wavefront_cmd (dev, WFC_VMIDI_ON, rbuf, wbuf)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) snd_printk ("cannot enable virtual MIDI mode.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) snd_wavefront_midi_disable_virtual (card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) const struct snd_rawmidi_ops snd_wavefront_midi_output =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) .open = snd_wavefront_midi_output_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) .close = snd_wavefront_midi_output_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) .trigger = snd_wavefront_midi_output_trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) const struct snd_rawmidi_ops snd_wavefront_midi_input =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) .open = snd_wavefront_midi_input_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) .close = snd_wavefront_midi_input_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) .trigger = snd_wavefront_midi_input_trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572)