^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * usbmidi.c - ALSA USB MIDI driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (c) 2002-2009 Clemens Ladisch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Based on the OSS usb-midi driver by NAGANO Daisuke,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * NetBSD's umidi driver by Takuya SHIOZAKI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * the "USB Device Class Definition for MIDI Devices" by Roland
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Redistribution and use in source and binary forms, with or without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * modification, are permitted provided that the following conditions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * are met:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * 1. Redistributions of source code must retain the above copyright
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * notice, this list of conditions, and the following disclaimer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * without modification.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * 2. The name of the author may not be used to endorse or promote products
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * derived from this software without specific prior written permission.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * Alternatively, this software may be distributed and/or modified under the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * terms of the GNU General Public License as published by the Free Software
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * Foundation; either version 2 of the License, or (at your option) any later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * version.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * SUCH DAMAGE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <linux/bitops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #include <linux/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #include <linux/usb/audio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #include <sound/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #include <sound/control.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #include <sound/rawmidi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #include <sound/asequencer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #include "usbaudio.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #include "midi.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #include "power.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #include "helper.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * define this to log all USB packets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) /* #define DUMP_PACKETS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * how long to wait after some USB errors, so that hub_wq can disconnect() us
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * without too many spurious errors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) #define ERROR_DELAY_JIFFIES (HZ / 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) #define OUTPUT_URBS 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #define INPUT_URBS 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) MODULE_DESCRIPTION("USB Audio/MIDI helper module");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) MODULE_LICENSE("Dual BSD/GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) struct usb_ms_header_descriptor {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) __u8 bLength;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) __u8 bDescriptorType;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) __u8 bDescriptorSubtype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) __u8 bcdMSC[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) __le16 wTotalLength;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) } __attribute__ ((packed));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) struct usb_ms_endpoint_descriptor {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) __u8 bLength;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) __u8 bDescriptorType;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) __u8 bDescriptorSubtype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) __u8 bNumEmbMIDIJack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) __u8 baAssocJackID[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) } __attribute__ ((packed));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) struct snd_usb_midi_in_endpoint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) struct snd_usb_midi_out_endpoint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) struct snd_usb_midi_endpoint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) struct usb_protocol_ops {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) void (*input)(struct snd_usb_midi_in_endpoint*, uint8_t*, int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) void (*output)(struct snd_usb_midi_out_endpoint *ep, struct urb *urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) void (*output_packet)(struct urb*, uint8_t, uint8_t, uint8_t, uint8_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) void (*init_out_endpoint)(struct snd_usb_midi_out_endpoint *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) void (*finish_out_endpoint)(struct snd_usb_midi_out_endpoint *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) struct snd_usb_midi {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) struct usb_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) struct snd_card *card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) struct usb_interface *iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) const struct snd_usb_audio_quirk *quirk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) struct snd_rawmidi *rmidi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) const struct usb_protocol_ops *usb_protocol_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) struct timer_list error_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) spinlock_t disc_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) struct rw_semaphore disc_rwsem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) struct mutex mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) u32 usb_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) int next_midi_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) struct snd_usb_midi_endpoint {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct snd_usb_midi_out_endpoint *out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) struct snd_usb_midi_in_endpoint *in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) } endpoints[MIDI_MAX_ENDPOINTS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) unsigned long input_triggered;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) unsigned int opened[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) unsigned char disconnected;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) unsigned char input_running;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) struct snd_kcontrol *roland_load_ctl;
^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) struct snd_usb_midi_out_endpoint {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) struct snd_usb_midi *umidi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) struct out_urb_context {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) struct urb *urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) struct snd_usb_midi_out_endpoint *ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) } urbs[OUTPUT_URBS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) unsigned int active_urbs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) unsigned int drain_urbs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) int max_transfer; /* size of urb buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) struct work_struct work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) unsigned int next_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) spinlock_t buffer_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) struct usbmidi_out_port {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) struct snd_usb_midi_out_endpoint *ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) struct snd_rawmidi_substream *substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) int active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) uint8_t cable; /* cable number << 4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) uint8_t state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) #define STATE_UNKNOWN 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) #define STATE_1PARAM 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) #define STATE_2PARAM_1 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) #define STATE_2PARAM_2 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) #define STATE_SYSEX_0 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) #define STATE_SYSEX_1 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) #define STATE_SYSEX_2 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) uint8_t data[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) } ports[0x10];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) int current_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) wait_queue_head_t drain_wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) struct snd_usb_midi_in_endpoint {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) struct snd_usb_midi *umidi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) struct urb *urbs[INPUT_URBS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) struct usbmidi_in_port {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) struct snd_rawmidi_substream *substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) u8 running_status_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) } ports[0x10];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) u8 seen_f5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) bool in_sysex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) u8 last_cin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) u8 error_resubmit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) int current_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) static void snd_usbmidi_do_output(struct snd_usb_midi_out_endpoint *ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) static const uint8_t snd_usbmidi_cin_length[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 0, 0, 2, 3, 3, 1, 2, 3, 3, 3, 3, 3, 2, 2, 3, 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) * Submits the URB, with error handling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) static int snd_usbmidi_submit_urb(struct urb *urb, gfp_t flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) int err = usb_submit_urb(urb, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) if (err < 0 && err != -ENODEV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) dev_err(&urb->dev->dev, "usb_submit_urb: %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) return err;
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) * Error handling for URB completion functions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) static int snd_usbmidi_urb_error(const struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) switch (urb->status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) /* manually unlinked, or device gone */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) case -ENOENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) case -ECONNRESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) case -ESHUTDOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) case -ENODEV:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) /* errors that might occur during unplugging */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) case -EPROTO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) case -ETIME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) case -EILSEQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) dev_err(&urb->dev->dev, "urb status %d\n", urb->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) return 0; /* continue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) * Receives a chunk of MIDI data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) static void snd_usbmidi_input_data(struct snd_usb_midi_in_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) int portidx, uint8_t *data, int length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) struct usbmidi_in_port *port = &ep->ports[portidx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) if (!port->substream) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) dev_dbg(&ep->umidi->dev->dev, "unexpected port %d!\n", portidx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) if (!test_bit(port->substream->number, &ep->umidi->input_triggered))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) snd_rawmidi_receive(port->substream, data, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) #ifdef DUMP_PACKETS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) static void dump_urb(const char *type, const u8 *data, int length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) snd_printk(KERN_DEBUG "%s packet: [", type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) for (; length > 0; ++data, --length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) printk(KERN_CONT " %02x", *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) printk(KERN_CONT " ]\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) #define dump_urb(type, data, length) /* nothing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) #endif
^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) * Processes the data read from the device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) static void snd_usbmidi_in_urb_complete(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) struct snd_usb_midi_in_endpoint *ep = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) if (urb->status == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) dump_urb("received", urb->transfer_buffer, urb->actual_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) ep->umidi->usb_protocol_ops->input(ep, urb->transfer_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) urb->actual_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) int err = snd_usbmidi_urb_error(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) if (err != -ENODEV) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) ep->error_resubmit = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) mod_timer(&ep->umidi->error_timer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) jiffies + ERROR_DELAY_JIFFIES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) urb->dev = ep->umidi->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) snd_usbmidi_submit_urb(urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) static void snd_usbmidi_out_urb_complete(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) struct out_urb_context *context = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) struct snd_usb_midi_out_endpoint *ep = context->ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) unsigned int urb_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) spin_lock_irqsave(&ep->buffer_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) urb_index = context - ep->urbs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) ep->active_urbs &= ~(1 << urb_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) if (unlikely(ep->drain_urbs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) ep->drain_urbs &= ~(1 << urb_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) wake_up(&ep->drain_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) spin_unlock_irqrestore(&ep->buffer_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) if (urb->status < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) int err = snd_usbmidi_urb_error(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) if (err != -ENODEV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) mod_timer(&ep->umidi->error_timer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) jiffies + ERROR_DELAY_JIFFIES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) snd_usbmidi_do_output(ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) * This is called when some data should be transferred to the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) * (from one or more substreams).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) static void snd_usbmidi_do_output(struct snd_usb_midi_out_endpoint *ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) unsigned int urb_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) struct urb *urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) spin_lock_irqsave(&ep->buffer_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) if (ep->umidi->disconnected) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) spin_unlock_irqrestore(&ep->buffer_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) return;
^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) urb_index = ep->next_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) if (!(ep->active_urbs & (1 << urb_index))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) urb = ep->urbs[urb_index].urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) urb->transfer_buffer_length = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) ep->umidi->usb_protocol_ops->output(ep, urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) if (urb->transfer_buffer_length == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) dump_urb("sending", urb->transfer_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) urb->transfer_buffer_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) urb->dev = ep->umidi->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) if (snd_usbmidi_submit_urb(urb, GFP_ATOMIC) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) ep->active_urbs |= 1 << urb_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) if (++urb_index >= OUTPUT_URBS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) urb_index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) if (urb_index == ep->next_urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) ep->next_urb = urb_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) spin_unlock_irqrestore(&ep->buffer_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) static void snd_usbmidi_out_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) struct snd_usb_midi_out_endpoint *ep =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) container_of(work, struct snd_usb_midi_out_endpoint, work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) snd_usbmidi_do_output(ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) /* called after transfers had been interrupted due to some USB error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) static void snd_usbmidi_error_timer(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) struct snd_usb_midi *umidi = from_timer(umidi, t, error_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) unsigned int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) spin_lock(&umidi->disc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) if (umidi->disconnected) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) spin_unlock(&umidi->disc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) struct snd_usb_midi_in_endpoint *in = umidi->endpoints[i].in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) if (in && in->error_resubmit) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) in->error_resubmit = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) for (j = 0; j < INPUT_URBS; ++j) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) if (atomic_read(&in->urbs[j]->use_count))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) in->urbs[j]->dev = umidi->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) snd_usbmidi_submit_urb(in->urbs[j], GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) if (umidi->endpoints[i].out)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) snd_usbmidi_do_output(umidi->endpoints[i].out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) spin_unlock(&umidi->disc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) /* helper function to send static data that may not DMA-able */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) static int send_bulk_static_data(struct snd_usb_midi_out_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) const void *data, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) void *buf = kmemdup(data, len, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) dump_urb("sending", buf, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) if (ep->urbs[0].urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) err = usb_bulk_msg(ep->umidi->dev, ep->urbs[0].urb->pipe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) buf, len, NULL, 250);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) }
^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) * Standard USB MIDI protocol: see the spec.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) * Midiman protocol: like the standard protocol, but the control byte is the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) * fourth byte in each packet, and uses length instead of CIN.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) static void snd_usbmidi_standard_input(struct snd_usb_midi_in_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) uint8_t *buffer, int buffer_length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) for (i = 0; i + 3 < buffer_length; i += 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) if (buffer[i] != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) int cable = buffer[i] >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) int length = snd_usbmidi_cin_length[buffer[i] & 0x0f];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) snd_usbmidi_input_data(ep, cable, &buffer[i + 1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) length);
^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) static void snd_usbmidi_midiman_input(struct snd_usb_midi_in_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) uint8_t *buffer, int buffer_length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) for (i = 0; i + 3 < buffer_length; i += 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) if (buffer[i + 3] != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) int port = buffer[i + 3] >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) int length = buffer[i + 3] & 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) snd_usbmidi_input_data(ep, port, &buffer[i], length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) * Buggy M-Audio device: running status on input results in a packet that has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) * the data bytes but not the status byte and that is marked with CIN 4.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) static void snd_usbmidi_maudio_broken_running_status_input(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) struct snd_usb_midi_in_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) uint8_t *buffer, int buffer_length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) for (i = 0; i + 3 < buffer_length; i += 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) if (buffer[i] != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) int cable = buffer[i] >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) u8 cin = buffer[i] & 0x0f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) struct usbmidi_in_port *port = &ep->ports[cable];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) int length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) length = snd_usbmidi_cin_length[cin];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) if (cin == 0xf && buffer[i + 1] >= 0xf8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) ; /* realtime msg: no running status change */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) else if (cin >= 0x8 && cin <= 0xe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) /* channel msg */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) port->running_status_length = length - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) else if (cin == 0x4 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) port->running_status_length != 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) buffer[i + 1] < 0x80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) /* CIN 4 that is not a SysEx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) length = port->running_status_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) * All other msgs cannot begin running status.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) * (A channel msg sent as two or three CIN 0xF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) * packets could in theory, but this device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) * doesn't use this format.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) port->running_status_length = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) snd_usbmidi_input_data(ep, cable, &buffer[i + 1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) * QinHeng CH345 is buggy: every second packet inside a SysEx has not CIN 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) * but the previously seen CIN, but still with three data bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) static void ch345_broken_sysex_input(struct snd_usb_midi_in_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) uint8_t *buffer, int buffer_length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) unsigned int i, cin, length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) for (i = 0; i + 3 < buffer_length; i += 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) if (buffer[i] == 0 && i > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) cin = buffer[i] & 0x0f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) if (ep->in_sysex &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) cin == ep->last_cin &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) (buffer[i + 1 + (cin == 0x6)] & 0x80) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) cin = 0x4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) if (buffer[i + 1] == 0x90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) * Either a corrupted running status or a real note-on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) * message; impossible to detect reliably.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) length = snd_usbmidi_cin_length[cin];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) snd_usbmidi_input_data(ep, 0, &buffer[i + 1], length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) ep->in_sysex = cin == 0x4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) if (!ep->in_sysex)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) ep->last_cin = cin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) * CME protocol: like the standard protocol, but SysEx commands are sent as a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) * single USB packet preceded by a 0x0F byte.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) static void snd_usbmidi_cme_input(struct snd_usb_midi_in_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) uint8_t *buffer, int buffer_length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) if (buffer_length < 2 || (buffer[0] & 0x0f) != 0x0f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) snd_usbmidi_standard_input(ep, buffer, buffer_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) snd_usbmidi_input_data(ep, buffer[0] >> 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) &buffer[1], buffer_length - 1);
^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) * Adds one USB MIDI packet to the output buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) static void snd_usbmidi_output_standard_packet(struct urb *urb, uint8_t p0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) uint8_t p1, uint8_t p2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) uint8_t p3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) uint8_t *buf =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) (uint8_t *)urb->transfer_buffer + urb->transfer_buffer_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) buf[0] = p0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) buf[1] = p1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) buf[2] = p2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) buf[3] = p3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) urb->transfer_buffer_length += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) * Adds one Midiman packet to the output buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) static void snd_usbmidi_output_midiman_packet(struct urb *urb, uint8_t p0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) uint8_t p1, uint8_t p2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) uint8_t p3)
^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) uint8_t *buf =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) (uint8_t *)urb->transfer_buffer + urb->transfer_buffer_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) buf[0] = p1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) buf[1] = p2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) buf[2] = p3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) buf[3] = (p0 & 0xf0) | snd_usbmidi_cin_length[p0 & 0x0f];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) urb->transfer_buffer_length += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) * Converts MIDI commands to USB MIDI packets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) static void snd_usbmidi_transmit_byte(struct usbmidi_out_port *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) uint8_t b, struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) uint8_t p0 = port->cable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) void (*output_packet)(struct urb*, uint8_t, uint8_t, uint8_t, uint8_t) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) port->ep->umidi->usb_protocol_ops->output_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) if (b >= 0xf8) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) output_packet(urb, p0 | 0x0f, b, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) } else if (b >= 0xf0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) switch (b) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) case 0xf0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) port->data[0] = b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) port->state = STATE_SYSEX_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) case 0xf1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) case 0xf3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) port->data[0] = b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) port->state = STATE_1PARAM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) case 0xf2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) port->data[0] = b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) port->state = STATE_2PARAM_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) case 0xf4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) case 0xf5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) port->state = STATE_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) case 0xf6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) output_packet(urb, p0 | 0x05, 0xf6, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) port->state = STATE_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) case 0xf7:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) switch (port->state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) case STATE_SYSEX_0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) output_packet(urb, p0 | 0x05, 0xf7, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) case STATE_SYSEX_1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) output_packet(urb, p0 | 0x06, port->data[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 0xf7, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) case STATE_SYSEX_2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) output_packet(urb, p0 | 0x07, port->data[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) port->data[1], 0xf7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) port->state = STATE_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) } else if (b >= 0x80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) port->data[0] = b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) if (b >= 0xc0 && b <= 0xdf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) port->state = STATE_1PARAM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) port->state = STATE_2PARAM_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) } else { /* b < 0x80 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) switch (port->state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) case STATE_1PARAM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) if (port->data[0] < 0xf0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) p0 |= port->data[0] >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) p0 |= 0x02;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) port->state = STATE_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) output_packet(urb, p0, port->data[0], b, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) case STATE_2PARAM_1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) port->data[1] = b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) port->state = STATE_2PARAM_2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) case STATE_2PARAM_2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) if (port->data[0] < 0xf0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) p0 |= port->data[0] >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) port->state = STATE_2PARAM_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) p0 |= 0x03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) port->state = STATE_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) output_packet(urb, p0, port->data[0], port->data[1], b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) case STATE_SYSEX_0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) port->data[0] = b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) port->state = STATE_SYSEX_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) case STATE_SYSEX_1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) port->data[1] = b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) port->state = STATE_SYSEX_2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) case STATE_SYSEX_2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) output_packet(urb, p0 | 0x04, port->data[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) port->data[1], b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) port->state = STATE_SYSEX_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) static void snd_usbmidi_standard_output(struct snd_usb_midi_out_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) int p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) /* FIXME: lower-numbered ports can starve higher-numbered ports */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) for (p = 0; p < 0x10; ++p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) struct usbmidi_out_port *port = &ep->ports[p];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) if (!port->active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) while (urb->transfer_buffer_length + 3 < ep->max_transfer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) uint8_t b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) if (snd_rawmidi_transmit(port->substream, &b, 1) != 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) port->active = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) snd_usbmidi_transmit_byte(port, b, urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) static const struct usb_protocol_ops snd_usbmidi_standard_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) .input = snd_usbmidi_standard_input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) .output = snd_usbmidi_standard_output,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) .output_packet = snd_usbmidi_output_standard_packet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) static const struct usb_protocol_ops snd_usbmidi_midiman_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) .input = snd_usbmidi_midiman_input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) .output = snd_usbmidi_standard_output,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) .output_packet = snd_usbmidi_output_midiman_packet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) static const
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) struct usb_protocol_ops snd_usbmidi_maudio_broken_running_status_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) .input = snd_usbmidi_maudio_broken_running_status_input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) .output = snd_usbmidi_standard_output,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) .output_packet = snd_usbmidi_output_standard_packet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) static const struct usb_protocol_ops snd_usbmidi_cme_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) .input = snd_usbmidi_cme_input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) .output = snd_usbmidi_standard_output,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) .output_packet = snd_usbmidi_output_standard_packet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) static const struct usb_protocol_ops snd_usbmidi_ch345_broken_sysex_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) .input = ch345_broken_sysex_input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) .output = snd_usbmidi_standard_output,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) .output_packet = snd_usbmidi_output_standard_packet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) * AKAI MPD16 protocol:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) * For control port (endpoint 1):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) * ==============================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) * One or more chunks consisting of first byte of (0x10 | msg_len) and then a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) * SysEx message (msg_len=9 bytes long).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) * For data port (endpoint 2):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) * ===========================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) * One or more chunks consisting of first byte of (0x20 | msg_len) and then a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) * MIDI message (msg_len bytes long)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) * Messages sent: Active Sense, Note On, Poly Pressure, Control Change.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) static void snd_usbmidi_akai_input(struct snd_usb_midi_in_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) uint8_t *buffer, int buffer_length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) unsigned int pos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) unsigned int len = (unsigned int)buffer_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) while (pos < len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) unsigned int port = (buffer[pos] >> 4) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) unsigned int msg_len = buffer[pos] & 0x0f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) pos++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) if (pos + msg_len <= len && port < 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) snd_usbmidi_input_data(ep, 0, &buffer[pos], msg_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) pos += msg_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) #define MAX_AKAI_SYSEX_LEN 9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) static void snd_usbmidi_akai_output(struct snd_usb_midi_out_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) uint8_t *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) int pos, end, count, buf_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) uint8_t tmp[MAX_AKAI_SYSEX_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) struct snd_rawmidi_substream *substream = ep->ports[0].substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) if (!ep->ports[0].active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) msg = urb->transfer_buffer + urb->transfer_buffer_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) buf_end = ep->max_transfer - MAX_AKAI_SYSEX_LEN - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) /* only try adding more data when there's space for at least 1 SysEx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) while (urb->transfer_buffer_length < buf_end) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) count = snd_rawmidi_transmit_peek(substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) tmp, MAX_AKAI_SYSEX_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) if (!count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) ep->ports[0].active = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) /* try to skip non-SysEx data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) for (pos = 0; pos < count && tmp[pos] != 0xF0; pos++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) if (pos > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) snd_rawmidi_transmit_ack(substream, pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) /* look for the start or end marker */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) for (end = 1; end < count && tmp[end] < 0xF0; end++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) /* next SysEx started before the end of current one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) if (end < count && tmp[end] == 0xF0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) /* it's incomplete - drop it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) snd_rawmidi_transmit_ack(substream, end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) /* SysEx complete */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) if (end < count && tmp[end] == 0xF7) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) /* queue it, ack it, and get the next one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) count = end + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) msg[0] = 0x10 | count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) memcpy(&msg[1], tmp, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) snd_rawmidi_transmit_ack(substream, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) urb->transfer_buffer_length += count + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) msg += count + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) /* less than 9 bytes and no end byte - wait for more */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) if (count < MAX_AKAI_SYSEX_LEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) ep->ports[0].active = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) /* 9 bytes and no end marker in sight - malformed, skip it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) snd_rawmidi_transmit_ack(substream, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) static const struct usb_protocol_ops snd_usbmidi_akai_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) .input = snd_usbmidi_akai_input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) .output = snd_usbmidi_akai_output,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) * Novation USB MIDI protocol: number of data bytes is in the first byte
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) * (when receiving) (+1!) or in the second byte (when sending); data begins
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) * at the third byte.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) static void snd_usbmidi_novation_input(struct snd_usb_midi_in_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) uint8_t *buffer, int buffer_length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) if (buffer_length < 2 || !buffer[0] || buffer_length < buffer[0] + 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) snd_usbmidi_input_data(ep, 0, &buffer[2], buffer[0] - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) static void snd_usbmidi_novation_output(struct snd_usb_midi_out_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) uint8_t *transfer_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) if (!ep->ports[0].active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) transfer_buffer = urb->transfer_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) count = snd_rawmidi_transmit(ep->ports[0].substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) &transfer_buffer[2],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) ep->max_transfer - 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) if (count < 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) ep->ports[0].active = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) transfer_buffer[0] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) transfer_buffer[1] = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) urb->transfer_buffer_length = 2 + count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) static const struct usb_protocol_ops snd_usbmidi_novation_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) .input = snd_usbmidi_novation_input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) .output = snd_usbmidi_novation_output,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) * "raw" protocol: just move raw MIDI bytes from/to the endpoint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) static void snd_usbmidi_raw_input(struct snd_usb_midi_in_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) uint8_t *buffer, int buffer_length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) snd_usbmidi_input_data(ep, 0, buffer, buffer_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) static void snd_usbmidi_raw_output(struct snd_usb_midi_out_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) if (!ep->ports[0].active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) count = snd_rawmidi_transmit(ep->ports[0].substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) urb->transfer_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) ep->max_transfer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) if (count < 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) ep->ports[0].active = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) urb->transfer_buffer_length = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) static const struct usb_protocol_ops snd_usbmidi_raw_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) .input = snd_usbmidi_raw_input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) .output = snd_usbmidi_raw_output,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) * FTDI protocol: raw MIDI bytes, but input packets have two modem status bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) static void snd_usbmidi_ftdi_input(struct snd_usb_midi_in_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) uint8_t *buffer, int buffer_length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) if (buffer_length > 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) snd_usbmidi_input_data(ep, 0, buffer + 2, buffer_length - 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) static const struct usb_protocol_ops snd_usbmidi_ftdi_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) .input = snd_usbmidi_ftdi_input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) .output = snd_usbmidi_raw_output,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) static void snd_usbmidi_us122l_input(struct snd_usb_midi_in_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) uint8_t *buffer, int buffer_length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) if (buffer_length != 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) buffer_length = 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) while (buffer_length && buffer[buffer_length - 1] == 0xFD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) buffer_length--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) if (buffer_length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) snd_usbmidi_input_data(ep, 0, buffer, buffer_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) static void snd_usbmidi_us122l_output(struct snd_usb_midi_out_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) if (!ep->ports[0].active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) switch (snd_usb_get_speed(ep->umidi->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) case USB_SPEED_HIGH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) case USB_SPEED_SUPER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) case USB_SPEED_SUPER_PLUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) count = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) count = snd_rawmidi_transmit(ep->ports[0].substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) urb->transfer_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) if (count < 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) ep->ports[0].active = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) memset(urb->transfer_buffer + count, 0xFD, ep->max_transfer - count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) urb->transfer_buffer_length = ep->max_transfer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) static const struct usb_protocol_ops snd_usbmidi_122l_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) .input = snd_usbmidi_us122l_input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) .output = snd_usbmidi_us122l_output,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) * Emagic USB MIDI protocol: raw MIDI with "F5 xx" port switching.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) static void snd_usbmidi_emagic_init_out(struct snd_usb_midi_out_endpoint *ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) static const u8 init_data[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) /* initialization magic: "get version" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) 0xf0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) 0x00, 0x20, 0x31, /* Emagic */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) 0x64, /* Unitor8 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) 0x0b, /* version number request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) 0x00, /* command version */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) 0x00, /* EEPROM, box 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) 0xf7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) send_bulk_static_data(ep, init_data, sizeof(init_data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) /* while we're at it, pour on more magic */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) send_bulk_static_data(ep, init_data, sizeof(init_data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) static void snd_usbmidi_emagic_finish_out(struct snd_usb_midi_out_endpoint *ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) static const u8 finish_data[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) /* switch to patch mode with last preset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) 0xf0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) 0x00, 0x20, 0x31, /* Emagic */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) 0x64, /* Unitor8 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) 0x10, /* patch switch command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) 0x00, /* command version */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) 0x7f, /* to all boxes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) 0x40, /* last preset in EEPROM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) 0xf7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) send_bulk_static_data(ep, finish_data, sizeof(finish_data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) static void snd_usbmidi_emagic_input(struct snd_usb_midi_in_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) uint8_t *buffer, int buffer_length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) /* FF indicates end of valid data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) for (i = 0; i < buffer_length; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) if (buffer[i] == 0xff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) buffer_length = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) /* handle F5 at end of last buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) if (ep->seen_f5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) goto switch_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) while (buffer_length > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) /* determine size of data until next F5 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) for (i = 0; i < buffer_length; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) if (buffer[i] == 0xf5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) snd_usbmidi_input_data(ep, ep->current_port, buffer, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) buffer += i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) buffer_length -= i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) if (buffer_length <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) /* assert(buffer[0] == 0xf5); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) ep->seen_f5 = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) ++buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) --buffer_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) switch_port:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) if (buffer_length <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) if (buffer[0] < 0x80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) ep->current_port = (buffer[0] - 1) & 15;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) ++buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) --buffer_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) ep->seen_f5 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) static void snd_usbmidi_emagic_output(struct snd_usb_midi_out_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) int port0 = ep->current_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) uint8_t *buf = urb->transfer_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) int buf_free = ep->max_transfer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) int length, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) for (i = 0; i < 0x10; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) /* round-robin, starting at the last current port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) int portnum = (port0 + i) & 15;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) struct usbmidi_out_port *port = &ep->ports[portnum];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) if (!port->active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) if (snd_rawmidi_transmit_peek(port->substream, buf, 1) != 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) port->active = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) if (portnum != ep->current_port) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) if (buf_free < 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) ep->current_port = portnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) buf[0] = 0xf5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) buf[1] = (portnum + 1) & 15;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) buf += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) buf_free -= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) if (buf_free < 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) length = snd_rawmidi_transmit(port->substream, buf, buf_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) if (length > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) buf += length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) buf_free -= length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) if (buf_free < 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) if (buf_free < ep->max_transfer && buf_free > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) *buf = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) --buf_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) urb->transfer_buffer_length = ep->max_transfer - buf_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) static const struct usb_protocol_ops snd_usbmidi_emagic_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) .input = snd_usbmidi_emagic_input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) .output = snd_usbmidi_emagic_output,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) .init_out_endpoint = snd_usbmidi_emagic_init_out,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) .finish_out_endpoint = snd_usbmidi_emagic_finish_out,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) static void update_roland_altsetting(struct snd_usb_midi *umidi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) struct usb_interface *intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) struct usb_host_interface *hostif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) struct usb_interface_descriptor *intfd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) int is_light_load;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) intf = umidi->iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) is_light_load = intf->cur_altsetting != intf->altsetting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) if (umidi->roland_load_ctl->private_value == is_light_load)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) hostif = &intf->altsetting[umidi->roland_load_ctl->private_value];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) intfd = get_iface_desc(hostif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) snd_usbmidi_input_stop(&umidi->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) usb_set_interface(umidi->dev, intfd->bInterfaceNumber,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) intfd->bAlternateSetting);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) snd_usbmidi_input_start(&umidi->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) static int substream_open(struct snd_rawmidi_substream *substream, int dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) int open)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) struct snd_usb_midi *umidi = substream->rmidi->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) struct snd_kcontrol *ctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) down_read(&umidi->disc_rwsem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) if (umidi->disconnected) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) up_read(&umidi->disc_rwsem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) return open ? -ENODEV : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) mutex_lock(&umidi->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) if (open) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) if (!umidi->opened[0] && !umidi->opened[1]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) if (umidi->roland_load_ctl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) ctl = umidi->roland_load_ctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) ctl->vd[0].access |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) SNDRV_CTL_ELEM_ACCESS_INACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) snd_ctl_notify(umidi->card,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) update_roland_altsetting(umidi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) umidi->opened[dir]++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) if (umidi->opened[1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) snd_usbmidi_input_start(&umidi->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) umidi->opened[dir]--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) if (!umidi->opened[1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) snd_usbmidi_input_stop(&umidi->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) if (!umidi->opened[0] && !umidi->opened[1]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) if (umidi->roland_load_ctl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) ctl = umidi->roland_load_ctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) ctl->vd[0].access &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) snd_ctl_notify(umidi->card,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) mutex_unlock(&umidi->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) up_read(&umidi->disc_rwsem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) static int snd_usbmidi_output_open(struct snd_rawmidi_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) struct snd_usb_midi *umidi = substream->rmidi->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) struct usbmidi_out_port *port = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) if (umidi->endpoints[i].out)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) for (j = 0; j < 0x10; ++j)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) if (umidi->endpoints[i].out->ports[j].substream == substream) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) port = &umidi->endpoints[i].out->ports[j];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) if (!port) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) snd_BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) substream->runtime->private_data = port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) port->state = STATE_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) return substream_open(substream, 0, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) static int snd_usbmidi_output_close(struct snd_rawmidi_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) return substream_open(substream, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) static void snd_usbmidi_output_trigger(struct snd_rawmidi_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) int up)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) struct usbmidi_out_port *port =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) (struct usbmidi_out_port *)substream->runtime->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) port->active = up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) if (up) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) if (port->ep->umidi->disconnected) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) /* gobble up remaining bytes to prevent wait in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) * snd_rawmidi_drain_output */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) snd_rawmidi_proceed(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) queue_work(system_highpri_wq, &port->ep->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) static void snd_usbmidi_output_drain(struct snd_rawmidi_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) struct usbmidi_out_port *port = substream->runtime->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) struct snd_usb_midi_out_endpoint *ep = port->ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) unsigned int drain_urbs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) DEFINE_WAIT(wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) long timeout = msecs_to_jiffies(50);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) if (ep->umidi->disconnected)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) * The substream buffer is empty, but some data might still be in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) * currently active URBs, so we have to wait for those to complete.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) spin_lock_irq(&ep->buffer_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) drain_urbs = ep->active_urbs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) if (drain_urbs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) ep->drain_urbs |= drain_urbs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) prepare_to_wait(&ep->drain_wait, &wait,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) TASK_UNINTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) spin_unlock_irq(&ep->buffer_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) timeout = schedule_timeout(timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) spin_lock_irq(&ep->buffer_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) drain_urbs &= ep->drain_urbs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) } while (drain_urbs && timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) finish_wait(&ep->drain_wait, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) spin_unlock_irq(&ep->buffer_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) static int snd_usbmidi_input_open(struct snd_rawmidi_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) return substream_open(substream, 1, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) static int snd_usbmidi_input_close(struct snd_rawmidi_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) return substream_open(substream, 1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) static void snd_usbmidi_input_trigger(struct snd_rawmidi_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) int up)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) struct snd_usb_midi *umidi = substream->rmidi->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) if (up)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) set_bit(substream->number, &umidi->input_triggered);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) clear_bit(substream->number, &umidi->input_triggered);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) static const struct snd_rawmidi_ops snd_usbmidi_output_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) .open = snd_usbmidi_output_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) .close = snd_usbmidi_output_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) .trigger = snd_usbmidi_output_trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) .drain = snd_usbmidi_output_drain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) static const struct snd_rawmidi_ops snd_usbmidi_input_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) .open = snd_usbmidi_input_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) .close = snd_usbmidi_input_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) .trigger = snd_usbmidi_input_trigger
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) static void free_urb_and_buffer(struct snd_usb_midi *umidi, struct urb *urb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) unsigned int buffer_length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) usb_free_coherent(umidi->dev, buffer_length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) urb->transfer_buffer, urb->transfer_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) usb_free_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) * Frees an input endpoint.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) * May be called when ep hasn't been initialized completely.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) static void snd_usbmidi_in_endpoint_delete(struct snd_usb_midi_in_endpoint *ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) for (i = 0; i < INPUT_URBS; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) if (ep->urbs[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) free_urb_and_buffer(ep->umidi, ep->urbs[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) ep->urbs[i]->transfer_buffer_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) kfree(ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) * Creates an input endpoint.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) static int snd_usbmidi_in_endpoint_create(struct snd_usb_midi *umidi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) struct snd_usb_midi_endpoint_info *ep_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) struct snd_usb_midi_endpoint *rep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) struct snd_usb_midi_in_endpoint *ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) void *buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) unsigned int pipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) int length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) rep->in = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) ep = kzalloc(sizeof(*ep), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) if (!ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) ep->umidi = umidi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) for (i = 0; i < INPUT_URBS; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) ep->urbs[i] = usb_alloc_urb(0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) if (!ep->urbs[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) if (ep_info->in_interval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) pipe = usb_rcvintpipe(umidi->dev, ep_info->in_ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) pipe = usb_rcvbulkpipe(umidi->dev, ep_info->in_ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) length = usb_maxpacket(umidi->dev, pipe, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) for (i = 0; i < INPUT_URBS; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) buffer = usb_alloc_coherent(umidi->dev, length, GFP_KERNEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) &ep->urbs[i]->transfer_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) if (!buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) if (ep_info->in_interval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) usb_fill_int_urb(ep->urbs[i], umidi->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) pipe, buffer, length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) snd_usbmidi_in_urb_complete,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) ep, ep_info->in_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) usb_fill_bulk_urb(ep->urbs[i], umidi->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) pipe, buffer, length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) snd_usbmidi_in_urb_complete, ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) ep->urbs[i]->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) err = usb_urb_ep_type_check(ep->urbs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) dev_err(&umidi->dev->dev, "invalid MIDI in EP %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) ep_info->in_ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) rep->in = ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) snd_usbmidi_in_endpoint_delete(ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) * Frees an output endpoint.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) * May be called when ep hasn't been initialized completely.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) static void snd_usbmidi_out_endpoint_clear(struct snd_usb_midi_out_endpoint *ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) for (i = 0; i < OUTPUT_URBS; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) if (ep->urbs[i].urb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) free_urb_and_buffer(ep->umidi, ep->urbs[i].urb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) ep->max_transfer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) ep->urbs[i].urb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) static void snd_usbmidi_out_endpoint_delete(struct snd_usb_midi_out_endpoint *ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) snd_usbmidi_out_endpoint_clear(ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) kfree(ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) * Creates an output endpoint, and initializes output ports.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) static int snd_usbmidi_out_endpoint_create(struct snd_usb_midi *umidi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) struct snd_usb_midi_endpoint_info *ep_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) struct snd_usb_midi_endpoint *rep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) struct snd_usb_midi_out_endpoint *ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) unsigned int pipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) void *buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) rep->out = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) ep = kzalloc(sizeof(*ep), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) if (!ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) ep->umidi = umidi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) for (i = 0; i < OUTPUT_URBS; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) ep->urbs[i].urb = usb_alloc_urb(0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) if (!ep->urbs[i].urb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) ep->urbs[i].ep = ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) if (ep_info->out_interval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) pipe = usb_sndintpipe(umidi->dev, ep_info->out_ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) pipe = usb_sndbulkpipe(umidi->dev, ep_info->out_ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) switch (umidi->usb_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) ep->max_transfer = usb_maxpacket(umidi->dev, pipe, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) * Various chips declare a packet size larger than 4 bytes, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) * do not actually work with larger packets:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) case USB_ID(0x0a67, 0x5011): /* Medeli DD305 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) case USB_ID(0x0a92, 0x1020): /* ESI M4U */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) case USB_ID(0x1430, 0x474b): /* RedOctane GH MIDI INTERFACE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) case USB_ID(0x15ca, 0x0101): /* Textech USB Midi Cable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) case USB_ID(0x15ca, 0x1806): /* Textech USB Midi Cable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) case USB_ID(0x1a86, 0x752d): /* QinHeng CH345 "USB2.0-MIDI" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) case USB_ID(0xfc08, 0x0101): /* Unknown vendor Cable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) ep->max_transfer = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) * Some devices only work with 9 bytes packet size:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) case USB_ID(0x0644, 0x800e): /* Tascam US-122L */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) case USB_ID(0x0644, 0x800f): /* Tascam US-144 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) ep->max_transfer = 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) for (i = 0; i < OUTPUT_URBS; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) buffer = usb_alloc_coherent(umidi->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) ep->max_transfer, GFP_KERNEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) &ep->urbs[i].urb->transfer_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) if (!buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) if (ep_info->out_interval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) usb_fill_int_urb(ep->urbs[i].urb, umidi->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) pipe, buffer, ep->max_transfer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) snd_usbmidi_out_urb_complete,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) &ep->urbs[i], ep_info->out_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) usb_fill_bulk_urb(ep->urbs[i].urb, umidi->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) pipe, buffer, ep->max_transfer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) snd_usbmidi_out_urb_complete,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) &ep->urbs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) err = usb_urb_ep_type_check(ep->urbs[i].urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) dev_err(&umidi->dev->dev, "invalid MIDI out EP %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) ep_info->out_ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) ep->urbs[i].urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) spin_lock_init(&ep->buffer_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) INIT_WORK(&ep->work, snd_usbmidi_out_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) init_waitqueue_head(&ep->drain_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) for (i = 0; i < 0x10; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) if (ep_info->out_cables & (1 << i)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) ep->ports[i].ep = ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) ep->ports[i].cable = i << 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) if (umidi->usb_protocol_ops->init_out_endpoint)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) umidi->usb_protocol_ops->init_out_endpoint(ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) rep->out = ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) snd_usbmidi_out_endpoint_delete(ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) * Frees everything.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) static void snd_usbmidi_free(struct snd_usb_midi *umidi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) struct snd_usb_midi_endpoint *ep = &umidi->endpoints[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) if (ep->out)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) snd_usbmidi_out_endpoint_delete(ep->out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) if (ep->in)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) snd_usbmidi_in_endpoint_delete(ep->in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) mutex_destroy(&umidi->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) kfree(umidi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) * Unlinks all URBs (must be done before the usb_device is deleted).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) void snd_usbmidi_disconnect(struct list_head *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) struct snd_usb_midi *umidi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) unsigned int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) umidi = list_entry(p, struct snd_usb_midi, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) * an URB's completion handler may start the timer and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) * a timer may submit an URB. To reliably break the cycle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) * a flag under lock must be used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) down_write(&umidi->disc_rwsem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) spin_lock_irq(&umidi->disc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) umidi->disconnected = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) spin_unlock_irq(&umidi->disc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) up_write(&umidi->disc_rwsem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) del_timer_sync(&umidi->error_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) struct snd_usb_midi_endpoint *ep = &umidi->endpoints[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) if (ep->out)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) cancel_work_sync(&ep->out->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) if (ep->out) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) for (j = 0; j < OUTPUT_URBS; ++j)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) usb_kill_urb(ep->out->urbs[j].urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) if (umidi->usb_protocol_ops->finish_out_endpoint)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) umidi->usb_protocol_ops->finish_out_endpoint(ep->out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) ep->out->active_urbs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) if (ep->out->drain_urbs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) ep->out->drain_urbs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) wake_up(&ep->out->drain_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) if (ep->in)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) for (j = 0; j < INPUT_URBS; ++j)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) usb_kill_urb(ep->in->urbs[j]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) /* free endpoints here; later call can result in Oops */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) if (ep->out)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) snd_usbmidi_out_endpoint_clear(ep->out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) if (ep->in) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) snd_usbmidi_in_endpoint_delete(ep->in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) ep->in = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) EXPORT_SYMBOL(snd_usbmidi_disconnect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) static void snd_usbmidi_rawmidi_free(struct snd_rawmidi *rmidi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) struct snd_usb_midi *umidi = rmidi->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) snd_usbmidi_free(umidi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) static struct snd_rawmidi_substream *snd_usbmidi_find_substream(struct snd_usb_midi *umidi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) int stream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) int number)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) struct snd_rawmidi_substream *substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) list_for_each_entry(substream, &umidi->rmidi->streams[stream].substreams,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) if (substream->number == number)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) return substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) * This list specifies names for ports that do not fit into the standard
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) * "(product) MIDI (n)" schema because they aren't external MIDI ports,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) * such as internal control or synthesizer ports.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) static struct port_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) u32 id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) short int port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) short int voices;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) unsigned int seq_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) } snd_usbmidi_port_info[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) #define PORT_INFO(vendor, product, num, name_, voices_, flags) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) { .id = USB_ID(vendor, product), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) .port = num, .voices = voices_, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) .name = name_, .seq_flags = flags }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) #define EXTERNAL_PORT(vendor, product, num, name) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) PORT_INFO(vendor, product, num, name, 0, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) SNDRV_SEQ_PORT_TYPE_HARDWARE | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) SNDRV_SEQ_PORT_TYPE_PORT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) #define CONTROL_PORT(vendor, product, num, name) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) PORT_INFO(vendor, product, num, name, 0, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) SNDRV_SEQ_PORT_TYPE_HARDWARE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) #define GM_SYNTH_PORT(vendor, product, num, name, voices) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) PORT_INFO(vendor, product, num, name, voices, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) SNDRV_SEQ_PORT_TYPE_MIDI_GM | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) SNDRV_SEQ_PORT_TYPE_HARDWARE | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) SNDRV_SEQ_PORT_TYPE_SYNTHESIZER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) #define ROLAND_SYNTH_PORT(vendor, product, num, name, voices) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) PORT_INFO(vendor, product, num, name, voices, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) SNDRV_SEQ_PORT_TYPE_MIDI_GM | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) SNDRV_SEQ_PORT_TYPE_MIDI_GM2 | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) SNDRV_SEQ_PORT_TYPE_MIDI_GS | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) SNDRV_SEQ_PORT_TYPE_MIDI_XG | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) SNDRV_SEQ_PORT_TYPE_HARDWARE | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) SNDRV_SEQ_PORT_TYPE_SYNTHESIZER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) #define SOUNDCANVAS_PORT(vendor, product, num, name, voices) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) PORT_INFO(vendor, product, num, name, voices, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) SNDRV_SEQ_PORT_TYPE_MIDI_GM | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) SNDRV_SEQ_PORT_TYPE_MIDI_GM2 | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) SNDRV_SEQ_PORT_TYPE_MIDI_GS | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) SNDRV_SEQ_PORT_TYPE_MIDI_XG | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) SNDRV_SEQ_PORT_TYPE_MIDI_MT32 | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) SNDRV_SEQ_PORT_TYPE_HARDWARE | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) SNDRV_SEQ_PORT_TYPE_SYNTHESIZER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) /* Yamaha MOTIF XF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) GM_SYNTH_PORT(0x0499, 0x105c, 0, "%s Tone Generator", 128),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) CONTROL_PORT(0x0499, 0x105c, 1, "%s Remote Control"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) EXTERNAL_PORT(0x0499, 0x105c, 2, "%s Thru"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) CONTROL_PORT(0x0499, 0x105c, 3, "%s Editor"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) /* Roland UA-100 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) CONTROL_PORT(0x0582, 0x0000, 2, "%s Control"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) /* Roland SC-8850 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) SOUNDCANVAS_PORT(0x0582, 0x0003, 0, "%s Part A", 128),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) SOUNDCANVAS_PORT(0x0582, 0x0003, 1, "%s Part B", 128),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) SOUNDCANVAS_PORT(0x0582, 0x0003, 2, "%s Part C", 128),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) SOUNDCANVAS_PORT(0x0582, 0x0003, 3, "%s Part D", 128),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) EXTERNAL_PORT(0x0582, 0x0003, 4, "%s MIDI 1"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) EXTERNAL_PORT(0x0582, 0x0003, 5, "%s MIDI 2"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) /* Roland U-8 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) EXTERNAL_PORT(0x0582, 0x0004, 0, "%s MIDI"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) CONTROL_PORT(0x0582, 0x0004, 1, "%s Control"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) /* Roland SC-8820 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) SOUNDCANVAS_PORT(0x0582, 0x0007, 0, "%s Part A", 64),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) SOUNDCANVAS_PORT(0x0582, 0x0007, 1, "%s Part B", 64),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) EXTERNAL_PORT(0x0582, 0x0007, 2, "%s MIDI"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) /* Roland SK-500 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) SOUNDCANVAS_PORT(0x0582, 0x000b, 0, "%s Part A", 64),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) SOUNDCANVAS_PORT(0x0582, 0x000b, 1, "%s Part B", 64),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) EXTERNAL_PORT(0x0582, 0x000b, 2, "%s MIDI"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) /* Roland SC-D70 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) SOUNDCANVAS_PORT(0x0582, 0x000c, 0, "%s Part A", 64),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) SOUNDCANVAS_PORT(0x0582, 0x000c, 1, "%s Part B", 64),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) EXTERNAL_PORT(0x0582, 0x000c, 2, "%s MIDI"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) /* Edirol UM-880 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) CONTROL_PORT(0x0582, 0x0014, 8, "%s Control"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) /* Edirol SD-90 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) ROLAND_SYNTH_PORT(0x0582, 0x0016, 0, "%s Part A", 128),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) ROLAND_SYNTH_PORT(0x0582, 0x0016, 1, "%s Part B", 128),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) EXTERNAL_PORT(0x0582, 0x0016, 2, "%s MIDI 1"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) EXTERNAL_PORT(0x0582, 0x0016, 3, "%s MIDI 2"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) /* Edirol UM-550 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) CONTROL_PORT(0x0582, 0x0023, 5, "%s Control"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) /* Edirol SD-20 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) ROLAND_SYNTH_PORT(0x0582, 0x0027, 0, "%s Part A", 64),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) ROLAND_SYNTH_PORT(0x0582, 0x0027, 1, "%s Part B", 64),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) EXTERNAL_PORT(0x0582, 0x0027, 2, "%s MIDI"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) /* Edirol SD-80 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) ROLAND_SYNTH_PORT(0x0582, 0x0029, 0, "%s Part A", 128),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) ROLAND_SYNTH_PORT(0x0582, 0x0029, 1, "%s Part B", 128),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) EXTERNAL_PORT(0x0582, 0x0029, 2, "%s MIDI 1"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) EXTERNAL_PORT(0x0582, 0x0029, 3, "%s MIDI 2"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) /* Edirol UA-700 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) EXTERNAL_PORT(0x0582, 0x002b, 0, "%s MIDI"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) CONTROL_PORT(0x0582, 0x002b, 1, "%s Control"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) /* Roland VariOS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) EXTERNAL_PORT(0x0582, 0x002f, 0, "%s MIDI"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) EXTERNAL_PORT(0x0582, 0x002f, 1, "%s External MIDI"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) EXTERNAL_PORT(0x0582, 0x002f, 2, "%s Sync"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) /* Edirol PCR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) EXTERNAL_PORT(0x0582, 0x0033, 0, "%s MIDI"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) EXTERNAL_PORT(0x0582, 0x0033, 1, "%s 1"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) EXTERNAL_PORT(0x0582, 0x0033, 2, "%s 2"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) /* BOSS GS-10 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) EXTERNAL_PORT(0x0582, 0x003b, 0, "%s MIDI"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) CONTROL_PORT(0x0582, 0x003b, 1, "%s Control"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) /* Edirol UA-1000 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) EXTERNAL_PORT(0x0582, 0x0044, 0, "%s MIDI"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) CONTROL_PORT(0x0582, 0x0044, 1, "%s Control"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) /* Edirol UR-80 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) EXTERNAL_PORT(0x0582, 0x0048, 0, "%s MIDI"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) EXTERNAL_PORT(0x0582, 0x0048, 1, "%s 1"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) EXTERNAL_PORT(0x0582, 0x0048, 2, "%s 2"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) /* Edirol PCR-A */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) EXTERNAL_PORT(0x0582, 0x004d, 0, "%s MIDI"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) EXTERNAL_PORT(0x0582, 0x004d, 1, "%s 1"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) EXTERNAL_PORT(0x0582, 0x004d, 2, "%s 2"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) /* BOSS GT-PRO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) CONTROL_PORT(0x0582, 0x0089, 0, "%s Control"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) /* Edirol UM-3EX */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) CONTROL_PORT(0x0582, 0x009a, 3, "%s Control"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) /* Roland VG-99 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) CONTROL_PORT(0x0582, 0x00b2, 0, "%s Control"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) EXTERNAL_PORT(0x0582, 0x00b2, 1, "%s MIDI"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) /* Cakewalk Sonar V-Studio 100 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) EXTERNAL_PORT(0x0582, 0x00eb, 0, "%s MIDI"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) CONTROL_PORT(0x0582, 0x00eb, 1, "%s Control"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) /* Roland VB-99 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) CONTROL_PORT(0x0582, 0x0102, 0, "%s Control"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) EXTERNAL_PORT(0x0582, 0x0102, 1, "%s MIDI"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) /* Roland A-PRO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) EXTERNAL_PORT(0x0582, 0x010f, 0, "%s MIDI"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) CONTROL_PORT(0x0582, 0x010f, 1, "%s 1"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) CONTROL_PORT(0x0582, 0x010f, 2, "%s 2"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) /* Roland SD-50 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) ROLAND_SYNTH_PORT(0x0582, 0x0114, 0, "%s Synth", 128),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) EXTERNAL_PORT(0x0582, 0x0114, 1, "%s MIDI"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) CONTROL_PORT(0x0582, 0x0114, 2, "%s Control"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) /* Roland OCTA-CAPTURE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) EXTERNAL_PORT(0x0582, 0x0120, 0, "%s MIDI"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) CONTROL_PORT(0x0582, 0x0120, 1, "%s Control"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) EXTERNAL_PORT(0x0582, 0x0121, 0, "%s MIDI"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) CONTROL_PORT(0x0582, 0x0121, 1, "%s Control"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) /* Roland SPD-SX */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) CONTROL_PORT(0x0582, 0x0145, 0, "%s Control"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) EXTERNAL_PORT(0x0582, 0x0145, 1, "%s MIDI"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) /* Roland A-Series */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) CONTROL_PORT(0x0582, 0x0156, 0, "%s Keyboard"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) EXTERNAL_PORT(0x0582, 0x0156, 1, "%s MIDI"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) /* Roland INTEGRA-7 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) ROLAND_SYNTH_PORT(0x0582, 0x015b, 0, "%s Synth", 128),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) CONTROL_PORT(0x0582, 0x015b, 1, "%s Control"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) /* M-Audio MidiSport 8x8 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) CONTROL_PORT(0x0763, 0x1031, 8, "%s Control"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) CONTROL_PORT(0x0763, 0x1033, 8, "%s Control"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) /* MOTU Fastlane */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) EXTERNAL_PORT(0x07fd, 0x0001, 0, "%s MIDI A"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) EXTERNAL_PORT(0x07fd, 0x0001, 1, "%s MIDI B"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) /* Emagic Unitor8/AMT8/MT4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) EXTERNAL_PORT(0x086a, 0x0001, 8, "%s Broadcast"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) EXTERNAL_PORT(0x086a, 0x0002, 8, "%s Broadcast"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) EXTERNAL_PORT(0x086a, 0x0003, 4, "%s Broadcast"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) /* Akai MPD16 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) CONTROL_PORT(0x09e8, 0x0062, 0, "%s Control"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) PORT_INFO(0x09e8, 0x0062, 1, "%s MIDI", 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) SNDRV_SEQ_PORT_TYPE_HARDWARE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) /* Access Music Virus TI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) EXTERNAL_PORT(0x133e, 0x0815, 0, "%s MIDI"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) PORT_INFO(0x133e, 0x0815, 1, "%s Synth", 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) SNDRV_SEQ_PORT_TYPE_HARDWARE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) SNDRV_SEQ_PORT_TYPE_SYNTHESIZER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) static struct port_info *find_port_info(struct snd_usb_midi *umidi, int number)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) for (i = 0; i < ARRAY_SIZE(snd_usbmidi_port_info); ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) if (snd_usbmidi_port_info[i].id == umidi->usb_id &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) snd_usbmidi_port_info[i].port == number)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) return &snd_usbmidi_port_info[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) static void snd_usbmidi_get_port_info(struct snd_rawmidi *rmidi, int number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) struct snd_seq_port_info *seq_port_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) struct snd_usb_midi *umidi = rmidi->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) struct port_info *port_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) /* TODO: read port flags from descriptors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) port_info = find_port_info(umidi, number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) if (port_info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) seq_port_info->type = port_info->seq_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) seq_port_info->midi_voices = port_info->voices;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) static void snd_usbmidi_init_substream(struct snd_usb_midi *umidi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) int stream, int number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) struct snd_rawmidi_substream **rsubstream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) struct port_info *port_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) const char *name_format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) struct snd_rawmidi_substream *substream =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) snd_usbmidi_find_substream(umidi, stream, number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) if (!substream) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) dev_err(&umidi->dev->dev, "substream %d:%d not found\n", stream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) /* TODO: read port name from jack descriptor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) port_info = find_port_info(umidi, number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) name_format = port_info ? port_info->name : "%s MIDI %d";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) snprintf(substream->name, sizeof(substream->name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) name_format, umidi->card->shortname, number + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) *rsubstream = substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) * Creates the endpoints and their ports.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) static int snd_usbmidi_create_endpoints(struct snd_usb_midi *umidi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) struct snd_usb_midi_endpoint_info *endpoints)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) int i, j, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) int out_ports = 0, in_ports = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) if (endpoints[i].out_cables) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) err = snd_usbmidi_out_endpoint_create(umidi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) &endpoints[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) &umidi->endpoints[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) if (endpoints[i].in_cables) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) err = snd_usbmidi_in_endpoint_create(umidi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) &endpoints[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) &umidi->endpoints[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) for (j = 0; j < 0x10; ++j) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) if (endpoints[i].out_cables & (1 << j)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) snd_usbmidi_init_substream(umidi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) SNDRV_RAWMIDI_STREAM_OUTPUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) out_ports,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) &umidi->endpoints[i].out->ports[j].substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) ++out_ports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) if (endpoints[i].in_cables & (1 << j)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) snd_usbmidi_init_substream(umidi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) SNDRV_RAWMIDI_STREAM_INPUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) in_ports,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) &umidi->endpoints[i].in->ports[j].substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) ++in_ports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) dev_dbg(&umidi->dev->dev, "created %d output and %d input ports\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) out_ports, in_ports);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) static struct usb_ms_endpoint_descriptor *find_usb_ms_endpoint_descriptor(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) struct usb_host_endpoint *hostep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) unsigned char *extra = hostep->extra;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) int extralen = hostep->extralen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) while (extralen > 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) struct usb_ms_endpoint_descriptor *ms_ep =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) (struct usb_ms_endpoint_descriptor *)extra;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) if (ms_ep->bLength > 3 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) ms_ep->bDescriptorType == USB_DT_CS_ENDPOINT &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) ms_ep->bDescriptorSubtype == UAC_MS_GENERAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) return ms_ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) if (!extra[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) extralen -= extra[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) extra += extra[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) * Returns MIDIStreaming device capabilities.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) static int snd_usbmidi_get_ms_info(struct snd_usb_midi *umidi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) struct snd_usb_midi_endpoint_info *endpoints)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) struct usb_interface *intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) struct usb_host_interface *hostif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) struct usb_interface_descriptor *intfd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) struct usb_ms_header_descriptor *ms_header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) struct usb_host_endpoint *hostep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) struct usb_endpoint_descriptor *ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) struct usb_ms_endpoint_descriptor *ms_ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) int i, epidx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) intf = umidi->iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) if (!intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) hostif = &intf->altsetting[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) intfd = get_iface_desc(hostif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) ms_header = (struct usb_ms_header_descriptor *)hostif->extra;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) if (hostif->extralen >= 7 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) ms_header->bLength >= 7 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) ms_header->bDescriptorType == USB_DT_CS_INTERFACE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) ms_header->bDescriptorSubtype == UAC_HEADER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) dev_dbg(&umidi->dev->dev, "MIDIStreaming version %02x.%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) ms_header->bcdMSC[1], ms_header->bcdMSC[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) dev_warn(&umidi->dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) "MIDIStreaming interface descriptor not found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) epidx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) for (i = 0; i < intfd->bNumEndpoints; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) hostep = &hostif->endpoint[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) ep = get_ep_desc(hostep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) if (!usb_endpoint_xfer_bulk(ep) && !usb_endpoint_xfer_int(ep))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) ms_ep = find_usb_ms_endpoint_descriptor(hostep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) if (!ms_ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) if (ms_ep->bLength <= sizeof(*ms_ep))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) if (ms_ep->bNumEmbMIDIJack > 0x10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) if (ms_ep->bLength < sizeof(*ms_ep) + ms_ep->bNumEmbMIDIJack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) if (usb_endpoint_dir_out(ep)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) if (endpoints[epidx].out_ep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) if (++epidx >= MIDI_MAX_ENDPOINTS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) dev_warn(&umidi->dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) "too many endpoints\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) endpoints[epidx].out_ep = usb_endpoint_num(ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) if (usb_endpoint_xfer_int(ep))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) endpoints[epidx].out_interval = ep->bInterval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) else if (snd_usb_get_speed(umidi->dev) == USB_SPEED_LOW)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) * Low speed bulk transfers don't exist, so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) * force interrupt transfers for devices like
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) * ESI MIDI Mate that try to use them anyway.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) endpoints[epidx].out_interval = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) endpoints[epidx].out_cables =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) (1 << ms_ep->bNumEmbMIDIJack) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) dev_dbg(&umidi->dev->dev, "EP %02X: %d jack(s)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) ep->bEndpointAddress, ms_ep->bNumEmbMIDIJack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) if (endpoints[epidx].in_ep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) if (++epidx >= MIDI_MAX_ENDPOINTS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) dev_warn(&umidi->dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) "too many endpoints\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) endpoints[epidx].in_ep = usb_endpoint_num(ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) if (usb_endpoint_xfer_int(ep))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) endpoints[epidx].in_interval = ep->bInterval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) else if (snd_usb_get_speed(umidi->dev) == USB_SPEED_LOW)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) endpoints[epidx].in_interval = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) endpoints[epidx].in_cables =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) (1 << ms_ep->bNumEmbMIDIJack) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) dev_dbg(&umidi->dev->dev, "EP %02X: %d jack(s)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) ep->bEndpointAddress, ms_ep->bNumEmbMIDIJack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) static int roland_load_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) struct snd_ctl_elem_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) static const char *const names[] = { "High Load", "Light Load" };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) return snd_ctl_enum_info(info, 1, 2, names);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) static int roland_load_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) struct snd_ctl_elem_value *value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) value->value.enumerated.item[0] = kcontrol->private_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) static int roland_load_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) struct snd_ctl_elem_value *value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) struct snd_usb_midi *umidi = kcontrol->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) int changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) if (value->value.enumerated.item[0] > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) mutex_lock(&umidi->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) changed = value->value.enumerated.item[0] != kcontrol->private_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) if (changed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) kcontrol->private_value = value->value.enumerated.item[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) mutex_unlock(&umidi->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) return changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) static const struct snd_kcontrol_new roland_load_ctl = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) .name = "MIDI Input Mode",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) .info = roland_load_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) .get = roland_load_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) .put = roland_load_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) .private_value = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) * On Roland devices, use the second alternate setting to be able to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) * the interrupt input endpoint.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) static void snd_usbmidi_switch_roland_altsetting(struct snd_usb_midi *umidi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) struct usb_interface *intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) struct usb_host_interface *hostif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) struct usb_interface_descriptor *intfd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) intf = umidi->iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) if (!intf || intf->num_altsetting != 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) hostif = &intf->altsetting[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) intfd = get_iface_desc(hostif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) /* If either or both of the endpoints support interrupt transfer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) * then use the alternate setting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) if (intfd->bNumEndpoints != 2 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) !((get_endpoint(hostif, 0)->bmAttributes &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) (get_endpoint(hostif, 1)->bmAttributes &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) dev_dbg(&umidi->dev->dev, "switching to altsetting %d with int ep\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) intfd->bAlternateSetting);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) usb_set_interface(umidi->dev, intfd->bInterfaceNumber,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) intfd->bAlternateSetting);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) umidi->roland_load_ctl = snd_ctl_new1(&roland_load_ctl, umidi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) if (snd_ctl_add(umidi->card, umidi->roland_load_ctl) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) umidi->roland_load_ctl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) * Try to find any usable endpoints in the interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) static int snd_usbmidi_detect_endpoints(struct snd_usb_midi *umidi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) struct snd_usb_midi_endpoint_info *endpoint,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) int max_endpoints)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) struct usb_interface *intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) struct usb_host_interface *hostif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) struct usb_interface_descriptor *intfd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) struct usb_endpoint_descriptor *epd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) int i, out_eps = 0, in_eps = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) if (USB_ID_VENDOR(umidi->usb_id) == 0x0582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) snd_usbmidi_switch_roland_altsetting(umidi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) if (endpoint[0].out_ep || endpoint[0].in_ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) intf = umidi->iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) if (!intf || intf->num_altsetting < 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) hostif = intf->cur_altsetting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) intfd = get_iface_desc(hostif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) for (i = 0; i < intfd->bNumEndpoints; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) epd = get_endpoint(hostif, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) if (!usb_endpoint_xfer_bulk(epd) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) !usb_endpoint_xfer_int(epd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) if (out_eps < max_endpoints &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) usb_endpoint_dir_out(epd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) endpoint[out_eps].out_ep = usb_endpoint_num(epd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) if (usb_endpoint_xfer_int(epd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) endpoint[out_eps].out_interval = epd->bInterval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) ++out_eps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) if (in_eps < max_endpoints &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) usb_endpoint_dir_in(epd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) endpoint[in_eps].in_ep = usb_endpoint_num(epd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) if (usb_endpoint_xfer_int(epd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) endpoint[in_eps].in_interval = epd->bInterval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) ++in_eps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) return (out_eps || in_eps) ? 0 : -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) * Detects the endpoints for one-port-per-endpoint protocols.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) static int snd_usbmidi_detect_per_port_endpoints(struct snd_usb_midi *umidi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) struct snd_usb_midi_endpoint_info *endpoints)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) int err, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) err = snd_usbmidi_detect_endpoints(umidi, endpoints, MIDI_MAX_ENDPOINTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) if (endpoints[i].out_ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) endpoints[i].out_cables = 0x0001;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) if (endpoints[i].in_ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) endpoints[i].in_cables = 0x0001;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) * Detects the endpoints and ports of Yamaha devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) static int snd_usbmidi_detect_yamaha(struct snd_usb_midi *umidi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) struct snd_usb_midi_endpoint_info *endpoint)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) struct usb_interface *intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) struct usb_host_interface *hostif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) struct usb_interface_descriptor *intfd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) uint8_t *cs_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) intf = umidi->iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) if (!intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) hostif = intf->altsetting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) intfd = get_iface_desc(hostif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) if (intfd->bNumEndpoints < 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) * For each port there is one MIDI_IN/OUT_JACK descriptor, not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) * necessarily with any useful contents. So simply count 'em.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) for (cs_desc = hostif->extra;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) cs_desc < hostif->extra + hostif->extralen && cs_desc[0] >= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) cs_desc += cs_desc[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) if (cs_desc[1] == USB_DT_CS_INTERFACE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) if (cs_desc[2] == UAC_MIDI_IN_JACK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) endpoint->in_cables =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) (endpoint->in_cables << 1) | 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) else if (cs_desc[2] == UAC_MIDI_OUT_JACK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) endpoint->out_cables =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) (endpoint->out_cables << 1) | 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) if (!endpoint->in_cables && !endpoint->out_cables)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) return snd_usbmidi_detect_endpoints(umidi, endpoint, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) * Detects the endpoints and ports of Roland devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) static int snd_usbmidi_detect_roland(struct snd_usb_midi *umidi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) struct snd_usb_midi_endpoint_info *endpoint)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) struct usb_interface *intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) struct usb_host_interface *hostif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) u8 *cs_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) intf = umidi->iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) if (!intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) hostif = intf->altsetting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) * Some devices have a descriptor <06 24 F1 02 <inputs> <outputs>>,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) * some have standard class descriptors, or both kinds, or neither.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) for (cs_desc = hostif->extra;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) cs_desc < hostif->extra + hostif->extralen && cs_desc[0] >= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) cs_desc += cs_desc[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) if (cs_desc[0] >= 6 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) cs_desc[1] == USB_DT_CS_INTERFACE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) cs_desc[2] == 0xf1 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) cs_desc[3] == 0x02) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) if (cs_desc[4] > 0x10 || cs_desc[5] > 0x10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) endpoint->in_cables = (1 << cs_desc[4]) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) endpoint->out_cables = (1 << cs_desc[5]) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) return snd_usbmidi_detect_endpoints(umidi, endpoint, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) } else if (cs_desc[0] >= 7 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) cs_desc[1] == USB_DT_CS_INTERFACE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) cs_desc[2] == UAC_HEADER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) return snd_usbmidi_get_ms_info(umidi, endpoint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) * Creates the endpoints and their ports for Midiman devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) static int snd_usbmidi_create_endpoints_midiman(struct snd_usb_midi *umidi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) struct snd_usb_midi_endpoint_info *endpoint)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) struct snd_usb_midi_endpoint_info ep_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) struct usb_interface *intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) struct usb_host_interface *hostif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) struct usb_interface_descriptor *intfd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) struct usb_endpoint_descriptor *epd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) int cable, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) intf = umidi->iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) if (!intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) hostif = intf->altsetting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) intfd = get_iface_desc(hostif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) * The various MidiSport devices have more or less random endpoint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) * numbers, so we have to identify the endpoints by their index in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) * the descriptor array, like the driver for that other OS does.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) * There is one interrupt input endpoint for all input ports, one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) * bulk output endpoint for even-numbered ports, and one for odd-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) * numbered ports. Both bulk output endpoints have corresponding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) * input bulk endpoints (at indices 1 and 3) which aren't used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) if (intfd->bNumEndpoints < (endpoint->out_cables > 0x0001 ? 5 : 3)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) dev_dbg(&umidi->dev->dev, "not enough endpoints\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) epd = get_endpoint(hostif, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) if (!usb_endpoint_dir_in(epd) || !usb_endpoint_xfer_int(epd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) dev_dbg(&umidi->dev->dev, "endpoint[0] isn't interrupt\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) epd = get_endpoint(hostif, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) if (!usb_endpoint_dir_out(epd) || !usb_endpoint_xfer_bulk(epd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) dev_dbg(&umidi->dev->dev, "endpoint[2] isn't bulk output\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) if (endpoint->out_cables > 0x0001) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) epd = get_endpoint(hostif, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) if (!usb_endpoint_dir_out(epd) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) !usb_endpoint_xfer_bulk(epd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) dev_dbg(&umidi->dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) "endpoint[4] isn't bulk output\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) ep_info.out_ep = get_endpoint(hostif, 2)->bEndpointAddress &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) USB_ENDPOINT_NUMBER_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) ep_info.out_interval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) ep_info.out_cables = endpoint->out_cables & 0x5555;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) err = snd_usbmidi_out_endpoint_create(umidi, &ep_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) &umidi->endpoints[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) ep_info.in_ep = get_endpoint(hostif, 0)->bEndpointAddress &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) USB_ENDPOINT_NUMBER_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) ep_info.in_interval = get_endpoint(hostif, 0)->bInterval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) ep_info.in_cables = endpoint->in_cables;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) err = snd_usbmidi_in_endpoint_create(umidi, &ep_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) &umidi->endpoints[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) if (endpoint->out_cables > 0x0001) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) ep_info.out_ep = get_endpoint(hostif, 4)->bEndpointAddress &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) USB_ENDPOINT_NUMBER_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) ep_info.out_cables = endpoint->out_cables & 0xaaaa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) err = snd_usbmidi_out_endpoint_create(umidi, &ep_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) &umidi->endpoints[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) for (cable = 0; cable < 0x10; ++cable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) if (endpoint->out_cables & (1 << cable))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248) snd_usbmidi_init_substream(umidi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) SNDRV_RAWMIDI_STREAM_OUTPUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) cable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) &umidi->endpoints[cable & 1].out->ports[cable].substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252) if (endpoint->in_cables & (1 << cable))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) snd_usbmidi_init_substream(umidi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) SNDRV_RAWMIDI_STREAM_INPUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255) cable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) &umidi->endpoints[0].in->ports[cable].substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) static const struct snd_rawmidi_global_ops snd_usbmidi_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) .get_port_info = snd_usbmidi_get_port_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) static int snd_usbmidi_create_rawmidi(struct snd_usb_midi *umidi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) int out_ports, int in_ports)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) struct snd_rawmidi *rmidi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) err = snd_rawmidi_new(umidi->card, "USB MIDI",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) umidi->next_midi_device++,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) out_ports, in_ports, &rmidi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) strcpy(rmidi->name, umidi->card->shortname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) rmidi->info_flags = SNDRV_RAWMIDI_INFO_OUTPUT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) SNDRV_RAWMIDI_INFO_INPUT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) SNDRV_RAWMIDI_INFO_DUPLEX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) rmidi->ops = &snd_usbmidi_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) rmidi->private_data = umidi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) rmidi->private_free = snd_usbmidi_rawmidi_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) &snd_usbmidi_output_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) &snd_usbmidi_input_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288) umidi->rmidi = rmidi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293) * Temporarily stop input.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) void snd_usbmidi_input_stop(struct list_head *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) struct snd_usb_midi *umidi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) unsigned int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) umidi = list_entry(p, struct snd_usb_midi, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) if (!umidi->input_running)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) struct snd_usb_midi_endpoint *ep = &umidi->endpoints[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) if (ep->in)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) for (j = 0; j < INPUT_URBS; ++j)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) usb_kill_urb(ep->in->urbs[j]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) umidi->input_running = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) EXPORT_SYMBOL(snd_usbmidi_input_stop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) static void snd_usbmidi_input_start_ep(struct snd_usb_midi *umidi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) struct snd_usb_midi_in_endpoint *ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) if (!ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) for (i = 0; i < INPUT_URBS; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) struct urb *urb = ep->urbs[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) spin_lock_irqsave(&umidi->disc_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) if (!atomic_read(&urb->use_count)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) urb->dev = ep->umidi->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) snd_usbmidi_submit_urb(urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) spin_unlock_irqrestore(&umidi->disc_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) * Resume input after a call to snd_usbmidi_input_stop().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) void snd_usbmidi_input_start(struct list_head *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) struct snd_usb_midi *umidi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) umidi = list_entry(p, struct snd_usb_midi, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) if (umidi->input_running || !umidi->opened[1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) snd_usbmidi_input_start_ep(umidi, umidi->endpoints[i].in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) umidi->input_running = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) EXPORT_SYMBOL(snd_usbmidi_input_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) * Prepare for suspend. Typically called from the USB suspend callback.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) void snd_usbmidi_suspend(struct list_head *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) struct snd_usb_midi *umidi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356) umidi = list_entry(p, struct snd_usb_midi, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357) mutex_lock(&umidi->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) snd_usbmidi_input_stop(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) mutex_unlock(&umidi->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) EXPORT_SYMBOL(snd_usbmidi_suspend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) * Resume. Typically called from the USB resume callback.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) void snd_usbmidi_resume(struct list_head *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) struct snd_usb_midi *umidi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) umidi = list_entry(p, struct snd_usb_midi, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) mutex_lock(&umidi->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) snd_usbmidi_input_start(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) mutex_unlock(&umidi->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) EXPORT_SYMBOL(snd_usbmidi_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378) * Creates and registers everything needed for a MIDI streaming interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) int __snd_usbmidi_create(struct snd_card *card,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) struct usb_interface *iface,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) struct list_head *midi_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) const struct snd_usb_audio_quirk *quirk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) unsigned int usb_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) struct snd_usb_midi *umidi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) struct snd_usb_midi_endpoint_info endpoints[MIDI_MAX_ENDPOINTS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) int out_ports, in_ports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) int i, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) umidi = kzalloc(sizeof(*umidi), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) if (!umidi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) umidi->dev = interface_to_usbdev(iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) umidi->card = card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396) umidi->iface = iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) umidi->quirk = quirk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) umidi->usb_protocol_ops = &snd_usbmidi_standard_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) spin_lock_init(&umidi->disc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400) init_rwsem(&umidi->disc_rwsem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) mutex_init(&umidi->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402) if (!usb_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) usb_id = USB_ID(le16_to_cpu(umidi->dev->descriptor.idVendor),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404) le16_to_cpu(umidi->dev->descriptor.idProduct));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) umidi->usb_id = usb_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) timer_setup(&umidi->error_timer, snd_usbmidi_error_timer, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) /* detect the endpoint(s) to use */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409) memset(endpoints, 0, sizeof(endpoints));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410) switch (quirk ? quirk->type : QUIRK_MIDI_STANDARD_INTERFACE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) case QUIRK_MIDI_STANDARD_INTERFACE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412) err = snd_usbmidi_get_ms_info(umidi, endpoints);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413) if (umidi->usb_id == USB_ID(0x0763, 0x0150)) /* M-Audio Uno */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414) umidi->usb_protocol_ops =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) &snd_usbmidi_maudio_broken_running_status_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417) case QUIRK_MIDI_US122L:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418) umidi->usb_protocol_ops = &snd_usbmidi_122l_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420) case QUIRK_MIDI_FIXED_ENDPOINT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421) memcpy(&endpoints[0], quirk->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422) sizeof(struct snd_usb_midi_endpoint_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423) err = snd_usbmidi_detect_endpoints(umidi, &endpoints[0], 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) case QUIRK_MIDI_YAMAHA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426) err = snd_usbmidi_detect_yamaha(umidi, &endpoints[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) case QUIRK_MIDI_ROLAND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) err = snd_usbmidi_detect_roland(umidi, &endpoints[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) case QUIRK_MIDI_MIDIMAN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) umidi->usb_protocol_ops = &snd_usbmidi_midiman_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) memcpy(&endpoints[0], quirk->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) sizeof(struct snd_usb_midi_endpoint_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) case QUIRK_MIDI_NOVATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438) umidi->usb_protocol_ops = &snd_usbmidi_novation_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) case QUIRK_MIDI_RAW_BYTES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) umidi->usb_protocol_ops = &snd_usbmidi_raw_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444) * Interface 1 contains isochronous endpoints, but with the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) * numbers as in interface 0. Since it is interface 1 that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) * USB core has most recently seen, these descriptors are now
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) * associated with the endpoint numbers. This will foul up our
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) * attempts to submit bulk/interrupt URBs to the endpoints in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) * interface 0, so we have to make sure that the USB core looks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) * again at interface 0 by calling usb_set_interface() on it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) if (umidi->usb_id == USB_ID(0x07fd, 0x0001)) /* MOTU Fastlane */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) usb_set_interface(umidi->dev, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) case QUIRK_MIDI_EMAGIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457) umidi->usb_protocol_ops = &snd_usbmidi_emagic_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) memcpy(&endpoints[0], quirk->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459) sizeof(struct snd_usb_midi_endpoint_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460) err = snd_usbmidi_detect_endpoints(umidi, &endpoints[0], 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) case QUIRK_MIDI_CME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) umidi->usb_protocol_ops = &snd_usbmidi_cme_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) case QUIRK_MIDI_AKAI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) umidi->usb_protocol_ops = &snd_usbmidi_akai_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) /* endpoint 1 is input-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) endpoints[1].out_cables = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472) case QUIRK_MIDI_FTDI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) umidi->usb_protocol_ops = &snd_usbmidi_ftdi_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) /* set baud rate to 31250 (48 MHz / 16 / 96) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) err = usb_control_msg(umidi->dev, usb_sndctrlpipe(umidi->dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) 3, 0x40, 0x60, 0, NULL, 0, 1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) case QUIRK_MIDI_CH345:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) umidi->usb_protocol_ops = &snd_usbmidi_ch345_broken_sysex_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) dev_err(&umidi->dev->dev, "invalid quirk type %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) quirk->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490) err = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494) goto free_midi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) /* create rawmidi device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497) out_ports = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) in_ports = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) out_ports += hweight16(endpoints[i].out_cables);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) in_ports += hweight16(endpoints[i].in_cables);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503) err = snd_usbmidi_create_rawmidi(umidi, out_ports, in_ports);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) goto free_midi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) /* create endpoint/port structures */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508) if (quirk && quirk->type == QUIRK_MIDI_MIDIMAN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509) err = snd_usbmidi_create_endpoints_midiman(umidi, &endpoints[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511) err = snd_usbmidi_create_endpoints(umidi, endpoints);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) usb_autopm_get_interface_no_resume(umidi->iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517) list_add_tail(&umidi->list, midi_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520) free_midi:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) kfree(umidi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525) EXPORT_SYMBOL(__snd_usbmidi_create);