^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Routines for control of SoundBlaster cards - MIDI interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * --
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Sun May 9 22:54:38 BST 1999 George David Morrison <gdm@gedamo.demon.co.uk>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Fixed typo in snd_sb8dsp_midi_new_device which prevented midi from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * working.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Sun May 11 12:34:56 UTC 2003 Clemens Ladisch <clemens@ladisch.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * Added full duplex UART mode for DSP version 2.0 and later.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <sound/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <sound/sb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) irqreturn_t snd_sb8dsp_midi_interrupt(struct snd_sb *chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) struct snd_rawmidi *rmidi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) int max = 64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) char byte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) if (!chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) return IRQ_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) rmidi = chip->rmidi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) if (!rmidi) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) inb(SBP(chip, DATA_AVAIL)); /* ack interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) return IRQ_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) spin_lock(&chip->midi_input_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) while (max-- > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) if (inb(SBP(chip, DATA_AVAIL)) & 0x80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) byte = inb(SBP(chip, READ));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) if (chip->open & SB_OPEN_MIDI_INPUT_TRIGGER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) snd_rawmidi_receive(chip->midi_substream_input, &byte, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) }
^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) spin_unlock(&chip->midi_input_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) static int snd_sb8dsp_midi_input_open(struct snd_rawmidi_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct snd_sb *chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) unsigned int valid_open_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) chip = substream->rmidi->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) valid_open_flags = chip->hardware >= SB_HW_20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) ? SB_OPEN_MIDI_OUTPUT | SB_OPEN_MIDI_OUTPUT_TRIGGER : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) spin_lock_irqsave(&chip->open_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) if (chip->open & ~valid_open_flags) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) spin_unlock_irqrestore(&chip->open_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) chip->open |= SB_OPEN_MIDI_INPUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) chip->midi_substream_input = substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) if (!(chip->open & SB_OPEN_MIDI_OUTPUT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) spin_unlock_irqrestore(&chip->open_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) snd_sbdsp_reset(chip); /* reset DSP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) if (chip->hardware >= SB_HW_20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) snd_sbdsp_command(chip, SB_DSP_MIDI_UART_IRQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) spin_unlock_irqrestore(&chip->open_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) static int snd_sb8dsp_midi_output_open(struct snd_rawmidi_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) struct snd_sb *chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) unsigned int valid_open_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) chip = substream->rmidi->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) valid_open_flags = chip->hardware >= SB_HW_20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) ? SB_OPEN_MIDI_INPUT | SB_OPEN_MIDI_INPUT_TRIGGER : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) spin_lock_irqsave(&chip->open_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) if (chip->open & ~valid_open_flags) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) spin_unlock_irqrestore(&chip->open_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) chip->open |= SB_OPEN_MIDI_OUTPUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) chip->midi_substream_output = substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) if (!(chip->open & SB_OPEN_MIDI_INPUT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) spin_unlock_irqrestore(&chip->open_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) snd_sbdsp_reset(chip); /* reset DSP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) if (chip->hardware >= SB_HW_20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) snd_sbdsp_command(chip, SB_DSP_MIDI_UART_IRQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) spin_unlock_irqrestore(&chip->open_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static int snd_sb8dsp_midi_input_close(struct snd_rawmidi_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct snd_sb *chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) chip = substream->rmidi->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) spin_lock_irqsave(&chip->open_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) chip->open &= ~(SB_OPEN_MIDI_INPUT | SB_OPEN_MIDI_INPUT_TRIGGER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) chip->midi_substream_input = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) if (!(chip->open & SB_OPEN_MIDI_OUTPUT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) spin_unlock_irqrestore(&chip->open_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) snd_sbdsp_reset(chip); /* reset DSP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) spin_unlock_irqrestore(&chip->open_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) static int snd_sb8dsp_midi_output_close(struct snd_rawmidi_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct snd_sb *chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) chip = substream->rmidi->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) del_timer_sync(&chip->midi_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) spin_lock_irqsave(&chip->open_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) chip->open &= ~(SB_OPEN_MIDI_OUTPUT | SB_OPEN_MIDI_OUTPUT_TRIGGER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) chip->midi_substream_output = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) if (!(chip->open & SB_OPEN_MIDI_INPUT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) spin_unlock_irqrestore(&chip->open_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) snd_sbdsp_reset(chip); /* reset DSP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) spin_unlock_irqrestore(&chip->open_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static void snd_sb8dsp_midi_input_trigger(struct snd_rawmidi_substream *substream, int up)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) struct snd_sb *chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) chip = substream->rmidi->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) spin_lock_irqsave(&chip->open_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) if (up) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) if (!(chip->open & SB_OPEN_MIDI_INPUT_TRIGGER)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) if (chip->hardware < SB_HW_20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) snd_sbdsp_command(chip, SB_DSP_MIDI_INPUT_IRQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) chip->open |= SB_OPEN_MIDI_INPUT_TRIGGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) if (chip->open & SB_OPEN_MIDI_INPUT_TRIGGER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) if (chip->hardware < SB_HW_20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) snd_sbdsp_command(chip, SB_DSP_MIDI_INPUT_IRQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) chip->open &= ~SB_OPEN_MIDI_INPUT_TRIGGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) spin_unlock_irqrestore(&chip->open_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) static void snd_sb8dsp_midi_output_write(struct snd_rawmidi_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) struct snd_sb *chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) char byte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) int max = 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) /* how big is Tx FIFO? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) chip = substream->rmidi->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) while (max-- > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) spin_lock_irqsave(&chip->open_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) if (snd_rawmidi_transmit_peek(substream, &byte, 1) != 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) chip->open &= ~SB_OPEN_MIDI_OUTPUT_TRIGGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) del_timer(&chip->midi_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) spin_unlock_irqrestore(&chip->open_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) if (chip->hardware >= SB_HW_20) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) int timeout = 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) while ((inb(SBP(chip, STATUS)) & 0x80) != 0 && --timeout > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) if (timeout == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) /* Tx FIFO full - try again later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) spin_unlock_irqrestore(&chip->open_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) outb(byte, SBP(chip, WRITE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) snd_sbdsp_command(chip, SB_DSP_MIDI_OUTPUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) snd_sbdsp_command(chip, byte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) snd_rawmidi_transmit_ack(substream, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) spin_unlock_irqrestore(&chip->open_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) static void snd_sb8dsp_midi_output_timer(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) struct snd_sb *chip = from_timer(chip, t, midi_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) struct snd_rawmidi_substream *substream = chip->midi_substream_output;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) spin_lock_irqsave(&chip->open_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) mod_timer(&chip->midi_timer, 1 + jiffies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) spin_unlock_irqrestore(&chip->open_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) snd_sb8dsp_midi_output_write(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) static void snd_sb8dsp_midi_output_trigger(struct snd_rawmidi_substream *substream, int up)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) struct snd_sb *chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) chip = substream->rmidi->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) spin_lock_irqsave(&chip->open_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) if (up) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) if (!(chip->open & SB_OPEN_MIDI_OUTPUT_TRIGGER)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) mod_timer(&chip->midi_timer, 1 + jiffies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) chip->open |= SB_OPEN_MIDI_OUTPUT_TRIGGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) if (chip->open & SB_OPEN_MIDI_OUTPUT_TRIGGER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) chip->open &= ~SB_OPEN_MIDI_OUTPUT_TRIGGER;
^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) spin_unlock_irqrestore(&chip->open_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) if (up)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) snd_sb8dsp_midi_output_write(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) static const struct snd_rawmidi_ops snd_sb8dsp_midi_output =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) .open = snd_sb8dsp_midi_output_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) .close = snd_sb8dsp_midi_output_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) .trigger = snd_sb8dsp_midi_output_trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) static const struct snd_rawmidi_ops snd_sb8dsp_midi_input =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) .open = snd_sb8dsp_midi_input_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) .close = snd_sb8dsp_midi_input_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) .trigger = snd_sb8dsp_midi_input_trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) int snd_sb8dsp_midi(struct snd_sb *chip, int device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) struct snd_rawmidi *rmidi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) if ((err = snd_rawmidi_new(chip->card, "SB8 MIDI", device, 1, 1, &rmidi)) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) strcpy(rmidi->name, "SB8 MIDI");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_sb8dsp_midi_output);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_sb8dsp_midi_input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT | SNDRV_RAWMIDI_INFO_INPUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) if (chip->hardware >= SB_HW_20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) rmidi->info_flags |= SNDRV_RAWMIDI_INFO_DUPLEX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) rmidi->private_data = chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) timer_setup(&chip->midi_timer, snd_sb8dsp_midi_output_timer, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) chip->rmidi = rmidi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) }