2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* usbmidi.c - ALSA USB MIDI driver
|
|
|
|
*
|
2009-10-22 15:06:19 +08:00
|
|
|
* Copyright (c) 2002-2009 Clemens Ladisch
|
2005-04-17 06:20:36 +08:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Based on the OSS usb-midi driver by NAGANO Daisuke,
|
|
|
|
* NetBSD's umidi driver by Takuya SHIOZAKI,
|
|
|
|
* the "USB Device Class Definition for MIDI Devices" by Roland
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions, and the following disclaimer,
|
|
|
|
* without modification.
|
|
|
|
* 2. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* Alternatively, this software may be distributed and/or modified under the
|
|
|
|
* terms of the GNU General Public License as published by the Free Software
|
|
|
|
* Foundation; either version 2 of the License, or (at your option) any later
|
|
|
|
* version.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/bitops.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/slab.h>
|
2005-08-02 21:26:52 +08:00
|
|
|
#include <linux/timer.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/usb.h>
|
2009-07-13 19:48:36 +08:00
|
|
|
#include <linux/wait.h>
|
2010-02-23 06:49:13 +08:00
|
|
|
#include <linux/usb/audio.h>
|
2011-07-16 00:38:28 +08:00
|
|
|
#include <linux/module.h>
|
2010-02-23 06:49:13 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <sound/core.h>
|
2009-10-22 15:06:19 +08:00
|
|
|
#include <sound/control.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <sound/rawmidi.h>
|
2006-05-02 22:22:12 +08:00
|
|
|
#include <sound/asequencer.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include "usbaudio.h"
|
2010-03-05 02:46:13 +08:00
|
|
|
#include "midi.h"
|
2011-03-11 21:51:12 +08:00
|
|
|
#include "power.h"
|
2010-03-05 02:46:13 +08:00
|
|
|
#include "helper.h"
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* define this to log all USB packets
|
|
|
|
*/
|
|
|
|
/* #define DUMP_PACKETS */
|
|
|
|
|
2005-08-02 21:26:52 +08:00
|
|
|
/*
|
2014-09-19 23:32:23 +08:00
|
|
|
* how long to wait after some USB errors, so that hub_wq can disconnect() us
|
2005-08-02 21:26:52 +08:00
|
|
|
* without too many spurious errors
|
|
|
|
*/
|
|
|
|
#define ERROR_DELAY_JIFFIES (HZ / 10)
|
|
|
|
|
2009-07-13 19:43:59 +08:00
|
|
|
#define OUTPUT_URBS 7
|
2009-07-13 19:40:36 +08:00
|
|
|
#define INPUT_URBS 7
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
|
|
|
|
MODULE_DESCRIPTION("USB Audio/MIDI helper module");
|
|
|
|
MODULE_LICENSE("Dual BSD/GPL");
|
|
|
|
|
|
|
|
|
|
|
|
struct usb_ms_header_descriptor {
|
|
|
|
__u8 bLength;
|
|
|
|
__u8 bDescriptorType;
|
|
|
|
__u8 bDescriptorSubtype;
|
|
|
|
__u8 bcdMSC[2];
|
|
|
|
__le16 wTotalLength;
|
|
|
|
} __attribute__ ((packed));
|
|
|
|
|
|
|
|
struct usb_ms_endpoint_descriptor {
|
|
|
|
__u8 bLength;
|
|
|
|
__u8 bDescriptorType;
|
|
|
|
__u8 bDescriptorSubtype;
|
|
|
|
__u8 bNumEmbMIDIJack;
|
|
|
|
__u8 baAssocJackID[0];
|
|
|
|
} __attribute__ ((packed));
|
|
|
|
|
2005-11-17 22:08:02 +08:00
|
|
|
struct snd_usb_midi_in_endpoint;
|
|
|
|
struct snd_usb_midi_out_endpoint;
|
|
|
|
struct snd_usb_midi_endpoint;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
struct usb_protocol_ops {
|
2005-11-17 22:08:02 +08:00
|
|
|
void (*input)(struct snd_usb_midi_in_endpoint*, uint8_t*, int);
|
2009-07-13 19:43:59 +08:00
|
|
|
void (*output)(struct snd_usb_midi_out_endpoint *ep, struct urb *urb);
|
2005-04-17 06:20:36 +08:00
|
|
|
void (*output_packet)(struct urb*, uint8_t, uint8_t, uint8_t, uint8_t);
|
2014-08-06 00:44:51 +08:00
|
|
|
void (*init_out_endpoint)(struct snd_usb_midi_out_endpoint *);
|
|
|
|
void (*finish_out_endpoint)(struct snd_usb_midi_out_endpoint *);
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct snd_usb_midi {
|
2009-11-16 19:23:46 +08:00
|
|
|
struct usb_device *dev;
|
|
|
|
struct snd_card *card;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct usb_interface *iface;
|
2005-11-17 22:08:02 +08:00
|
|
|
const struct snd_usb_audio_quirk *quirk;
|
|
|
|
struct snd_rawmidi *rmidi;
|
2015-12-11 22:52:37 +08:00
|
|
|
const struct usb_protocol_ops *usb_protocol_ops;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct list_head list;
|
2005-08-02 21:26:52 +08:00
|
|
|
struct timer_list error_timer;
|
2008-02-23 01:34:44 +08:00
|
|
|
spinlock_t disc_lock;
|
2012-12-03 18:12:46 +08:00
|
|
|
struct rw_semaphore disc_rwsem;
|
2009-10-22 15:06:19 +08:00
|
|
|
struct mutex mutex;
|
2009-11-16 19:23:46 +08:00
|
|
|
u32 usb_id;
|
|
|
|
int next_midi_device;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
struct snd_usb_midi_endpoint {
|
2005-11-17 22:08:02 +08:00
|
|
|
struct snd_usb_midi_out_endpoint *out;
|
|
|
|
struct snd_usb_midi_in_endpoint *in;
|
2005-04-17 06:20:36 +08:00
|
|
|
} endpoints[MIDI_MAX_ENDPOINTS];
|
|
|
|
unsigned long input_triggered;
|
2012-12-03 18:30:50 +08:00
|
|
|
unsigned int opened[2];
|
2008-02-23 01:34:44 +08:00
|
|
|
unsigned char disconnected;
|
2012-12-03 18:30:50 +08:00
|
|
|
unsigned char input_running;
|
2009-10-22 15:06:19 +08:00
|
|
|
|
|
|
|
struct snd_kcontrol *roland_load_ctl;
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct snd_usb_midi_out_endpoint {
|
2014-08-06 00:44:51 +08:00
|
|
|
struct snd_usb_midi *umidi;
|
2009-07-13 19:43:59 +08:00
|
|
|
struct out_urb_context {
|
|
|
|
struct urb *urb;
|
|
|
|
struct snd_usb_midi_out_endpoint *ep;
|
|
|
|
} urbs[OUTPUT_URBS];
|
|
|
|
unsigned int active_urbs;
|
2009-07-13 19:48:36 +08:00
|
|
|
unsigned int drain_urbs;
|
2005-04-17 06:20:36 +08:00
|
|
|
int max_transfer; /* size of urb buffer */
|
|
|
|
struct tasklet_struct tasklet;
|
2009-07-13 19:48:36 +08:00
|
|
|
unsigned int next_urb;
|
2005-04-17 06:20:36 +08:00
|
|
|
spinlock_t buffer_lock;
|
|
|
|
|
|
|
|
struct usbmidi_out_port {
|
2014-08-06 00:44:51 +08:00
|
|
|
struct snd_usb_midi_out_endpoint *ep;
|
2005-11-17 22:08:02 +08:00
|
|
|
struct snd_rawmidi_substream *substream;
|
2005-04-17 06:20:36 +08:00
|
|
|
int active;
|
|
|
|
uint8_t cable; /* cable number << 4 */
|
|
|
|
uint8_t state;
|
|
|
|
#define STATE_UNKNOWN 0
|
|
|
|
#define STATE_1PARAM 1
|
|
|
|
#define STATE_2PARAM_1 2
|
|
|
|
#define STATE_2PARAM_2 3
|
|
|
|
#define STATE_SYSEX_0 4
|
|
|
|
#define STATE_SYSEX_1 5
|
|
|
|
#define STATE_SYSEX_2 6
|
|
|
|
uint8_t data[2];
|
|
|
|
} ports[0x10];
|
|
|
|
int current_port;
|
2009-07-13 19:48:36 +08:00
|
|
|
|
|
|
|
wait_queue_head_t drain_wait;
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct snd_usb_midi_in_endpoint {
|
2014-08-06 00:44:51 +08:00
|
|
|
struct snd_usb_midi *umidi;
|
|
|
|
struct urb *urbs[INPUT_URBS];
|
2005-04-17 06:20:36 +08:00
|
|
|
struct usbmidi_in_port {
|
2005-11-17 22:08:02 +08:00
|
|
|
struct snd_rawmidi_substream *substream;
|
2007-05-07 15:28:53 +08:00
|
|
|
u8 running_status_length;
|
2005-04-17 06:20:36 +08:00
|
|
|
} ports[0x10];
|
2005-08-02 21:26:52 +08:00
|
|
|
u8 seen_f5;
|
2015-11-16 05:39:08 +08:00
|
|
|
bool in_sysex;
|
|
|
|
u8 last_cin;
|
2005-08-02 21:26:52 +08:00
|
|
|
u8 error_resubmit;
|
2005-04-17 06:20:36 +08:00
|
|
|
int current_port;
|
|
|
|
};
|
|
|
|
|
2014-08-06 00:44:51 +08:00
|
|
|
static void snd_usbmidi_do_output(struct snd_usb_midi_out_endpoint *ep);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static const uint8_t snd_usbmidi_cin_length[] = {
|
|
|
|
0, 0, 2, 3, 3, 1, 2, 3, 3, 3, 3, 3, 2, 2, 3, 1
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Submits the URB, with error handling.
|
|
|
|
*/
|
2014-08-06 00:44:51 +08:00
|
|
|
static int snd_usbmidi_submit_urb(struct urb *urb, gfp_t flags)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int err = usb_submit_urb(urb, flags);
|
|
|
|
if (err < 0 && err != -ENODEV)
|
2014-02-26 20:02:17 +08:00
|
|
|
dev_err(&urb->dev->dev, "usb_submit_urb: %d\n", err);
|
2005-04-17 06:20:36 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Error handling for URB completion functions.
|
|
|
|
*/
|
2014-02-26 20:02:17 +08:00
|
|
|
static int snd_usbmidi_urb_error(const struct urb *urb)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2014-02-26 20:02:17 +08:00
|
|
|
switch (urb->status) {
|
2005-08-02 21:26:52 +08:00
|
|
|
/* manually unlinked, or device gone */
|
|
|
|
case -ENOENT:
|
|
|
|
case -ECONNRESET:
|
|
|
|
case -ESHUTDOWN:
|
|
|
|
case -ENODEV:
|
|
|
|
return -ENODEV;
|
|
|
|
/* errors that might occur during unplugging */
|
2006-09-19 13:49:02 +08:00
|
|
|
case -EPROTO:
|
|
|
|
case -ETIME:
|
|
|
|
case -EILSEQ:
|
2005-08-02 21:26:52 +08:00
|
|
|
return -EIO;
|
|
|
|
default:
|
2014-02-26 20:02:17 +08:00
|
|
|
dev_err(&urb->dev->dev, "urb status %d\n", urb->status);
|
2005-08-02 21:26:52 +08:00
|
|
|
return 0; /* continue */
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Receives a chunk of MIDI data.
|
|
|
|
*/
|
2014-08-06 00:44:51 +08:00
|
|
|
static void snd_usbmidi_input_data(struct snd_usb_midi_in_endpoint *ep,
|
|
|
|
int portidx, uint8_t *data, int length)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2014-08-06 00:44:51 +08:00
|
|
|
struct usbmidi_in_port *port = &ep->ports[portidx];
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (!port->substream) {
|
2014-02-26 20:02:17 +08:00
|
|
|
dev_dbg(&ep->umidi->dev->dev, "unexpected port %d!\n", portidx);
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!test_bit(port->substream->number, &ep->umidi->input_triggered))
|
|
|
|
return;
|
|
|
|
snd_rawmidi_receive(port->substream, data, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DUMP_PACKETS
|
|
|
|
static void dump_urb(const char *type, const u8 *data, int length)
|
|
|
|
{
|
|
|
|
snd_printk(KERN_DEBUG "%s packet: [", type);
|
|
|
|
for (; length > 0; ++data, --length)
|
|
|
|
printk(" %02x", *data);
|
|
|
|
printk(" ]\n");
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define dump_urb(type, data, length) /* nothing */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Processes the data read from the device.
|
|
|
|
*/
|
2014-08-06 00:44:51 +08:00
|
|
|
static void snd_usbmidi_in_urb_complete(struct urb *urb)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2014-08-06 00:44:51 +08:00
|
|
|
struct snd_usb_midi_in_endpoint *ep = urb->context;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (urb->status == 0) {
|
|
|
|
dump_urb("received", urb->transfer_buffer, urb->actual_length);
|
|
|
|
ep->umidi->usb_protocol_ops->input(ep, urb->transfer_buffer,
|
|
|
|
urb->actual_length);
|
|
|
|
} else {
|
2014-02-26 20:02:17 +08:00
|
|
|
int err = snd_usbmidi_urb_error(urb);
|
2005-08-02 21:26:52 +08:00
|
|
|
if (err < 0) {
|
|
|
|
if (err != -ENODEV) {
|
|
|
|
ep->error_resubmit = 1;
|
|
|
|
mod_timer(&ep->umidi->error_timer,
|
|
|
|
jiffies + ERROR_DELAY_JIFFIES);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
2005-08-02 21:26:52 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-11-16 19:23:46 +08:00
|
|
|
urb->dev = ep->umidi->dev;
|
2005-09-26 16:01:12 +08:00
|
|
|
snd_usbmidi_submit_urb(urb, GFP_ATOMIC);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2014-08-06 00:44:51 +08:00
|
|
|
static void snd_usbmidi_out_urb_complete(struct urb *urb)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-07-13 19:43:59 +08:00
|
|
|
struct out_urb_context *context = urb->context;
|
2014-08-06 00:44:51 +08:00
|
|
|
struct snd_usb_midi_out_endpoint *ep = context->ep;
|
2009-07-13 19:48:36 +08:00
|
|
|
unsigned int urb_index;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
spin_lock(&ep->buffer_lock);
|
2009-07-13 19:48:36 +08:00
|
|
|
urb_index = context - ep->urbs;
|
|
|
|
ep->active_urbs &= ~(1 << urb_index);
|
|
|
|
if (unlikely(ep->drain_urbs)) {
|
|
|
|
ep->drain_urbs &= ~(1 << urb_index);
|
|
|
|
wake_up(&ep->drain_wait);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_unlock(&ep->buffer_lock);
|
|
|
|
if (urb->status < 0) {
|
2014-02-26 20:02:17 +08:00
|
|
|
int err = snd_usbmidi_urb_error(urb);
|
2005-08-02 21:26:52 +08:00
|
|
|
if (err < 0) {
|
|
|
|
if (err != -ENODEV)
|
|
|
|
mod_timer(&ep->umidi->error_timer,
|
|
|
|
jiffies + ERROR_DELAY_JIFFIES);
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
2005-08-02 21:26:52 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
snd_usbmidi_do_output(ep);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is called when some data should be transferred to the device
|
|
|
|
* (from one or more substreams).
|
|
|
|
*/
|
2014-08-06 00:44:51 +08:00
|
|
|
static void snd_usbmidi_do_output(struct snd_usb_midi_out_endpoint *ep)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-07-13 19:43:59 +08:00
|
|
|
unsigned int urb_index;
|
2014-08-06 00:44:51 +08:00
|
|
|
struct urb *urb;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&ep->buffer_lock, flags);
|
2009-11-16 19:23:46 +08:00
|
|
|
if (ep->umidi->disconnected) {
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_unlock_irqrestore(&ep->buffer_lock, flags);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-07-13 19:48:36 +08:00
|
|
|
urb_index = ep->next_urb;
|
2009-07-13 19:43:59 +08:00
|
|
|
for (;;) {
|
2009-07-13 19:48:36 +08:00
|
|
|
if (!(ep->active_urbs & (1 << urb_index))) {
|
|
|
|
urb = ep->urbs[urb_index].urb;
|
|
|
|
urb->transfer_buffer_length = 0;
|
|
|
|
ep->umidi->usb_protocol_ops->output(ep, urb);
|
|
|
|
if (urb->transfer_buffer_length == 0)
|
2009-07-13 19:43:59 +08:00
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-07-13 19:48:36 +08:00
|
|
|
dump_urb("sending", urb->transfer_buffer,
|
|
|
|
urb->transfer_buffer_length);
|
2009-11-16 19:23:46 +08:00
|
|
|
urb->dev = ep->umidi->dev;
|
2009-07-13 19:48:36 +08:00
|
|
|
if (snd_usbmidi_submit_urb(urb, GFP_ATOMIC) < 0)
|
|
|
|
break;
|
|
|
|
ep->active_urbs |= 1 << urb_index;
|
|
|
|
}
|
|
|
|
if (++urb_index >= OUTPUT_URBS)
|
|
|
|
urb_index = 0;
|
|
|
|
if (urb_index == ep->next_urb)
|
2009-07-13 19:43:59 +08:00
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2009-07-13 19:48:36 +08:00
|
|
|
ep->next_urb = urb_index;
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_unlock_irqrestore(&ep->buffer_lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void snd_usbmidi_out_tasklet(unsigned long data)
|
|
|
|
{
|
2014-08-06 00:44:51 +08:00
|
|
|
struct snd_usb_midi_out_endpoint *ep =
|
|
|
|
(struct snd_usb_midi_out_endpoint *) data;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
snd_usbmidi_do_output(ep);
|
|
|
|
}
|
|
|
|
|
2005-08-02 21:26:52 +08:00
|
|
|
/* called after transfers had been interrupted due to some USB error */
|
|
|
|
static void snd_usbmidi_error_timer(unsigned long data)
|
|
|
|
{
|
2005-11-17 22:08:02 +08:00
|
|
|
struct snd_usb_midi *umidi = (struct snd_usb_midi *)data;
|
2009-07-13 19:40:36 +08:00
|
|
|
unsigned int i, j;
|
2005-08-02 21:26:52 +08:00
|
|
|
|
2008-02-23 01:34:44 +08:00
|
|
|
spin_lock(&umidi->disc_lock);
|
|
|
|
if (umidi->disconnected) {
|
|
|
|
spin_unlock(&umidi->disc_lock);
|
|
|
|
return;
|
|
|
|
}
|
2005-08-02 21:26:52 +08:00
|
|
|
for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) {
|
2005-11-17 22:08:02 +08:00
|
|
|
struct snd_usb_midi_in_endpoint *in = umidi->endpoints[i].in;
|
2005-08-02 21:26:52 +08:00
|
|
|
if (in && in->error_resubmit) {
|
|
|
|
in->error_resubmit = 0;
|
2009-07-13 19:40:36 +08:00
|
|
|
for (j = 0; j < INPUT_URBS; ++j) {
|
2014-12-07 01:02:55 +08:00
|
|
|
if (atomic_read(&in->urbs[j]->use_count))
|
|
|
|
continue;
|
2009-11-16 19:23:46 +08:00
|
|
|
in->urbs[j]->dev = umidi->dev;
|
2009-07-13 19:40:36 +08:00
|
|
|
snd_usbmidi_submit_urb(in->urbs[j], GFP_ATOMIC);
|
|
|
|
}
|
2005-08-02 21:26:52 +08:00
|
|
|
}
|
|
|
|
if (umidi->endpoints[i].out)
|
|
|
|
snd_usbmidi_do_output(umidi->endpoints[i].out);
|
|
|
|
}
|
2008-02-23 01:34:44 +08:00
|
|
|
spin_unlock(&umidi->disc_lock);
|
2005-08-02 21:26:52 +08:00
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* helper function to send static data that may not DMA-able */
|
2014-08-06 00:44:51 +08:00
|
|
|
static int send_bulk_static_data(struct snd_usb_midi_out_endpoint *ep,
|
2005-04-17 06:20:36 +08:00
|
|
|
const void *data, int len)
|
|
|
|
{
|
2009-07-13 19:43:59 +08:00
|
|
|
int err = 0;
|
2006-10-01 14:27:21 +08:00
|
|
|
void *buf = kmemdup(data, len, GFP_KERNEL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!buf)
|
|
|
|
return -ENOMEM;
|
|
|
|
dump_urb("sending", buf, len);
|
2009-07-13 19:43:59 +08:00
|
|
|
if (ep->urbs[0].urb)
|
2009-11-16 19:23:46 +08:00
|
|
|
err = usb_bulk_msg(ep->umidi->dev, ep->urbs[0].urb->pipe,
|
2009-07-13 19:43:59 +08:00
|
|
|
buf, len, NULL, 250);
|
2005-04-17 06:20:36 +08:00
|
|
|
kfree(buf);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Standard USB MIDI protocol: see the spec.
|
|
|
|
* Midiman protocol: like the standard protocol, but the control byte is the
|
|
|
|
* fourth byte in each packet, and uses length instead of CIN.
|
|
|
|
*/
|
|
|
|
|
2014-08-06 00:44:51 +08:00
|
|
|
static void snd_usbmidi_standard_input(struct snd_usb_midi_in_endpoint *ep,
|
|
|
|
uint8_t *buffer, int buffer_length)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i + 3 < buffer_length; i += 4)
|
|
|
|
if (buffer[i] != 0) {
|
|
|
|
int cable = buffer[i] >> 4;
|
|
|
|
int length = snd_usbmidi_cin_length[buffer[i] & 0x0f];
|
2014-08-06 00:44:51 +08:00
|
|
|
snd_usbmidi_input_data(ep, cable, &buffer[i + 1],
|
|
|
|
length);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-06 00:44:51 +08:00
|
|
|
static void snd_usbmidi_midiman_input(struct snd_usb_midi_in_endpoint *ep,
|
|
|
|
uint8_t *buffer, int buffer_length)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i + 3 < buffer_length; i += 4)
|
|
|
|
if (buffer[i + 3] != 0) {
|
|
|
|
int port = buffer[i + 3] >> 4;
|
|
|
|
int length = buffer[i + 3] & 3;
|
|
|
|
snd_usbmidi_input_data(ep, port, &buffer[i], length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-07 15:28:53 +08:00
|
|
|
/*
|
|
|
|
* Buggy M-Audio device: running status on input results in a packet that has
|
|
|
|
* the data bytes but not the status byte and that is marked with CIN 4.
|
|
|
|
*/
|
|
|
|
static void snd_usbmidi_maudio_broken_running_status_input(
|
2014-08-06 00:44:51 +08:00
|
|
|
struct snd_usb_midi_in_endpoint *ep,
|
|
|
|
uint8_t *buffer, int buffer_length)
|
2007-05-07 15:28:53 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i + 3 < buffer_length; i += 4)
|
|
|
|
if (buffer[i] != 0) {
|
|
|
|
int cable = buffer[i] >> 4;
|
|
|
|
u8 cin = buffer[i] & 0x0f;
|
|
|
|
struct usbmidi_in_port *port = &ep->ports[cable];
|
|
|
|
int length;
|
2010-06-16 23:57:29 +08:00
|
|
|
|
2007-05-07 15:28:53 +08:00
|
|
|
length = snd_usbmidi_cin_length[cin];
|
|
|
|
if (cin == 0xf && buffer[i + 1] >= 0xf8)
|
|
|
|
; /* realtime msg: no running status change */
|
|
|
|
else if (cin >= 0x8 && cin <= 0xe)
|
|
|
|
/* channel msg */
|
|
|
|
port->running_status_length = length - 1;
|
|
|
|
else if (cin == 0x4 &&
|
|
|
|
port->running_status_length != 0 &&
|
|
|
|
buffer[i + 1] < 0x80)
|
|
|
|
/* CIN 4 that is not a SysEx */
|
|
|
|
length = port->running_status_length;
|
|
|
|
else
|
|
|
|
/*
|
|
|
|
* All other msgs cannot begin running status.
|
|
|
|
* (A channel msg sent as two or three CIN 0xF
|
|
|
|
* packets could in theory, but this device
|
|
|
|
* doesn't use this format.)
|
|
|
|
*/
|
|
|
|
port->running_status_length = 0;
|
2014-08-06 00:44:51 +08:00
|
|
|
snd_usbmidi_input_data(ep, cable, &buffer[i + 1],
|
|
|
|
length);
|
2007-05-07 15:28:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-16 05:39:08 +08:00
|
|
|
/*
|
|
|
|
* QinHeng CH345 is buggy: every second packet inside a SysEx has not CIN 4
|
|
|
|
* but the previously seen CIN, but still with three data bytes.
|
|
|
|
*/
|
|
|
|
static void ch345_broken_sysex_input(struct snd_usb_midi_in_endpoint *ep,
|
|
|
|
uint8_t *buffer, int buffer_length)
|
|
|
|
{
|
|
|
|
unsigned int i, cin, length;
|
|
|
|
|
|
|
|
for (i = 0; i + 3 < buffer_length; i += 4) {
|
|
|
|
if (buffer[i] == 0 && i > 0)
|
|
|
|
break;
|
|
|
|
cin = buffer[i] & 0x0f;
|
|
|
|
if (ep->in_sysex &&
|
|
|
|
cin == ep->last_cin &&
|
|
|
|
(buffer[i + 1 + (cin == 0x6)] & 0x80) == 0)
|
|
|
|
cin = 0x4;
|
|
|
|
#if 0
|
|
|
|
if (buffer[i + 1] == 0x90) {
|
|
|
|
/*
|
|
|
|
* Either a corrupted running status or a real note-on
|
|
|
|
* message; impossible to detect reliably.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
length = snd_usbmidi_cin_length[cin];
|
|
|
|
snd_usbmidi_input_data(ep, 0, &buffer[i + 1], length);
|
|
|
|
ep->in_sysex = cin == 0x4;
|
|
|
|
if (!ep->in_sysex)
|
|
|
|
ep->last_cin = cin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-16 14:44:51 +08:00
|
|
|
/*
|
|
|
|
* CME protocol: like the standard protocol, but SysEx commands are sent as a
|
|
|
|
* single USB packet preceded by a 0x0F byte.
|
|
|
|
*/
|
|
|
|
static void snd_usbmidi_cme_input(struct snd_usb_midi_in_endpoint *ep,
|
|
|
|
uint8_t *buffer, int buffer_length)
|
|
|
|
{
|
|
|
|
if (buffer_length < 2 || (buffer[0] & 0x0f) != 0x0f)
|
|
|
|
snd_usbmidi_standard_input(ep, buffer, buffer_length);
|
|
|
|
else
|
|
|
|
snd_usbmidi_input_data(ep, buffer[0] >> 4,
|
|
|
|
&buffer[1], buffer_length - 1);
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Adds one USB MIDI packet to the output buffer.
|
|
|
|
*/
|
2014-08-06 00:44:51 +08:00
|
|
|
static void snd_usbmidi_output_standard_packet(struct urb *urb, uint8_t p0,
|
|
|
|
uint8_t p1, uint8_t p2,
|
|
|
|
uint8_t p3)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
|
2014-08-06 00:44:51 +08:00
|
|
|
uint8_t *buf =
|
|
|
|
(uint8_t *)urb->transfer_buffer + urb->transfer_buffer_length;
|
2005-04-17 06:20:36 +08:00
|
|
|
buf[0] = p0;
|
|
|
|
buf[1] = p1;
|
|
|
|
buf[2] = p2;
|
|
|
|
buf[3] = p3;
|
|
|
|
urb->transfer_buffer_length += 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Adds one Midiman packet to the output buffer.
|
|
|
|
*/
|
2014-08-06 00:44:51 +08:00
|
|
|
static void snd_usbmidi_output_midiman_packet(struct urb *urb, uint8_t p0,
|
|
|
|
uint8_t p1, uint8_t p2,
|
|
|
|
uint8_t p3)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
|
2014-08-06 00:44:51 +08:00
|
|
|
uint8_t *buf =
|
|
|
|
(uint8_t *)urb->transfer_buffer + urb->transfer_buffer_length;
|
2005-04-17 06:20:36 +08:00
|
|
|
buf[0] = p1;
|
|
|
|
buf[1] = p2;
|
|
|
|
buf[2] = p3;
|
|
|
|
buf[3] = (p0 & 0xf0) | snd_usbmidi_cin_length[p0 & 0x0f];
|
|
|
|
urb->transfer_buffer_length += 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Converts MIDI commands to USB MIDI packets.
|
|
|
|
*/
|
2014-08-06 00:44:51 +08:00
|
|
|
static void snd_usbmidi_transmit_byte(struct usbmidi_out_port *port,
|
|
|
|
uint8_t b, struct urb *urb)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
uint8_t p0 = port->cable;
|
|
|
|
void (*output_packet)(struct urb*, uint8_t, uint8_t, uint8_t, uint8_t) =
|
|
|
|
port->ep->umidi->usb_protocol_ops->output_packet;
|
|
|
|
|
|
|
|
if (b >= 0xf8) {
|
|
|
|
output_packet(urb, p0 | 0x0f, b, 0, 0);
|
|
|
|
} else if (b >= 0xf0) {
|
|
|
|
switch (b) {
|
|
|
|
case 0xf0:
|
|
|
|
port->data[0] = b;
|
|
|
|
port->state = STATE_SYSEX_1;
|
|
|
|
break;
|
|
|
|
case 0xf1:
|
|
|
|
case 0xf3:
|
|
|
|
port->data[0] = b;
|
|
|
|
port->state = STATE_1PARAM;
|
|
|
|
break;
|
|
|
|
case 0xf2:
|
|
|
|
port->data[0] = b;
|
|
|
|
port->state = STATE_2PARAM_1;
|
|
|
|
break;
|
|
|
|
case 0xf4:
|
|
|
|
case 0xf5:
|
|
|
|
port->state = STATE_UNKNOWN;
|
|
|
|
break;
|
|
|
|
case 0xf6:
|
|
|
|
output_packet(urb, p0 | 0x05, 0xf6, 0, 0);
|
|
|
|
port->state = STATE_UNKNOWN;
|
|
|
|
break;
|
|
|
|
case 0xf7:
|
|
|
|
switch (port->state) {
|
|
|
|
case STATE_SYSEX_0:
|
|
|
|
output_packet(urb, p0 | 0x05, 0xf7, 0, 0);
|
|
|
|
break;
|
|
|
|
case STATE_SYSEX_1:
|
2014-08-06 00:44:51 +08:00
|
|
|
output_packet(urb, p0 | 0x06, port->data[0],
|
|
|
|
0xf7, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case STATE_SYSEX_2:
|
2014-08-06 00:44:51 +08:00
|
|
|
output_packet(urb, p0 | 0x07, port->data[0],
|
|
|
|
port->data[1], 0xf7);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
port->state = STATE_UNKNOWN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (b >= 0x80) {
|
|
|
|
port->data[0] = b;
|
|
|
|
if (b >= 0xc0 && b <= 0xdf)
|
|
|
|
port->state = STATE_1PARAM;
|
|
|
|
else
|
|
|
|
port->state = STATE_2PARAM_1;
|
|
|
|
} else { /* b < 0x80 */
|
|
|
|
switch (port->state) {
|
|
|
|
case STATE_1PARAM:
|
|
|
|
if (port->data[0] < 0xf0) {
|
|
|
|
p0 |= port->data[0] >> 4;
|
|
|
|
} else {
|
|
|
|
p0 |= 0x02;
|
|
|
|
port->state = STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
output_packet(urb, p0, port->data[0], b, 0);
|
|
|
|
break;
|
|
|
|
case STATE_2PARAM_1:
|
|
|
|
port->data[1] = b;
|
|
|
|
port->state = STATE_2PARAM_2;
|
|
|
|
break;
|
|
|
|
case STATE_2PARAM_2:
|
|
|
|
if (port->data[0] < 0xf0) {
|
|
|
|
p0 |= port->data[0] >> 4;
|
|
|
|
port->state = STATE_2PARAM_1;
|
|
|
|
} else {
|
|
|
|
p0 |= 0x03;
|
|
|
|
port->state = STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
output_packet(urb, p0, port->data[0], port->data[1], b);
|
|
|
|
break;
|
|
|
|
case STATE_SYSEX_0:
|
|
|
|
port->data[0] = b;
|
|
|
|
port->state = STATE_SYSEX_1;
|
|
|
|
break;
|
|
|
|
case STATE_SYSEX_1:
|
|
|
|
port->data[1] = b;
|
|
|
|
port->state = STATE_SYSEX_2;
|
|
|
|
break;
|
|
|
|
case STATE_SYSEX_2:
|
2014-08-06 00:44:51 +08:00
|
|
|
output_packet(urb, p0 | 0x04, port->data[0],
|
|
|
|
port->data[1], b);
|
2005-04-17 06:20:36 +08:00
|
|
|
port->state = STATE_SYSEX_0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-06 00:44:51 +08:00
|
|
|
static void snd_usbmidi_standard_output(struct snd_usb_midi_out_endpoint *ep,
|
2009-07-13 19:43:59 +08:00
|
|
|
struct urb *urb)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int p;
|
|
|
|
|
|
|
|
/* FIXME: lower-numbered ports can starve higher-numbered ports */
|
|
|
|
for (p = 0; p < 0x10; ++p) {
|
2014-08-06 00:44:51 +08:00
|
|
|
struct usbmidi_out_port *port = &ep->ports[p];
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!port->active)
|
|
|
|
continue;
|
|
|
|
while (urb->transfer_buffer_length + 3 < ep->max_transfer) {
|
|
|
|
uint8_t b;
|
|
|
|
if (snd_rawmidi_transmit(port->substream, &b, 1) != 1) {
|
|
|
|
port->active = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
snd_usbmidi_transmit_byte(port, b, urb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-11 22:52:37 +08:00
|
|
|
static const struct usb_protocol_ops snd_usbmidi_standard_ops = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.input = snd_usbmidi_standard_input,
|
|
|
|
.output = snd_usbmidi_standard_output,
|
|
|
|
.output_packet = snd_usbmidi_output_standard_packet,
|
|
|
|
};
|
|
|
|
|
2015-12-11 22:52:37 +08:00
|
|
|
static const struct usb_protocol_ops snd_usbmidi_midiman_ops = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.input = snd_usbmidi_midiman_input,
|
2010-06-16 23:57:29 +08:00
|
|
|
.output = snd_usbmidi_standard_output,
|
2005-04-17 06:20:36 +08:00
|
|
|
.output_packet = snd_usbmidi_output_midiman_packet,
|
|
|
|
};
|
|
|
|
|
2015-12-11 22:52:37 +08:00
|
|
|
static const
|
|
|
|
struct usb_protocol_ops snd_usbmidi_maudio_broken_running_status_ops = {
|
2007-05-07 15:28:53 +08:00
|
|
|
.input = snd_usbmidi_maudio_broken_running_status_input,
|
2010-06-16 23:57:29 +08:00
|
|
|
.output = snd_usbmidi_standard_output,
|
2007-05-07 15:28:53 +08:00
|
|
|
.output_packet = snd_usbmidi_output_standard_packet,
|
|
|
|
};
|
|
|
|
|
2015-12-11 22:52:37 +08:00
|
|
|
static const struct usb_protocol_ops snd_usbmidi_cme_ops = {
|
2007-08-16 14:44:51 +08:00
|
|
|
.input = snd_usbmidi_cme_input,
|
|
|
|
.output = snd_usbmidi_standard_output,
|
|
|
|
.output_packet = snd_usbmidi_output_standard_packet,
|
|
|
|
};
|
|
|
|
|
2015-12-11 22:52:37 +08:00
|
|
|
static const struct usb_protocol_ops snd_usbmidi_ch345_broken_sysex_ops = {
|
2015-11-16 05:39:08 +08:00
|
|
|
.input = ch345_broken_sysex_input,
|
|
|
|
.output = snd_usbmidi_standard_output,
|
|
|
|
.output_packet = snd_usbmidi_output_standard_packet,
|
|
|
|
};
|
|
|
|
|
2010-05-21 03:31:10 +08:00
|
|
|
/*
|
|
|
|
* AKAI MPD16 protocol:
|
|
|
|
*
|
|
|
|
* For control port (endpoint 1):
|
|
|
|
* ==============================
|
|
|
|
* One or more chunks consisting of first byte of (0x10 | msg_len) and then a
|
|
|
|
* SysEx message (msg_len=9 bytes long).
|
|
|
|
*
|
|
|
|
* For data port (endpoint 2):
|
|
|
|
* ===========================
|
|
|
|
* One or more chunks consisting of first byte of (0x20 | msg_len) and then a
|
|
|
|
* MIDI message (msg_len bytes long)
|
|
|
|
*
|
|
|
|
* Messages sent: Active Sense, Note On, Poly Pressure, Control Change.
|
|
|
|
*/
|
|
|
|
static void snd_usbmidi_akai_input(struct snd_usb_midi_in_endpoint *ep,
|
|
|
|
uint8_t *buffer, int buffer_length)
|
|
|
|
{
|
|
|
|
unsigned int pos = 0;
|
|
|
|
unsigned int len = (unsigned int)buffer_length;
|
|
|
|
while (pos < len) {
|
|
|
|
unsigned int port = (buffer[pos] >> 4) - 1;
|
|
|
|
unsigned int msg_len = buffer[pos] & 0x0f;
|
|
|
|
pos++;
|
|
|
|
if (pos + msg_len <= len && port < 2)
|
|
|
|
snd_usbmidi_input_data(ep, 0, &buffer[pos], msg_len);
|
|
|
|
pos += msg_len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MAX_AKAI_SYSEX_LEN 9
|
|
|
|
|
|
|
|
static void snd_usbmidi_akai_output(struct snd_usb_midi_out_endpoint *ep,
|
|
|
|
struct urb *urb)
|
|
|
|
{
|
|
|
|
uint8_t *msg;
|
|
|
|
int pos, end, count, buf_end;
|
|
|
|
uint8_t tmp[MAX_AKAI_SYSEX_LEN];
|
|
|
|
struct snd_rawmidi_substream *substream = ep->ports[0].substream;
|
|
|
|
|
|
|
|
if (!ep->ports[0].active)
|
|
|
|
return;
|
|
|
|
|
|
|
|
msg = urb->transfer_buffer + urb->transfer_buffer_length;
|
|
|
|
buf_end = ep->max_transfer - MAX_AKAI_SYSEX_LEN - 1;
|
|
|
|
|
|
|
|
/* only try adding more data when there's space for at least 1 SysEx */
|
|
|
|
while (urb->transfer_buffer_length < buf_end) {
|
|
|
|
count = snd_rawmidi_transmit_peek(substream,
|
|
|
|
tmp, MAX_AKAI_SYSEX_LEN);
|
|
|
|
if (!count) {
|
|
|
|
ep->ports[0].active = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* try to skip non-SysEx data */
|
|
|
|
for (pos = 0; pos < count && tmp[pos] != 0xF0; pos++)
|
|
|
|
;
|
|
|
|
|
|
|
|
if (pos > 0) {
|
|
|
|
snd_rawmidi_transmit_ack(substream, pos);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* look for the start or end marker */
|
|
|
|
for (end = 1; end < count && tmp[end] < 0xF0; end++)
|
|
|
|
;
|
|
|
|
|
|
|
|
/* next SysEx started before the end of current one */
|
|
|
|
if (end < count && tmp[end] == 0xF0) {
|
|
|
|
/* it's incomplete - drop it */
|
|
|
|
snd_rawmidi_transmit_ack(substream, end);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* SysEx complete */
|
|
|
|
if (end < count && tmp[end] == 0xF7) {
|
|
|
|
/* queue it, ack it, and get the next one */
|
|
|
|
count = end + 1;
|
|
|
|
msg[0] = 0x10 | count;
|
|
|
|
memcpy(&msg[1], tmp, count);
|
|
|
|
snd_rawmidi_transmit_ack(substream, count);
|
|
|
|
urb->transfer_buffer_length += count + 1;
|
|
|
|
msg += count + 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* less than 9 bytes and no end byte - wait for more */
|
|
|
|
if (count < MAX_AKAI_SYSEX_LEN) {
|
|
|
|
ep->ports[0].active = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* 9 bytes and no end marker in sight - malformed, skip it */
|
|
|
|
snd_rawmidi_transmit_ack(substream, count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-11 22:52:37 +08:00
|
|
|
static const struct usb_protocol_ops snd_usbmidi_akai_ops = {
|
2010-05-21 03:31:10 +08:00
|
|
|
.input = snd_usbmidi_akai_input,
|
|
|
|
.output = snd_usbmidi_akai_output,
|
|
|
|
};
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Novation USB MIDI protocol: number of data bytes is in the first byte
|
|
|
|
* (when receiving) (+1!) or in the second byte (when sending); data begins
|
|
|
|
* at the third byte.
|
|
|
|
*/
|
|
|
|
|
2014-08-06 00:44:51 +08:00
|
|
|
static void snd_usbmidi_novation_input(struct snd_usb_midi_in_endpoint *ep,
|
|
|
|
uint8_t *buffer, int buffer_length)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
if (buffer_length < 2 || !buffer[0] || buffer_length < buffer[0] + 1)
|
|
|
|
return;
|
|
|
|
snd_usbmidi_input_data(ep, 0, &buffer[2], buffer[0] - 1);
|
|
|
|
}
|
|
|
|
|
2014-08-06 00:44:51 +08:00
|
|
|
static void snd_usbmidi_novation_output(struct snd_usb_midi_out_endpoint *ep,
|
2009-07-13 19:43:59 +08:00
|
|
|
struct urb *urb)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2014-08-06 00:44:51 +08:00
|
|
|
uint8_t *transfer_buffer;
|
2005-04-17 06:20:36 +08:00
|
|
|
int count;
|
|
|
|
|
|
|
|
if (!ep->ports[0].active)
|
|
|
|
return;
|
2009-07-13 19:43:59 +08:00
|
|
|
transfer_buffer = urb->transfer_buffer;
|
2005-04-17 06:20:36 +08:00
|
|
|
count = snd_rawmidi_transmit(ep->ports[0].substream,
|
|
|
|
&transfer_buffer[2],
|
|
|
|
ep->max_transfer - 2);
|
|
|
|
if (count < 1) {
|
|
|
|
ep->ports[0].active = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
transfer_buffer[0] = 0;
|
|
|
|
transfer_buffer[1] = count;
|
2009-07-13 19:43:59 +08:00
|
|
|
urb->transfer_buffer_length = 2 + count;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2015-12-11 22:52:37 +08:00
|
|
|
static const struct usb_protocol_ops snd_usbmidi_novation_ops = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.input = snd_usbmidi_novation_input,
|
|
|
|
.output = snd_usbmidi_novation_output,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2010-10-23 00:20:48 +08:00
|
|
|
* "raw" protocol: just move raw MIDI bytes from/to the endpoint
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
2014-08-06 00:44:51 +08:00
|
|
|
static void snd_usbmidi_raw_input(struct snd_usb_midi_in_endpoint *ep,
|
|
|
|
uint8_t *buffer, int buffer_length)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
snd_usbmidi_input_data(ep, 0, buffer, buffer_length);
|
|
|
|
}
|
|
|
|
|
2014-08-06 00:44:51 +08:00
|
|
|
static void snd_usbmidi_raw_output(struct snd_usb_midi_out_endpoint *ep,
|
2009-07-13 19:43:59 +08:00
|
|
|
struct urb *urb)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int count;
|
|
|
|
|
|
|
|
if (!ep->ports[0].active)
|
|
|
|
return;
|
|
|
|
count = snd_rawmidi_transmit(ep->ports[0].substream,
|
2009-07-13 19:43:59 +08:00
|
|
|
urb->transfer_buffer,
|
2005-04-17 06:20:36 +08:00
|
|
|
ep->max_transfer);
|
|
|
|
if (count < 1) {
|
|
|
|
ep->ports[0].active = 0;
|
|
|
|
return;
|
|
|
|
}
|
2009-07-13 19:43:59 +08:00
|
|
|
urb->transfer_buffer_length = count;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2015-12-11 22:52:37 +08:00
|
|
|
static const struct usb_protocol_ops snd_usbmidi_raw_ops = {
|
2005-07-04 15:20:42 +08:00
|
|
|
.input = snd_usbmidi_raw_input,
|
|
|
|
.output = snd_usbmidi_raw_output,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2011-08-26 19:19:49 +08:00
|
|
|
/*
|
|
|
|
* FTDI protocol: raw MIDI bytes, but input packets have two modem status bytes.
|
|
|
|
*/
|
|
|
|
|
2014-08-06 00:44:51 +08:00
|
|
|
static void snd_usbmidi_ftdi_input(struct snd_usb_midi_in_endpoint *ep,
|
|
|
|
uint8_t *buffer, int buffer_length)
|
2011-08-26 19:19:49 +08:00
|
|
|
{
|
|
|
|
if (buffer_length > 2)
|
|
|
|
snd_usbmidi_input_data(ep, 0, buffer + 2, buffer_length - 2);
|
|
|
|
}
|
|
|
|
|
2015-12-11 22:52:37 +08:00
|
|
|
static const struct usb_protocol_ops snd_usbmidi_ftdi_ops = {
|
2011-08-26 19:19:49 +08:00
|
|
|
.input = snd_usbmidi_ftdi_input,
|
|
|
|
.output = snd_usbmidi_raw_output,
|
|
|
|
};
|
|
|
|
|
2008-07-30 21:13:29 +08:00
|
|
|
static void snd_usbmidi_us122l_input(struct snd_usb_midi_in_endpoint *ep,
|
|
|
|
uint8_t *buffer, int buffer_length)
|
|
|
|
{
|
|
|
|
if (buffer_length != 9)
|
|
|
|
return;
|
|
|
|
buffer_length = 8;
|
|
|
|
while (buffer_length && buffer[buffer_length - 1] == 0xFD)
|
|
|
|
buffer_length--;
|
|
|
|
if (buffer_length)
|
|
|
|
snd_usbmidi_input_data(ep, 0, buffer, buffer_length);
|
|
|
|
}
|
|
|
|
|
2009-07-13 19:43:59 +08:00
|
|
|
static void snd_usbmidi_us122l_output(struct snd_usb_midi_out_endpoint *ep,
|
|
|
|
struct urb *urb)
|
2008-07-30 21:13:29 +08:00
|
|
|
{
|
|
|
|
int count;
|
|
|
|
|
|
|
|
if (!ep->ports[0].active)
|
|
|
|
return;
|
2010-08-14 03:42:07 +08:00
|
|
|
switch (snd_usb_get_speed(ep->umidi->dev)) {
|
|
|
|
case USB_SPEED_HIGH:
|
|
|
|
case USB_SPEED_SUPER:
|
2016-05-04 20:18:40 +08:00
|
|
|
case USB_SPEED_SUPER_PLUS:
|
2010-08-14 03:42:07 +08:00
|
|
|
count = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
count = 2;
|
|
|
|
}
|
2008-07-30 21:13:29 +08:00
|
|
|
count = snd_rawmidi_transmit(ep->ports[0].substream,
|
2009-07-13 19:43:59 +08:00
|
|
|
urb->transfer_buffer,
|
2008-07-30 21:13:29 +08:00
|
|
|
count);
|
|
|
|
if (count < 1) {
|
|
|
|
ep->ports[0].active = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-01-03 09:41:58 +08:00
|
|
|
memset(urb->transfer_buffer + count, 0xFD, ep->max_transfer - count);
|
|
|
|
urb->transfer_buffer_length = ep->max_transfer;
|
2008-07-30 21:13:29 +08:00
|
|
|
}
|
|
|
|
|
2015-12-11 22:52:37 +08:00
|
|
|
static const struct usb_protocol_ops snd_usbmidi_122l_ops = {
|
2008-07-30 21:13:29 +08:00
|
|
|
.input = snd_usbmidi_us122l_input,
|
|
|
|
.output = snd_usbmidi_us122l_output,
|
|
|
|
};
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Emagic USB MIDI protocol: raw MIDI with "F5 xx" port switching.
|
|
|
|
*/
|
|
|
|
|
2014-08-06 00:44:51 +08:00
|
|
|
static void snd_usbmidi_emagic_init_out(struct snd_usb_midi_out_endpoint *ep)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
static const u8 init_data[] = {
|
|
|
|
/* initialization magic: "get version" */
|
|
|
|
0xf0,
|
|
|
|
0x00, 0x20, 0x31, /* Emagic */
|
|
|
|
0x64, /* Unitor8 */
|
|
|
|
0x0b, /* version number request */
|
|
|
|
0x00, /* command version */
|
|
|
|
0x00, /* EEPROM, box 0 */
|
|
|
|
0xf7
|
|
|
|
};
|
|
|
|
send_bulk_static_data(ep, init_data, sizeof(init_data));
|
|
|
|
/* while we're at it, pour on more magic */
|
|
|
|
send_bulk_static_data(ep, init_data, sizeof(init_data));
|
|
|
|
}
|
|
|
|
|
2014-08-06 00:44:51 +08:00
|
|
|
static void snd_usbmidi_emagic_finish_out(struct snd_usb_midi_out_endpoint *ep)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
static const u8 finish_data[] = {
|
|
|
|
/* switch to patch mode with last preset */
|
|
|
|
0xf0,
|
|
|
|
0x00, 0x20, 0x31, /* Emagic */
|
|
|
|
0x64, /* Unitor8 */
|
|
|
|
0x10, /* patch switch command */
|
|
|
|
0x00, /* command version */
|
|
|
|
0x7f, /* to all boxes */
|
|
|
|
0x40, /* last preset in EEPROM */
|
|
|
|
0xf7
|
|
|
|
};
|
|
|
|
send_bulk_static_data(ep, finish_data, sizeof(finish_data));
|
|
|
|
}
|
|
|
|
|
2014-08-06 00:44:51 +08:00
|
|
|
static void snd_usbmidi_emagic_input(struct snd_usb_midi_in_endpoint *ep,
|
|
|
|
uint8_t *buffer, int buffer_length)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-08-25 17:10:05 +08:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/* FF indicates end of valid data */
|
|
|
|
for (i = 0; i < buffer_length; ++i)
|
|
|
|
if (buffer[i] == 0xff) {
|
|
|
|
buffer_length = i;
|
|
|
|
break;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* handle F5 at end of last buffer */
|
|
|
|
if (ep->seen_f5)
|
|
|
|
goto switch_port;
|
|
|
|
|
|
|
|
while (buffer_length > 0) {
|
|
|
|
/* determine size of data until next F5 */
|
|
|
|
for (i = 0; i < buffer_length; ++i)
|
|
|
|
if (buffer[i] == 0xf5)
|
|
|
|
break;
|
|
|
|
snd_usbmidi_input_data(ep, ep->current_port, buffer, i);
|
|
|
|
buffer += i;
|
|
|
|
buffer_length -= i;
|
|
|
|
|
|
|
|
if (buffer_length <= 0)
|
|
|
|
break;
|
|
|
|
/* assert(buffer[0] == 0xf5); */
|
|
|
|
ep->seen_f5 = 1;
|
|
|
|
++buffer;
|
|
|
|
--buffer_length;
|
|
|
|
|
|
|
|
switch_port:
|
|
|
|
if (buffer_length <= 0)
|
|
|
|
break;
|
|
|
|
if (buffer[0] < 0x80) {
|
|
|
|
ep->current_port = (buffer[0] - 1) & 15;
|
|
|
|
++buffer;
|
|
|
|
--buffer_length;
|
|
|
|
}
|
|
|
|
ep->seen_f5 = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-06 00:44:51 +08:00
|
|
|
static void snd_usbmidi_emagic_output(struct snd_usb_midi_out_endpoint *ep,
|
2009-07-13 19:43:59 +08:00
|
|
|
struct urb *urb)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int port0 = ep->current_port;
|
2014-08-06 00:44:51 +08:00
|
|
|
uint8_t *buf = urb->transfer_buffer;
|
2005-04-17 06:20:36 +08:00
|
|
|
int buf_free = ep->max_transfer;
|
|
|
|
int length, i;
|
|
|
|
|
|
|
|
for (i = 0; i < 0x10; ++i) {
|
|
|
|
/* round-robin, starting at the last current port */
|
|
|
|
int portnum = (port0 + i) & 15;
|
2014-08-06 00:44:51 +08:00
|
|
|
struct usbmidi_out_port *port = &ep->ports[portnum];
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (!port->active)
|
|
|
|
continue;
|
|
|
|
if (snd_rawmidi_transmit_peek(port->substream, buf, 1) != 1) {
|
|
|
|
port->active = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (portnum != ep->current_port) {
|
|
|
|
if (buf_free < 2)
|
|
|
|
break;
|
|
|
|
ep->current_port = portnum;
|
|
|
|
buf[0] = 0xf5;
|
|
|
|
buf[1] = (portnum + 1) & 15;
|
|
|
|
buf += 2;
|
|
|
|
buf_free -= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buf_free < 1)
|
|
|
|
break;
|
|
|
|
length = snd_rawmidi_transmit(port->substream, buf, buf_free);
|
|
|
|
if (length > 0) {
|
|
|
|
buf += length;
|
|
|
|
buf_free -= length;
|
|
|
|
if (buf_free < 1)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-08-25 17:10:05 +08:00
|
|
|
if (buf_free < ep->max_transfer && buf_free > 0) {
|
|
|
|
*buf = 0xff;
|
|
|
|
--buf_free;
|
|
|
|
}
|
2009-07-13 19:43:59 +08:00
|
|
|
urb->transfer_buffer_length = ep->max_transfer - buf_free;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2015-12-11 22:52:37 +08:00
|
|
|
static const struct usb_protocol_ops snd_usbmidi_emagic_ops = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.input = snd_usbmidi_emagic_input,
|
|
|
|
.output = snd_usbmidi_emagic_output,
|
|
|
|
.init_out_endpoint = snd_usbmidi_emagic_init_out,
|
|
|
|
.finish_out_endpoint = snd_usbmidi_emagic_finish_out,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-08-06 00:44:51 +08:00
|
|
|
static void update_roland_altsetting(struct snd_usb_midi *umidi)
|
2009-10-22 15:06:19 +08:00
|
|
|
{
|
|
|
|
struct usb_interface *intf;
|
|
|
|
struct usb_host_interface *hostif;
|
|
|
|
struct usb_interface_descriptor *intfd;
|
|
|
|
int is_light_load;
|
|
|
|
|
|
|
|
intf = umidi->iface;
|
|
|
|
is_light_load = intf->cur_altsetting != intf->altsetting;
|
|
|
|
if (umidi->roland_load_ctl->private_value == is_light_load)
|
|
|
|
return;
|
|
|
|
hostif = &intf->altsetting[umidi->roland_load_ctl->private_value];
|
|
|
|
intfd = get_iface_desc(hostif);
|
|
|
|
snd_usbmidi_input_stop(&umidi->list);
|
2009-11-16 19:23:46 +08:00
|
|
|
usb_set_interface(umidi->dev, intfd->bInterfaceNumber,
|
2009-10-22 15:06:19 +08:00
|
|
|
intfd->bAlternateSetting);
|
|
|
|
snd_usbmidi_input_start(&umidi->list);
|
|
|
|
}
|
|
|
|
|
2012-12-03 18:30:50 +08:00
|
|
|
static int substream_open(struct snd_rawmidi_substream *substream, int dir,
|
|
|
|
int open)
|
2009-10-22 15:06:19 +08:00
|
|
|
{
|
2014-08-06 00:44:51 +08:00
|
|
|
struct snd_usb_midi *umidi = substream->rmidi->private_data;
|
2009-10-22 15:06:19 +08:00
|
|
|
struct snd_kcontrol *ctl;
|
|
|
|
|
2012-12-03 18:12:46 +08:00
|
|
|
down_read(&umidi->disc_rwsem);
|
|
|
|
if (umidi->disconnected) {
|
|
|
|
up_read(&umidi->disc_rwsem);
|
2012-12-03 18:30:50 +08:00
|
|
|
return open ? -ENODEV : 0;
|
2012-12-03 18:12:46 +08:00
|
|
|
}
|
|
|
|
|
2009-10-22 15:06:19 +08:00
|
|
|
mutex_lock(&umidi->mutex);
|
|
|
|
if (open) {
|
2012-12-03 18:30:50 +08:00
|
|
|
if (!umidi->opened[0] && !umidi->opened[1]) {
|
|
|
|
if (umidi->roland_load_ctl) {
|
|
|
|
ctl = umidi->roland_load_ctl;
|
2014-08-06 00:44:51 +08:00
|
|
|
ctl->vd[0].access |=
|
|
|
|
SNDRV_CTL_ELEM_ACCESS_INACTIVE;
|
2012-12-03 18:30:50 +08:00
|
|
|
snd_ctl_notify(umidi->card,
|
2009-10-22 15:06:19 +08:00
|
|
|
SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
|
2012-12-03 18:30:50 +08:00
|
|
|
update_roland_altsetting(umidi);
|
|
|
|
}
|
2009-10-22 15:06:19 +08:00
|
|
|
}
|
2012-12-03 18:30:50 +08:00
|
|
|
umidi->opened[dir]++;
|
|
|
|
if (umidi->opened[1])
|
|
|
|
snd_usbmidi_input_start(&umidi->list);
|
2009-10-22 15:06:19 +08:00
|
|
|
} else {
|
2012-12-03 18:30:50 +08:00
|
|
|
umidi->opened[dir]--;
|
|
|
|
if (!umidi->opened[1])
|
|
|
|
snd_usbmidi_input_stop(&umidi->list);
|
|
|
|
if (!umidi->opened[0] && !umidi->opened[1]) {
|
|
|
|
if (umidi->roland_load_ctl) {
|
|
|
|
ctl = umidi->roland_load_ctl;
|
2014-08-06 00:44:51 +08:00
|
|
|
ctl->vd[0].access &=
|
|
|
|
~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
|
2012-12-03 18:30:50 +08:00
|
|
|
snd_ctl_notify(umidi->card,
|
2009-10-22 15:06:19 +08:00
|
|
|
SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
|
2012-12-03 18:30:50 +08:00
|
|
|
}
|
2009-10-22 15:06:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
mutex_unlock(&umidi->mutex);
|
2012-12-03 18:12:46 +08:00
|
|
|
up_read(&umidi->disc_rwsem);
|
2012-12-03 18:30:50 +08:00
|
|
|
return 0;
|
2009-10-22 15:06:19 +08:00
|
|
|
}
|
|
|
|
|
2005-11-17 22:08:02 +08:00
|
|
|
static int snd_usbmidi_output_open(struct snd_rawmidi_substream *substream)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2014-08-06 00:44:51 +08:00
|
|
|
struct snd_usb_midi *umidi = substream->rmidi->private_data;
|
|
|
|
struct usbmidi_out_port *port = NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i)
|
|
|
|
if (umidi->endpoints[i].out)
|
|
|
|
for (j = 0; j < 0x10; ++j)
|
|
|
|
if (umidi->endpoints[i].out->ports[j].substream == substream) {
|
|
|
|
port = &umidi->endpoints[i].out->ports[j];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!port) {
|
|
|
|
snd_BUG();
|
|
|
|
return -ENXIO;
|
|
|
|
}
|
2012-12-03 18:12:46 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
substream->runtime->private_data = port;
|
|
|
|
port->state = STATE_UNKNOWN;
|
2012-12-03 18:30:50 +08:00
|
|
|
return substream_open(substream, 0, 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2005-11-17 22:08:02 +08:00
|
|
|
static int snd_usbmidi_output_close(struct snd_rawmidi_substream *substream)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2012-12-03 18:30:50 +08:00
|
|
|
return substream_open(substream, 0, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2014-08-06 00:44:51 +08:00
|
|
|
static void snd_usbmidi_output_trigger(struct snd_rawmidi_substream *substream,
|
|
|
|
int up)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2014-08-06 00:44:51 +08:00
|
|
|
struct usbmidi_out_port *port =
|
|
|
|
(struct usbmidi_out_port *)substream->runtime->private_data;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
port->active = up;
|
|
|
|
if (up) {
|
2009-11-16 19:23:46 +08:00
|
|
|
if (port->ep->umidi->disconnected) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/* gobble up remaining bytes to prevent wait in
|
|
|
|
* snd_rawmidi_drain_output */
|
|
|
|
while (!snd_rawmidi_transmit_empty(substream))
|
|
|
|
snd_rawmidi_transmit_ack(substream, 1);
|
|
|
|
return;
|
|
|
|
}
|
2008-12-18 19:17:55 +08:00
|
|
|
tasklet_schedule(&port->ep->tasklet);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-13 19:48:36 +08:00
|
|
|
static void snd_usbmidi_output_drain(struct snd_rawmidi_substream *substream)
|
|
|
|
{
|
2014-08-06 00:44:51 +08:00
|
|
|
struct usbmidi_out_port *port = substream->runtime->private_data;
|
2009-07-13 19:48:36 +08:00
|
|
|
struct snd_usb_midi_out_endpoint *ep = port->ep;
|
|
|
|
unsigned int drain_urbs;
|
|
|
|
DEFINE_WAIT(wait);
|
|
|
|
long timeout = msecs_to_jiffies(50);
|
|
|
|
|
2010-04-11 03:27:23 +08:00
|
|
|
if (ep->umidi->disconnected)
|
|
|
|
return;
|
2009-07-13 19:48:36 +08:00
|
|
|
/*
|
|
|
|
* The substream buffer is empty, but some data might still be in the
|
|
|
|
* currently active URBs, so we have to wait for those to complete.
|
|
|
|
*/
|
|
|
|
spin_lock_irq(&ep->buffer_lock);
|
|
|
|
drain_urbs = ep->active_urbs;
|
|
|
|
if (drain_urbs) {
|
|
|
|
ep->drain_urbs |= drain_urbs;
|
|
|
|
do {
|
|
|
|
prepare_to_wait(&ep->drain_wait, &wait,
|
|
|
|
TASK_UNINTERRUPTIBLE);
|
|
|
|
spin_unlock_irq(&ep->buffer_lock);
|
|
|
|
timeout = schedule_timeout(timeout);
|
|
|
|
spin_lock_irq(&ep->buffer_lock);
|
|
|
|
drain_urbs &= ep->drain_urbs;
|
|
|
|
} while (drain_urbs && timeout);
|
|
|
|
finish_wait(&ep->drain_wait, &wait);
|
|
|
|
}
|
|
|
|
spin_unlock_irq(&ep->buffer_lock);
|
|
|
|
}
|
|
|
|
|
2005-11-17 22:08:02 +08:00
|
|
|
static int snd_usbmidi_input_open(struct snd_rawmidi_substream *substream)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2012-12-03 18:30:50 +08:00
|
|
|
return substream_open(substream, 1, 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2005-11-17 22:08:02 +08:00
|
|
|
static int snd_usbmidi_input_close(struct snd_rawmidi_substream *substream)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2012-12-03 18:30:50 +08:00
|
|
|
return substream_open(substream, 1, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2014-08-06 00:44:51 +08:00
|
|
|
static void snd_usbmidi_input_trigger(struct snd_rawmidi_substream *substream,
|
|
|
|
int up)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2014-08-06 00:44:51 +08:00
|
|
|
struct snd_usb_midi *umidi = substream->rmidi->private_data;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (up)
|
|
|
|
set_bit(substream->number, &umidi->input_triggered);
|
|
|
|
else
|
|
|
|
clear_bit(substream->number, &umidi->input_triggered);
|
|
|
|
}
|
|
|
|
|
2005-11-17 22:08:02 +08:00
|
|
|
static struct snd_rawmidi_ops snd_usbmidi_output_ops = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.open = snd_usbmidi_output_open,
|
|
|
|
.close = snd_usbmidi_output_close,
|
|
|
|
.trigger = snd_usbmidi_output_trigger,
|
2009-07-13 19:48:36 +08:00
|
|
|
.drain = snd_usbmidi_output_drain,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2005-11-17 22:08:02 +08:00
|
|
|
static struct snd_rawmidi_ops snd_usbmidi_input_ops = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.open = snd_usbmidi_input_open,
|
|
|
|
.close = snd_usbmidi_input_close,
|
|
|
|
.trigger = snd_usbmidi_input_trigger
|
|
|
|
};
|
|
|
|
|
2009-07-13 19:43:59 +08:00
|
|
|
static void free_urb_and_buffer(struct snd_usb_midi *umidi, struct urb *urb,
|
|
|
|
unsigned int buffer_length)
|
|
|
|
{
|
2010-04-12 19:17:25 +08:00
|
|
|
usb_free_coherent(umidi->dev, buffer_length,
|
|
|
|
urb->transfer_buffer, urb->transfer_dma);
|
2009-07-13 19:43:59 +08:00
|
|
|
usb_free_urb(urb);
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Frees an input endpoint.
|
|
|
|
* May be called when ep hasn't been initialized completely.
|
|
|
|
*/
|
2014-08-06 00:44:51 +08:00
|
|
|
static void snd_usbmidi_in_endpoint_delete(struct snd_usb_midi_in_endpoint *ep)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-07-13 19:40:36 +08:00
|
|
|
unsigned int i;
|
|
|
|
|
2009-07-13 19:43:59 +08:00
|
|
|
for (i = 0; i < INPUT_URBS; ++i)
|
|
|
|
if (ep->urbs[i])
|
|
|
|
free_urb_and_buffer(ep->umidi, ep->urbs[i],
|
|
|
|
ep->urbs[i]->transfer_buffer_length);
|
2005-04-17 06:20:36 +08:00
|
|
|
kfree(ep);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Creates an input endpoint.
|
|
|
|
*/
|
2014-08-06 00:44:51 +08:00
|
|
|
static int snd_usbmidi_in_endpoint_create(struct snd_usb_midi *umidi,
|
|
|
|
struct snd_usb_midi_endpoint_info *ep_info,
|
|
|
|
struct snd_usb_midi_endpoint *rep)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2014-08-06 00:44:51 +08:00
|
|
|
struct snd_usb_midi_in_endpoint *ep;
|
|
|
|
void *buffer;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned int pipe;
|
|
|
|
int length;
|
2009-07-13 19:40:36 +08:00
|
|
|
unsigned int i;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
rep->in = NULL;
|
[ALSA] Replace with kzalloc() - others
Documentation,SA11xx UDA1341 driver,Generic drivers,MPU401 UART,OPL3
OPL4,Digigram VX core,I2C cs8427,I2C lib core,I2C tea6330t,L3 drivers
AK4114 receiver,AK4117 receiver,PDAudioCF driver,PPC PMAC driver
SPARC AMD7930 driver,SPARC cs4231 driver,Synth,Common EMU synth
USB generic driver,USB USX2Y
Replace kcalloc(1,..) with kzalloc().
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2005-09-09 20:22:34 +08:00
|
|
|
ep = kzalloc(sizeof(*ep), GFP_KERNEL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!ep)
|
|
|
|
return -ENOMEM;
|
|
|
|
ep->umidi = umidi;
|
|
|
|
|
2009-07-13 19:40:36 +08:00
|
|
|
for (i = 0; i < INPUT_URBS; ++i) {
|
|
|
|
ep->urbs[i] = usb_alloc_urb(0, GFP_KERNEL);
|
|
|
|
if (!ep->urbs[i]) {
|
|
|
|
snd_usbmidi_in_endpoint_delete(ep);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
if (ep_info->in_interval)
|
2009-11-16 19:23:46 +08:00
|
|
|
pipe = usb_rcvintpipe(umidi->dev, ep_info->in_ep);
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
2009-11-16 19:23:46 +08:00
|
|
|
pipe = usb_rcvbulkpipe(umidi->dev, ep_info->in_ep);
|
|
|
|
length = usb_maxpacket(umidi->dev, pipe, 0);
|
2009-07-13 19:40:36 +08:00
|
|
|
for (i = 0; i < INPUT_URBS; ++i) {
|
2010-04-12 19:17:25 +08:00
|
|
|
buffer = usb_alloc_coherent(umidi->dev, length, GFP_KERNEL,
|
|
|
|
&ep->urbs[i]->transfer_dma);
|
2009-07-13 19:40:36 +08:00
|
|
|
if (!buffer) {
|
|
|
|
snd_usbmidi_in_endpoint_delete(ep);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
if (ep_info->in_interval)
|
2009-11-16 19:23:46 +08:00
|
|
|
usb_fill_int_urb(ep->urbs[i], umidi->dev,
|
2009-07-13 19:40:36 +08:00
|
|
|
pipe, buffer, length,
|
|
|
|
snd_usbmidi_in_urb_complete,
|
|
|
|
ep, ep_info->in_interval);
|
|
|
|
else
|
2009-11-16 19:23:46 +08:00
|
|
|
usb_fill_bulk_urb(ep->urbs[i], umidi->dev,
|
2009-07-13 19:40:36 +08:00
|
|
|
pipe, buffer, length,
|
|
|
|
snd_usbmidi_in_urb_complete, ep);
|
|
|
|
ep->urbs[i]->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
rep->in = ep;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Frees an output endpoint.
|
|
|
|
* May be called when ep hasn't been initialized completely.
|
|
|
|
*/
|
2010-04-11 03:27:23 +08:00
|
|
|
static void snd_usbmidi_out_endpoint_clear(struct snd_usb_midi_out_endpoint *ep)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-07-13 19:43:59 +08:00
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < OUTPUT_URBS; ++i)
|
2010-04-11 03:27:23 +08:00
|
|
|
if (ep->urbs[i].urb) {
|
2009-07-13 19:43:59 +08:00
|
|
|
free_urb_and_buffer(ep->umidi, ep->urbs[i].urb,
|
|
|
|
ep->max_transfer);
|
2010-04-11 03:27:23 +08:00
|
|
|
ep->urbs[i].urb = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void snd_usbmidi_out_endpoint_delete(struct snd_usb_midi_out_endpoint *ep)
|
|
|
|
{
|
|
|
|
snd_usbmidi_out_endpoint_clear(ep);
|
2005-04-17 06:20:36 +08:00
|
|
|
kfree(ep);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Creates an output endpoint, and initializes output ports.
|
|
|
|
*/
|
2014-08-06 00:44:51 +08:00
|
|
|
static int snd_usbmidi_out_endpoint_create(struct snd_usb_midi *umidi,
|
|
|
|
struct snd_usb_midi_endpoint_info *ep_info,
|
|
|
|
struct snd_usb_midi_endpoint *rep)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2014-08-06 00:44:51 +08:00
|
|
|
struct snd_usb_midi_out_endpoint *ep;
|
2009-07-13 19:43:59 +08:00
|
|
|
unsigned int i;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned int pipe;
|
2014-08-06 00:44:51 +08:00
|
|
|
void *buffer;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
rep->out = NULL;
|
[ALSA] Replace with kzalloc() - others
Documentation,SA11xx UDA1341 driver,Generic drivers,MPU401 UART,OPL3
OPL4,Digigram VX core,I2C cs8427,I2C lib core,I2C tea6330t,L3 drivers
AK4114 receiver,AK4117 receiver,PDAudioCF driver,PPC PMAC driver
SPARC AMD7930 driver,SPARC cs4231 driver,Synth,Common EMU synth
USB generic driver,USB USX2Y
Replace kcalloc(1,..) with kzalloc().
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2005-09-09 20:22:34 +08:00
|
|
|
ep = kzalloc(sizeof(*ep), GFP_KERNEL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!ep)
|
|
|
|
return -ENOMEM;
|
|
|
|
ep->umidi = umidi;
|
|
|
|
|
2009-07-13 19:43:59 +08:00
|
|
|
for (i = 0; i < OUTPUT_URBS; ++i) {
|
|
|
|
ep->urbs[i].urb = usb_alloc_urb(0, GFP_KERNEL);
|
|
|
|
if (!ep->urbs[i].urb) {
|
|
|
|
snd_usbmidi_out_endpoint_delete(ep);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
ep->urbs[i].ep = ep;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2007-08-21 14:56:08 +08:00
|
|
|
if (ep_info->out_interval)
|
2009-11-16 19:23:46 +08:00
|
|
|
pipe = usb_sndintpipe(umidi->dev, ep_info->out_ep);
|
2007-08-21 14:56:08 +08:00
|
|
|
else
|
2009-11-16 19:23:46 +08:00
|
|
|
pipe = usb_sndbulkpipe(umidi->dev, ep_info->out_ep);
|
2010-02-15 15:55:28 +08:00
|
|
|
switch (umidi->usb_id) {
|
|
|
|
default:
|
2009-11-16 19:23:46 +08:00
|
|
|
ep->max_transfer = usb_maxpacket(umidi->dev, pipe, 1);
|
2010-02-15 15:55:28 +08:00
|
|
|
break;
|
|
|
|
/*
|
|
|
|
* Various chips declare a packet size larger than 4 bytes, but
|
|
|
|
* do not actually work with larger packets:
|
|
|
|
*/
|
2015-11-16 05:37:44 +08:00
|
|
|
case USB_ID(0x0a67, 0x5011): /* Medeli DD305 */
|
2010-02-15 15:55:28 +08:00
|
|
|
case USB_ID(0x0a92, 0x1020): /* ESI M4U */
|
|
|
|
case USB_ID(0x1430, 0x474b): /* RedOctane GH MIDI INTERFACE */
|
|
|
|
case USB_ID(0x15ca, 0x0101): /* Textech USB Midi Cable */
|
|
|
|
case USB_ID(0x15ca, 0x1806): /* Textech USB Midi Cable */
|
|
|
|
case USB_ID(0x1a86, 0x752d): /* QinHeng CH345 "USB2.0-MIDI" */
|
2011-04-04 22:23:53 +08:00
|
|
|
case USB_ID(0xfc08, 0x0101): /* Unknown vendor Cable */
|
2010-02-15 15:55:28 +08:00
|
|
|
ep->max_transfer = 4;
|
|
|
|
break;
|
2011-01-03 09:41:58 +08:00
|
|
|
/*
|
|
|
|
* Some devices only work with 9 bytes packet size:
|
|
|
|
*/
|
|
|
|
case USB_ID(0x0644, 0x800E): /* Tascam US-122L */
|
|
|
|
case USB_ID(0x0644, 0x800F): /* Tascam US-144 */
|
|
|
|
ep->max_transfer = 9;
|
|
|
|
break;
|
2010-02-15 15:55:28 +08:00
|
|
|
}
|
2009-07-13 19:43:59 +08:00
|
|
|
for (i = 0; i < OUTPUT_URBS; ++i) {
|
2010-04-12 19:17:25 +08:00
|
|
|
buffer = usb_alloc_coherent(umidi->dev,
|
|
|
|
ep->max_transfer, GFP_KERNEL,
|
|
|
|
&ep->urbs[i].urb->transfer_dma);
|
2009-07-13 19:43:59 +08:00
|
|
|
if (!buffer) {
|
|
|
|
snd_usbmidi_out_endpoint_delete(ep);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
if (ep_info->out_interval)
|
2009-11-16 19:23:46 +08:00
|
|
|
usb_fill_int_urb(ep->urbs[i].urb, umidi->dev,
|
2009-07-13 19:43:59 +08:00
|
|
|
pipe, buffer, ep->max_transfer,
|
|
|
|
snd_usbmidi_out_urb_complete,
|
|
|
|
&ep->urbs[i], ep_info->out_interval);
|
|
|
|
else
|
2009-11-16 19:23:46 +08:00
|
|
|
usb_fill_bulk_urb(ep->urbs[i].urb, umidi->dev,
|
2009-07-13 19:43:59 +08:00
|
|
|
pipe, buffer, ep->max_transfer,
|
|
|
|
snd_usbmidi_out_urb_complete,
|
|
|
|
&ep->urbs[i]);
|
|
|
|
ep->urbs[i].urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock_init(&ep->buffer_lock);
|
|
|
|
tasklet_init(&ep->tasklet, snd_usbmidi_out_tasklet, (unsigned long)ep);
|
2009-07-13 19:48:36 +08:00
|
|
|
init_waitqueue_head(&ep->drain_wait);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
for (i = 0; i < 0x10; ++i)
|
|
|
|
if (ep_info->out_cables & (1 << i)) {
|
|
|
|
ep->ports[i].ep = ep;
|
|
|
|
ep->ports[i].cable = i << 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (umidi->usb_protocol_ops->init_out_endpoint)
|
|
|
|
umidi->usb_protocol_ops->init_out_endpoint(ep);
|
|
|
|
|
|
|
|
rep->out = ep;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Frees everything.
|
|
|
|
*/
|
2014-08-06 00:44:51 +08:00
|
|
|
static void snd_usbmidi_free(struct snd_usb_midi *umidi)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) {
|
2014-08-06 00:44:51 +08:00
|
|
|
struct snd_usb_midi_endpoint *ep = &umidi->endpoints[i];
|
2005-04-17 06:20:36 +08:00
|
|
|
if (ep->out)
|
|
|
|
snd_usbmidi_out_endpoint_delete(ep->out);
|
|
|
|
if (ep->in)
|
|
|
|
snd_usbmidi_in_endpoint_delete(ep->in);
|
|
|
|
}
|
2009-10-22 15:06:19 +08:00
|
|
|
mutex_destroy(&umidi->mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
kfree(umidi);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unlinks all URBs (must be done before the usb_device is deleted).
|
|
|
|
*/
|
2014-08-06 00:44:51 +08:00
|
|
|
void snd_usbmidi_disconnect(struct list_head *p)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2014-08-06 00:44:51 +08:00
|
|
|
struct snd_usb_midi *umidi;
|
2009-07-13 19:40:36 +08:00
|
|
|
unsigned int i, j;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-11-17 22:08:02 +08:00
|
|
|
umidi = list_entry(p, struct snd_usb_midi, list);
|
2008-02-23 01:34:44 +08:00
|
|
|
/*
|
|
|
|
* an URB's completion handler may start the timer and
|
|
|
|
* a timer may submit an URB. To reliably break the cycle
|
|
|
|
* a flag under lock must be used
|
|
|
|
*/
|
2012-12-03 18:12:46 +08:00
|
|
|
down_write(&umidi->disc_rwsem);
|
2008-02-23 01:34:44 +08:00
|
|
|
spin_lock_irq(&umidi->disc_lock);
|
|
|
|
umidi->disconnected = 1;
|
|
|
|
spin_unlock_irq(&umidi->disc_lock);
|
2012-12-03 18:12:46 +08:00
|
|
|
up_write(&umidi->disc_rwsem);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) {
|
2014-08-06 00:44:51 +08:00
|
|
|
struct snd_usb_midi_endpoint *ep = &umidi->endpoints[i];
|
2005-08-02 21:26:52 +08:00
|
|
|
if (ep->out)
|
|
|
|
tasklet_kill(&ep->out->tasklet);
|
2009-07-13 19:43:59 +08:00
|
|
|
if (ep->out) {
|
|
|
|
for (j = 0; j < OUTPUT_URBS; ++j)
|
|
|
|
usb_kill_urb(ep->out->urbs[j].urb);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (umidi->usb_protocol_ops->finish_out_endpoint)
|
|
|
|
umidi->usb_protocol_ops->finish_out_endpoint(ep->out);
|
2010-04-11 03:27:23 +08:00
|
|
|
ep->out->active_urbs = 0;
|
|
|
|
if (ep->out->drain_urbs) {
|
|
|
|
ep->out->drain_urbs = 0;
|
|
|
|
wake_up(&ep->out->drain_wait);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2006-11-08 22:37:00 +08:00
|
|
|
if (ep->in)
|
2009-07-13 19:40:36 +08:00
|
|
|
for (j = 0; j < INPUT_URBS; ++j)
|
|
|
|
usb_kill_urb(ep->in->urbs[j]);
|
2008-10-02 20:50:22 +08:00
|
|
|
/* free endpoints here; later call can result in Oops */
|
2010-04-11 03:27:23 +08:00
|
|
|
if (ep->out)
|
|
|
|
snd_usbmidi_out_endpoint_clear(ep->out);
|
2008-10-02 20:50:22 +08:00
|
|
|
if (ep->in) {
|
|
|
|
snd_usbmidi_in_endpoint_delete(ep->in);
|
|
|
|
ep->in = NULL;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2008-02-23 01:34:44 +08:00
|
|
|
del_timer_sync(&umidi->error_timer);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2013-04-04 05:18:51 +08:00
|
|
|
EXPORT_SYMBOL(snd_usbmidi_disconnect);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-11-17 22:08:02 +08:00
|
|
|
static void snd_usbmidi_rawmidi_free(struct snd_rawmidi *rmidi)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2014-08-06 00:44:51 +08:00
|
|
|
struct snd_usb_midi *umidi = rmidi->private_data;
|
2005-04-17 06:20:36 +08:00
|
|
|
snd_usbmidi_free(umidi);
|
|
|
|
}
|
|
|
|
|
2014-08-06 00:44:51 +08:00
|
|
|
static struct snd_rawmidi_substream *snd_usbmidi_find_substream(struct snd_usb_midi *umidi,
|
|
|
|
int stream,
|
|
|
|
int number)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2013-04-04 05:18:49 +08:00
|
|
|
struct snd_rawmidi_substream *substream;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-08-06 00:44:51 +08:00
|
|
|
list_for_each_entry(substream, &umidi->rmidi->streams[stream].substreams,
|
|
|
|
list) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (substream->number == number)
|
|
|
|
return substream;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This list specifies names for ports that do not fit into the standard
|
|
|
|
* "(product) MIDI (n)" schema because they aren't external MIDI ports,
|
|
|
|
* such as internal control or synthesizer ports.
|
|
|
|
*/
|
2006-05-02 22:22:12 +08:00
|
|
|
static struct port_info {
|
2005-05-02 14:51:26 +08:00
|
|
|
u32 id;
|
2006-05-02 22:22:12 +08:00
|
|
|
short int port;
|
|
|
|
short int voices;
|
|
|
|
const char *name;
|
|
|
|
unsigned int seq_flags;
|
|
|
|
} snd_usbmidi_port_info[] = {
|
|
|
|
#define PORT_INFO(vendor, product, num, name_, voices_, flags) \
|
|
|
|
{ .id = USB_ID(vendor, product), \
|
|
|
|
.port = num, .voices = voices_, \
|
|
|
|
.name = name_, .seq_flags = flags }
|
|
|
|
#define EXTERNAL_PORT(vendor, product, num, name) \
|
|
|
|
PORT_INFO(vendor, product, num, name, 0, \
|
|
|
|
SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC | \
|
|
|
|
SNDRV_SEQ_PORT_TYPE_HARDWARE | \
|
|
|
|
SNDRV_SEQ_PORT_TYPE_PORT)
|
|
|
|
#define CONTROL_PORT(vendor, product, num, name) \
|
|
|
|
PORT_INFO(vendor, product, num, name, 0, \
|
|
|
|
SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC | \
|
|
|
|
SNDRV_SEQ_PORT_TYPE_HARDWARE)
|
2014-09-08 03:44:29 +08:00
|
|
|
#define GM_SYNTH_PORT(vendor, product, num, name, voices) \
|
|
|
|
PORT_INFO(vendor, product, num, name, voices, \
|
|
|
|
SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC | \
|
|
|
|
SNDRV_SEQ_PORT_TYPE_MIDI_GM | \
|
|
|
|
SNDRV_SEQ_PORT_TYPE_HARDWARE | \
|
|
|
|
SNDRV_SEQ_PORT_TYPE_SYNTHESIZER)
|
2006-05-02 22:22:12 +08:00
|
|
|
#define ROLAND_SYNTH_PORT(vendor, product, num, name, voices) \
|
|
|
|
PORT_INFO(vendor, product, num, name, voices, \
|
|
|
|
SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC | \
|
|
|
|
SNDRV_SEQ_PORT_TYPE_MIDI_GM | \
|
|
|
|
SNDRV_SEQ_PORT_TYPE_MIDI_GM2 | \
|
|
|
|
SNDRV_SEQ_PORT_TYPE_MIDI_GS | \
|
|
|
|
SNDRV_SEQ_PORT_TYPE_MIDI_XG | \
|
|
|
|
SNDRV_SEQ_PORT_TYPE_HARDWARE | \
|
|
|
|
SNDRV_SEQ_PORT_TYPE_SYNTHESIZER)
|
|
|
|
#define SOUNDCANVAS_PORT(vendor, product, num, name, voices) \
|
|
|
|
PORT_INFO(vendor, product, num, name, voices, \
|
|
|
|
SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC | \
|
|
|
|
SNDRV_SEQ_PORT_TYPE_MIDI_GM | \
|
|
|
|
SNDRV_SEQ_PORT_TYPE_MIDI_GM2 | \
|
|
|
|
SNDRV_SEQ_PORT_TYPE_MIDI_GS | \
|
|
|
|
SNDRV_SEQ_PORT_TYPE_MIDI_XG | \
|
|
|
|
SNDRV_SEQ_PORT_TYPE_MIDI_MT32 | \
|
|
|
|
SNDRV_SEQ_PORT_TYPE_HARDWARE | \
|
|
|
|
SNDRV_SEQ_PORT_TYPE_SYNTHESIZER)
|
2014-09-08 03:44:29 +08:00
|
|
|
/* Yamaha MOTIF XF */
|
|
|
|
GM_SYNTH_PORT(0x0499, 0x105c, 0, "%s Tone Generator", 128),
|
|
|
|
CONTROL_PORT(0x0499, 0x105c, 1, "%s Remote Control"),
|
|
|
|
EXTERNAL_PORT(0x0499, 0x105c, 2, "%s Thru"),
|
|
|
|
CONTROL_PORT(0x0499, 0x105c, 3, "%s Editor"),
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Roland UA-100 */
|
2006-05-02 22:22:12 +08:00
|
|
|
CONTROL_PORT(0x0582, 0x0000, 2, "%s Control"),
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Roland SC-8850 */
|
2006-05-02 22:22:12 +08:00
|
|
|
SOUNDCANVAS_PORT(0x0582, 0x0003, 0, "%s Part A", 128),
|
|
|
|
SOUNDCANVAS_PORT(0x0582, 0x0003, 1, "%s Part B", 128),
|
|
|
|
SOUNDCANVAS_PORT(0x0582, 0x0003, 2, "%s Part C", 128),
|
|
|
|
SOUNDCANVAS_PORT(0x0582, 0x0003, 3, "%s Part D", 128),
|
|
|
|
EXTERNAL_PORT(0x0582, 0x0003, 4, "%s MIDI 1"),
|
|
|
|
EXTERNAL_PORT(0x0582, 0x0003, 5, "%s MIDI 2"),
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Roland U-8 */
|
2006-05-02 22:22:12 +08:00
|
|
|
EXTERNAL_PORT(0x0582, 0x0004, 0, "%s MIDI"),
|
|
|
|
CONTROL_PORT(0x0582, 0x0004, 1, "%s Control"),
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Roland SC-8820 */
|
2006-05-02 22:22:12 +08:00
|
|
|
SOUNDCANVAS_PORT(0x0582, 0x0007, 0, "%s Part A", 64),
|
|
|
|
SOUNDCANVAS_PORT(0x0582, 0x0007, 1, "%s Part B", 64),
|
|
|
|
EXTERNAL_PORT(0x0582, 0x0007, 2, "%s MIDI"),
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Roland SK-500 */
|
2006-05-02 22:22:12 +08:00
|
|
|
SOUNDCANVAS_PORT(0x0582, 0x000b, 0, "%s Part A", 64),
|
|
|
|
SOUNDCANVAS_PORT(0x0582, 0x000b, 1, "%s Part B", 64),
|
|
|
|
EXTERNAL_PORT(0x0582, 0x000b, 2, "%s MIDI"),
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Roland SC-D70 */
|
2006-05-02 22:22:12 +08:00
|
|
|
SOUNDCANVAS_PORT(0x0582, 0x000c, 0, "%s Part A", 64),
|
|
|
|
SOUNDCANVAS_PORT(0x0582, 0x000c, 1, "%s Part B", 64),
|
|
|
|
EXTERNAL_PORT(0x0582, 0x000c, 2, "%s MIDI"),
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Edirol UM-880 */
|
2006-05-02 22:22:12 +08:00
|
|
|
CONTROL_PORT(0x0582, 0x0014, 8, "%s Control"),
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Edirol SD-90 */
|
2006-05-02 22:22:12 +08:00
|
|
|
ROLAND_SYNTH_PORT(0x0582, 0x0016, 0, "%s Part A", 128),
|
|
|
|
ROLAND_SYNTH_PORT(0x0582, 0x0016, 1, "%s Part B", 128),
|
|
|
|
EXTERNAL_PORT(0x0582, 0x0016, 2, "%s MIDI 1"),
|
|
|
|
EXTERNAL_PORT(0x0582, 0x0016, 3, "%s MIDI 2"),
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Edirol UM-550 */
|
2006-05-02 22:22:12 +08:00
|
|
|
CONTROL_PORT(0x0582, 0x0023, 5, "%s Control"),
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Edirol SD-20 */
|
2006-05-02 22:22:12 +08:00
|
|
|
ROLAND_SYNTH_PORT(0x0582, 0x0027, 0, "%s Part A", 64),
|
|
|
|
ROLAND_SYNTH_PORT(0x0582, 0x0027, 1, "%s Part B", 64),
|
|
|
|
EXTERNAL_PORT(0x0582, 0x0027, 2, "%s MIDI"),
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Edirol SD-80 */
|
2006-05-02 22:22:12 +08:00
|
|
|
ROLAND_SYNTH_PORT(0x0582, 0x0029, 0, "%s Part A", 128),
|
|
|
|
ROLAND_SYNTH_PORT(0x0582, 0x0029, 1, "%s Part B", 128),
|
|
|
|
EXTERNAL_PORT(0x0582, 0x0029, 2, "%s MIDI 1"),
|
|
|
|
EXTERNAL_PORT(0x0582, 0x0029, 3, "%s MIDI 2"),
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Edirol UA-700 */
|
2006-05-02 22:22:12 +08:00
|
|
|
EXTERNAL_PORT(0x0582, 0x002b, 0, "%s MIDI"),
|
|
|
|
CONTROL_PORT(0x0582, 0x002b, 1, "%s Control"),
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Roland VariOS */
|
2006-05-02 22:22:12 +08:00
|
|
|
EXTERNAL_PORT(0x0582, 0x002f, 0, "%s MIDI"),
|
|
|
|
EXTERNAL_PORT(0x0582, 0x002f, 1, "%s External MIDI"),
|
|
|
|
EXTERNAL_PORT(0x0582, 0x002f, 2, "%s Sync"),
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Edirol PCR */
|
2006-05-02 22:22:12 +08:00
|
|
|
EXTERNAL_PORT(0x0582, 0x0033, 0, "%s MIDI"),
|
|
|
|
EXTERNAL_PORT(0x0582, 0x0033, 1, "%s 1"),
|
|
|
|
EXTERNAL_PORT(0x0582, 0x0033, 2, "%s 2"),
|
2005-04-17 06:20:36 +08:00
|
|
|
/* BOSS GS-10 */
|
2006-05-02 22:22:12 +08:00
|
|
|
EXTERNAL_PORT(0x0582, 0x003b, 0, "%s MIDI"),
|
|
|
|
CONTROL_PORT(0x0582, 0x003b, 1, "%s Control"),
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Edirol UA-1000 */
|
2006-05-02 22:22:12 +08:00
|
|
|
EXTERNAL_PORT(0x0582, 0x0044, 0, "%s MIDI"),
|
|
|
|
CONTROL_PORT(0x0582, 0x0044, 1, "%s Control"),
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Edirol UR-80 */
|
2006-05-02 22:22:12 +08:00
|
|
|
EXTERNAL_PORT(0x0582, 0x0048, 0, "%s MIDI"),
|
|
|
|
EXTERNAL_PORT(0x0582, 0x0048, 1, "%s 1"),
|
|
|
|
EXTERNAL_PORT(0x0582, 0x0048, 2, "%s 2"),
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Edirol PCR-A */
|
2006-05-02 22:22:12 +08:00
|
|
|
EXTERNAL_PORT(0x0582, 0x004d, 0, "%s MIDI"),
|
|
|
|
EXTERNAL_PORT(0x0582, 0x004d, 1, "%s 1"),
|
|
|
|
EXTERNAL_PORT(0x0582, 0x004d, 2, "%s 2"),
|
2013-02-09 17:05:20 +08:00
|
|
|
/* BOSS GT-PRO */
|
|
|
|
CONTROL_PORT(0x0582, 0x0089, 0, "%s Control"),
|
2006-01-11 01:56:23 +08:00
|
|
|
/* Edirol UM-3EX */
|
2006-05-02 22:22:12 +08:00
|
|
|
CONTROL_PORT(0x0582, 0x009a, 3, "%s Control"),
|
2013-02-09 17:05:20 +08:00
|
|
|
/* Roland VG-99 */
|
|
|
|
CONTROL_PORT(0x0582, 0x00b2, 0, "%s Control"),
|
|
|
|
EXTERNAL_PORT(0x0582, 0x00b2, 1, "%s MIDI"),
|
|
|
|
/* Cakewalk Sonar V-Studio 100 */
|
|
|
|
EXTERNAL_PORT(0x0582, 0x00eb, 0, "%s MIDI"),
|
|
|
|
CONTROL_PORT(0x0582, 0x00eb, 1, "%s Control"),
|
|
|
|
/* Roland VB-99 */
|
|
|
|
CONTROL_PORT(0x0582, 0x0102, 0, "%s Control"),
|
|
|
|
EXTERNAL_PORT(0x0582, 0x0102, 1, "%s MIDI"),
|
|
|
|
/* Roland A-PRO */
|
|
|
|
EXTERNAL_PORT(0x0582, 0x010f, 0, "%s MIDI"),
|
|
|
|
CONTROL_PORT(0x0582, 0x010f, 1, "%s 1"),
|
|
|
|
CONTROL_PORT(0x0582, 0x010f, 2, "%s 2"),
|
|
|
|
/* Roland SD-50 */
|
|
|
|
ROLAND_SYNTH_PORT(0x0582, 0x0114, 0, "%s Synth", 128),
|
|
|
|
EXTERNAL_PORT(0x0582, 0x0114, 1, "%s MIDI"),
|
|
|
|
CONTROL_PORT(0x0582, 0x0114, 2, "%s Control"),
|
|
|
|
/* Roland OCTA-CAPTURE */
|
|
|
|
EXTERNAL_PORT(0x0582, 0x0120, 0, "%s MIDI"),
|
|
|
|
CONTROL_PORT(0x0582, 0x0120, 1, "%s Control"),
|
|
|
|
EXTERNAL_PORT(0x0582, 0x0121, 0, "%s MIDI"),
|
|
|
|
CONTROL_PORT(0x0582, 0x0121, 1, "%s Control"),
|
|
|
|
/* Roland SPD-SX */
|
|
|
|
CONTROL_PORT(0x0582, 0x0145, 0, "%s Control"),
|
|
|
|
EXTERNAL_PORT(0x0582, 0x0145, 1, "%s MIDI"),
|
|
|
|
/* Roland A-Series */
|
|
|
|
CONTROL_PORT(0x0582, 0x0156, 0, "%s Keyboard"),
|
|
|
|
EXTERNAL_PORT(0x0582, 0x0156, 1, "%s MIDI"),
|
|
|
|
/* Roland INTEGRA-7 */
|
|
|
|
ROLAND_SYNTH_PORT(0x0582, 0x015b, 0, "%s Synth", 128),
|
|
|
|
CONTROL_PORT(0x0582, 0x015b, 1, "%s Control"),
|
2005-04-17 06:20:36 +08:00
|
|
|
/* M-Audio MidiSport 8x8 */
|
2006-05-02 22:22:12 +08:00
|
|
|
CONTROL_PORT(0x0763, 0x1031, 8, "%s Control"),
|
|
|
|
CONTROL_PORT(0x0763, 0x1033, 8, "%s Control"),
|
2005-04-17 06:20:36 +08:00
|
|
|
/* MOTU Fastlane */
|
2006-05-02 22:22:12 +08:00
|
|
|
EXTERNAL_PORT(0x07fd, 0x0001, 0, "%s MIDI A"),
|
|
|
|
EXTERNAL_PORT(0x07fd, 0x0001, 1, "%s MIDI B"),
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Emagic Unitor8/AMT8/MT4 */
|
2006-05-02 22:22:12 +08:00
|
|
|
EXTERNAL_PORT(0x086a, 0x0001, 8, "%s Broadcast"),
|
|
|
|
EXTERNAL_PORT(0x086a, 0x0002, 8, "%s Broadcast"),
|
|
|
|
EXTERNAL_PORT(0x086a, 0x0003, 4, "%s Broadcast"),
|
2010-05-21 03:31:10 +08:00
|
|
|
/* Akai MPD16 */
|
|
|
|
CONTROL_PORT(0x09e8, 0x0062, 0, "%s Control"),
|
|
|
|
PORT_INFO(0x09e8, 0x0062, 1, "%s MIDI", 0,
|
|
|
|
SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC |
|
|
|
|
SNDRV_SEQ_PORT_TYPE_HARDWARE),
|
2010-02-16 15:55:08 +08:00
|
|
|
/* Access Music Virus TI */
|
|
|
|
EXTERNAL_PORT(0x133e, 0x0815, 0, "%s MIDI"),
|
|
|
|
PORT_INFO(0x133e, 0x0815, 1, "%s Synth", 0,
|
|
|
|
SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC |
|
|
|
|
SNDRV_SEQ_PORT_TYPE_HARDWARE |
|
|
|
|
SNDRV_SEQ_PORT_TYPE_SYNTHESIZER),
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2014-08-06 00:44:51 +08:00
|
|
|
static struct port_info *find_port_info(struct snd_usb_midi *umidi, int number)
|
2006-05-02 22:22:12 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(snd_usbmidi_port_info); ++i) {
|
2009-11-16 19:23:46 +08:00
|
|
|
if (snd_usbmidi_port_info[i].id == umidi->usb_id &&
|
2006-05-02 22:22:12 +08:00
|
|
|
snd_usbmidi_port_info[i].port == number)
|
|
|
|
return &snd_usbmidi_port_info[i];
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void snd_usbmidi_get_port_info(struct snd_rawmidi *rmidi, int number,
|
|
|
|
struct snd_seq_port_info *seq_port_info)
|
|
|
|
{
|
|
|
|
struct snd_usb_midi *umidi = rmidi->private_data;
|
|
|
|
struct port_info *port_info;
|
|
|
|
|
|
|
|
/* TODO: read port flags from descriptors */
|
|
|
|
port_info = find_port_info(umidi, number);
|
|
|
|
if (port_info) {
|
|
|
|
seq_port_info->type = port_info->seq_flags;
|
|
|
|
seq_port_info->midi_voices = port_info->voices;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-06 00:44:51 +08:00
|
|
|
static void snd_usbmidi_init_substream(struct snd_usb_midi *umidi,
|
2005-04-17 06:20:36 +08:00
|
|
|
int stream, int number,
|
2014-08-06 00:44:51 +08:00
|
|
|
struct snd_rawmidi_substream **rsubstream)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-05-02 22:22:12 +08:00
|
|
|
struct port_info *port_info;
|
2005-04-17 06:20:36 +08:00
|
|
|
const char *name_format;
|
|
|
|
|
2014-08-06 00:44:51 +08:00
|
|
|
struct snd_rawmidi_substream *substream =
|
|
|
|
snd_usbmidi_find_substream(umidi, stream, number);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!substream) {
|
2014-08-06 00:44:51 +08:00
|
|
|
dev_err(&umidi->dev->dev, "substream %d:%d not found\n", stream,
|
|
|
|
number);
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: read port name from jack descriptor */
|
2006-05-02 22:22:12 +08:00
|
|
|
port_info = find_port_info(umidi, number);
|
|
|
|
name_format = port_info ? port_info->name : "%s MIDI %d";
|
2005-04-17 06:20:36 +08:00
|
|
|
snprintf(substream->name, sizeof(substream->name),
|
2009-11-16 19:23:46 +08:00
|
|
|
name_format, umidi->card->shortname, number + 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
*rsubstream = substream;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Creates the endpoints and their ports.
|
|
|
|
*/
|
2014-08-06 00:44:51 +08:00
|
|
|
static int snd_usbmidi_create_endpoints(struct snd_usb_midi *umidi,
|
|
|
|
struct snd_usb_midi_endpoint_info *endpoints)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int i, j, err;
|
|
|
|
int out_ports = 0, in_ports = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) {
|
|
|
|
if (endpoints[i].out_cables) {
|
2014-08-06 00:44:51 +08:00
|
|
|
err = snd_usbmidi_out_endpoint_create(umidi,
|
|
|
|
&endpoints[i],
|
2005-04-17 06:20:36 +08:00
|
|
|
&umidi->endpoints[i]);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
if (endpoints[i].in_cables) {
|
2014-08-06 00:44:51 +08:00
|
|
|
err = snd_usbmidi_in_endpoint_create(umidi,
|
|
|
|
&endpoints[i],
|
2005-04-17 06:20:36 +08:00
|
|
|
&umidi->endpoints[i]);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j = 0; j < 0x10; ++j) {
|
|
|
|
if (endpoints[i].out_cables & (1 << j)) {
|
2014-08-06 00:44:51 +08:00
|
|
|
snd_usbmidi_init_substream(umidi,
|
|
|
|
SNDRV_RAWMIDI_STREAM_OUTPUT,
|
|
|
|
out_ports,
|
2005-04-17 06:20:36 +08:00
|
|
|
&umidi->endpoints[i].out->ports[j].substream);
|
|
|
|
++out_ports;
|
|
|
|
}
|
|
|
|
if (endpoints[i].in_cables & (1 << j)) {
|
2014-08-06 00:44:51 +08:00
|
|
|
snd_usbmidi_init_substream(umidi,
|
|
|
|
SNDRV_RAWMIDI_STREAM_INPUT,
|
|
|
|
in_ports,
|
2005-04-17 06:20:36 +08:00
|
|
|
&umidi->endpoints[i].in->ports[j].substream);
|
|
|
|
++in_ports;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-02-26 20:02:17 +08:00
|
|
|
dev_dbg(&umidi->dev->dev, "created %d output and %d input ports\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
out_ports, in_ports);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns MIDIStreaming device capabilities.
|
|
|
|
*/
|
2014-08-06 00:44:51 +08:00
|
|
|
static int snd_usbmidi_get_ms_info(struct snd_usb_midi *umidi,
|
|
|
|
struct snd_usb_midi_endpoint_info *endpoints)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2014-08-06 00:44:51 +08:00
|
|
|
struct usb_interface *intf;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct usb_host_interface *hostif;
|
2014-08-06 00:44:51 +08:00
|
|
|
struct usb_interface_descriptor *intfd;
|
|
|
|
struct usb_ms_header_descriptor *ms_header;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct usb_host_endpoint *hostep;
|
2014-08-06 00:44:51 +08:00
|
|
|
struct usb_endpoint_descriptor *ep;
|
|
|
|
struct usb_ms_endpoint_descriptor *ms_ep;
|
2005-04-17 06:20:36 +08:00
|
|
|
int i, epidx;
|
|
|
|
|
|
|
|
intf = umidi->iface;
|
|
|
|
if (!intf)
|
|
|
|
return -ENXIO;
|
|
|
|
hostif = &intf->altsetting[0];
|
|
|
|
intfd = get_iface_desc(hostif);
|
2014-08-06 00:44:51 +08:00
|
|
|
ms_header = (struct usb_ms_header_descriptor *)hostif->extra;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (hostif->extralen >= 7 &&
|
|
|
|
ms_header->bLength >= 7 &&
|
|
|
|
ms_header->bDescriptorType == USB_DT_CS_INTERFACE &&
|
2010-02-23 06:49:13 +08:00
|
|
|
ms_header->bDescriptorSubtype == UAC_HEADER)
|
2014-02-26 20:02:17 +08:00
|
|
|
dev_dbg(&umidi->dev->dev, "MIDIStreaming version %02x.%02x\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
ms_header->bcdMSC[1], ms_header->bcdMSC[0]);
|
|
|
|
else
|
2014-02-26 20:02:17 +08:00
|
|
|
dev_warn(&umidi->dev->dev,
|
|
|
|
"MIDIStreaming interface descriptor not found\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
epidx = 0;
|
|
|
|
for (i = 0; i < intfd->bNumEndpoints; ++i) {
|
|
|
|
hostep = &hostif->endpoint[i];
|
|
|
|
ep = get_ep_desc(hostep);
|
2009-01-04 00:54:53 +08:00
|
|
|
if (!usb_endpoint_xfer_bulk(ep) && !usb_endpoint_xfer_int(ep))
|
2005-04-17 06:20:36 +08:00
|
|
|
continue;
|
2014-08-06 00:44:51 +08:00
|
|
|
ms_ep = (struct usb_ms_endpoint_descriptor *)hostep->extra;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (hostep->extralen < 4 ||
|
|
|
|
ms_ep->bLength < 4 ||
|
|
|
|
ms_ep->bDescriptorType != USB_DT_CS_ENDPOINT ||
|
2010-02-23 06:49:13 +08:00
|
|
|
ms_ep->bDescriptorSubtype != UAC_MS_GENERAL)
|
2005-04-17 06:20:36 +08:00
|
|
|
continue;
|
2008-12-29 18:23:02 +08:00
|
|
|
if (usb_endpoint_dir_out(ep)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (endpoints[epidx].out_ep) {
|
|
|
|
if (++epidx >= MIDI_MAX_ENDPOINTS) {
|
2014-02-26 20:02:17 +08:00
|
|
|
dev_warn(&umidi->dev->dev,
|
|
|
|
"too many endpoints\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-12-29 18:23:02 +08:00
|
|
|
endpoints[epidx].out_ep = usb_endpoint_num(ep);
|
|
|
|
if (usb_endpoint_xfer_int(ep))
|
2005-04-17 06:20:36 +08:00
|
|
|
endpoints[epidx].out_interval = ep->bInterval;
|
2009-11-16 19:23:46 +08:00
|
|
|
else if (snd_usb_get_speed(umidi->dev) == USB_SPEED_LOW)
|
2007-08-21 14:57:34 +08:00
|
|
|
/*
|
|
|
|
* Low speed bulk transfers don't exist, so
|
|
|
|
* force interrupt transfers for devices like
|
|
|
|
* ESI MIDI Mate that try to use them anyway.
|
|
|
|
*/
|
|
|
|
endpoints[epidx].out_interval = 1;
|
2014-08-06 00:44:51 +08:00
|
|
|
endpoints[epidx].out_cables =
|
|
|
|
(1 << ms_ep->bNumEmbMIDIJack) - 1;
|
2014-02-26 20:02:17 +08:00
|
|
|
dev_dbg(&umidi->dev->dev, "EP %02X: %d jack(s)\n",
|
2014-08-06 00:44:51 +08:00
|
|
|
ep->bEndpointAddress, ms_ep->bNumEmbMIDIJack);
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
|
|
|
if (endpoints[epidx].in_ep) {
|
|
|
|
if (++epidx >= MIDI_MAX_ENDPOINTS) {
|
2014-02-26 20:02:17 +08:00
|
|
|
dev_warn(&umidi->dev->dev,
|
|
|
|
"too many endpoints\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-12-29 18:23:02 +08:00
|
|
|
endpoints[epidx].in_ep = usb_endpoint_num(ep);
|
|
|
|
if (usb_endpoint_xfer_int(ep))
|
2005-04-17 06:20:36 +08:00
|
|
|
endpoints[epidx].in_interval = ep->bInterval;
|
2009-11-16 19:23:46 +08:00
|
|
|
else if (snd_usb_get_speed(umidi->dev) == USB_SPEED_LOW)
|
2007-08-21 14:57:34 +08:00
|
|
|
endpoints[epidx].in_interval = 1;
|
2014-08-06 00:44:51 +08:00
|
|
|
endpoints[epidx].in_cables =
|
|
|
|
(1 << ms_ep->bNumEmbMIDIJack) - 1;
|
2014-02-26 20:02:17 +08:00
|
|
|
dev_dbg(&umidi->dev->dev, "EP %02X: %d jack(s)\n",
|
2014-08-06 00:44:51 +08:00
|
|
|
ep->bEndpointAddress, ms_ep->bNumEmbMIDIJack);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-10-22 15:06:19 +08:00
|
|
|
static int roland_load_info(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_info *info)
|
|
|
|
{
|
|
|
|
static const char *const names[] = { "High Load", "Light Load" };
|
|
|
|
|
2011-01-10 23:30:13 +08:00
|
|
|
return snd_ctl_enum_info(info, 1, 2, names);
|
2009-10-22 15:06:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int roland_load_get(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *value)
|
|
|
|
{
|
|
|
|
value->value.enumerated.item[0] = kcontrol->private_value;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int roland_load_put(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *value)
|
|
|
|
{
|
2014-08-06 00:44:51 +08:00
|
|
|
struct snd_usb_midi *umidi = kcontrol->private_data;
|
2009-10-22 15:06:19 +08:00
|
|
|
int changed;
|
|
|
|
|
|
|
|
if (value->value.enumerated.item[0] > 1)
|
|
|
|
return -EINVAL;
|
|
|
|
mutex_lock(&umidi->mutex);
|
|
|
|
changed = value->value.enumerated.item[0] != kcontrol->private_value;
|
|
|
|
if (changed)
|
|
|
|
kcontrol->private_value = value->value.enumerated.item[0];
|
|
|
|
mutex_unlock(&umidi->mutex);
|
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct snd_kcontrol_new roland_load_ctl = {
|
|
|
|
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
|
|
|
|
.name = "MIDI Input Mode",
|
|
|
|
.info = roland_load_info,
|
|
|
|
.get = roland_load_get,
|
|
|
|
.put = roland_load_put,
|
|
|
|
.private_value = 1,
|
|
|
|
};
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* On Roland devices, use the second alternate setting to be able to use
|
|
|
|
* the interrupt input endpoint.
|
|
|
|
*/
|
2014-08-06 00:44:51 +08:00
|
|
|
static void snd_usbmidi_switch_roland_altsetting(struct snd_usb_midi *umidi)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2014-08-06 00:44:51 +08:00
|
|
|
struct usb_interface *intf;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct usb_host_interface *hostif;
|
2014-08-06 00:44:51 +08:00
|
|
|
struct usb_interface_descriptor *intfd;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
intf = umidi->iface;
|
|
|
|
if (!intf || intf->num_altsetting != 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
hostif = &intf->altsetting[1];
|
|
|
|
intfd = get_iface_desc(hostif);
|
2015-10-11 22:19:48 +08:00
|
|
|
/* If either or both of the endpoints support interrupt transfer,
|
|
|
|
* then use the alternate setting
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
if (intfd->bNumEndpoints != 2 ||
|
2015-10-11 22:19:48 +08:00
|
|
|
!((get_endpoint(hostif, 0)->bmAttributes &
|
|
|
|
USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT ||
|
|
|
|
(get_endpoint(hostif, 1)->bmAttributes &
|
|
|
|
USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT))
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
|
2014-02-26 20:02:17 +08:00
|
|
|
dev_dbg(&umidi->dev->dev, "switching to altsetting %d with int ep\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
intfd->bAlternateSetting);
|
2009-11-16 19:23:46 +08:00
|
|
|
usb_set_interface(umidi->dev, intfd->bInterfaceNumber,
|
2005-04-17 06:20:36 +08:00
|
|
|
intfd->bAlternateSetting);
|
2009-10-22 15:06:19 +08:00
|
|
|
|
|
|
|
umidi->roland_load_ctl = snd_ctl_new1(&roland_load_ctl, umidi);
|
2009-11-16 19:23:46 +08:00
|
|
|
if (snd_ctl_add(umidi->card, umidi->roland_load_ctl) < 0)
|
2009-10-22 15:06:19 +08:00
|
|
|
umidi->roland_load_ctl = NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to find any usable endpoints in the interface.
|
|
|
|
*/
|
2014-08-06 00:44:51 +08:00
|
|
|
static int snd_usbmidi_detect_endpoints(struct snd_usb_midi *umidi,
|
|
|
|
struct snd_usb_midi_endpoint_info *endpoint,
|
2005-04-17 06:20:36 +08:00
|
|
|
int max_endpoints)
|
|
|
|
{
|
2014-08-06 00:44:51 +08:00
|
|
|
struct usb_interface *intf;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct usb_host_interface *hostif;
|
2014-08-06 00:44:51 +08:00
|
|
|
struct usb_interface_descriptor *intfd;
|
|
|
|
struct usb_endpoint_descriptor *epd;
|
2005-04-17 06:20:36 +08:00
|
|
|
int i, out_eps = 0, in_eps = 0;
|
|
|
|
|
2009-11-16 19:23:46 +08:00
|
|
|
if (USB_ID_VENDOR(umidi->usb_id) == 0x0582)
|
2005-04-17 06:20:36 +08:00
|
|
|
snd_usbmidi_switch_roland_altsetting(umidi);
|
|
|
|
|
2005-03-30 22:22:01 +08:00
|
|
|
if (endpoint[0].out_ep || endpoint[0].in_ep)
|
2010-06-16 23:57:29 +08:00
|
|
|
return 0;
|
2005-03-30 22:22:01 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
intf = umidi->iface;
|
|
|
|
if (!intf || intf->num_altsetting < 1)
|
|
|
|
return -ENOENT;
|
|
|
|
hostif = intf->cur_altsetting;
|
|
|
|
intfd = get_iface_desc(hostif);
|
|
|
|
|
|
|
|
for (i = 0; i < intfd->bNumEndpoints; ++i) {
|
|
|
|
epd = get_endpoint(hostif, i);
|
2009-01-04 00:54:53 +08:00
|
|
|
if (!usb_endpoint_xfer_bulk(epd) &&
|
|
|
|
!usb_endpoint_xfer_int(epd))
|
2005-04-17 06:20:36 +08:00
|
|
|
continue;
|
|
|
|
if (out_eps < max_endpoints &&
|
2008-12-29 18:23:02 +08:00
|
|
|
usb_endpoint_dir_out(epd)) {
|
|
|
|
endpoint[out_eps].out_ep = usb_endpoint_num(epd);
|
|
|
|
if (usb_endpoint_xfer_int(epd))
|
2005-04-17 06:20:36 +08:00
|
|
|
endpoint[out_eps].out_interval = epd->bInterval;
|
|
|
|
++out_eps;
|
|
|
|
}
|
|
|
|
if (in_eps < max_endpoints &&
|
2008-12-29 18:23:02 +08:00
|
|
|
usb_endpoint_dir_in(epd)) {
|
|
|
|
endpoint[in_eps].in_ep = usb_endpoint_num(epd);
|
|
|
|
if (usb_endpoint_xfer_int(epd))
|
2005-04-17 06:20:36 +08:00
|
|
|
endpoint[in_eps].in_interval = epd->bInterval;
|
|
|
|
++in_eps;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (out_eps || in_eps) ? 0 : -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Detects the endpoints for one-port-per-endpoint protocols.
|
|
|
|
*/
|
2014-08-06 00:44:51 +08:00
|
|
|
static int snd_usbmidi_detect_per_port_endpoints(struct snd_usb_midi *umidi,
|
|
|
|
struct snd_usb_midi_endpoint_info *endpoints)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int err, i;
|
2010-06-16 23:57:29 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
err = snd_usbmidi_detect_endpoints(umidi, endpoints, MIDI_MAX_ENDPOINTS);
|
|
|
|
for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) {
|
|
|
|
if (endpoints[i].out_ep)
|
|
|
|
endpoints[i].out_cables = 0x0001;
|
|
|
|
if (endpoints[i].in_ep)
|
|
|
|
endpoints[i].in_cables = 0x0001;
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Detects the endpoints and ports of Yamaha devices.
|
|
|
|
*/
|
2014-08-06 00:44:51 +08:00
|
|
|
static int snd_usbmidi_detect_yamaha(struct snd_usb_midi *umidi,
|
|
|
|
struct snd_usb_midi_endpoint_info *endpoint)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2014-08-06 00:44:51 +08:00
|
|
|
struct usb_interface *intf;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct usb_host_interface *hostif;
|
2014-08-06 00:44:51 +08:00
|
|
|
struct usb_interface_descriptor *intfd;
|
|
|
|
uint8_t *cs_desc;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
intf = umidi->iface;
|
|
|
|
if (!intf)
|
|
|
|
return -ENOENT;
|
|
|
|
hostif = intf->altsetting;
|
|
|
|
intfd = get_iface_desc(hostif);
|
|
|
|
if (intfd->bNumEndpoints < 1)
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For each port there is one MIDI_IN/OUT_JACK descriptor, not
|
|
|
|
* necessarily with any useful contents. So simply count 'em.
|
|
|
|
*/
|
|
|
|
for (cs_desc = hostif->extra;
|
|
|
|
cs_desc < hostif->extra + hostif->extralen && cs_desc[0] >= 2;
|
|
|
|
cs_desc += cs_desc[0]) {
|
2006-06-19 23:20:09 +08:00
|
|
|
if (cs_desc[1] == USB_DT_CS_INTERFACE) {
|
2010-02-23 06:49:13 +08:00
|
|
|
if (cs_desc[2] == UAC_MIDI_IN_JACK)
|
2014-08-06 00:44:51 +08:00
|
|
|
endpoint->in_cables =
|
|
|
|
(endpoint->in_cables << 1) | 1;
|
2010-02-23 06:49:13 +08:00
|
|
|
else if (cs_desc[2] == UAC_MIDI_OUT_JACK)
|
2014-08-06 00:44:51 +08:00
|
|
|
endpoint->out_cables =
|
|
|
|
(endpoint->out_cables << 1) | 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!endpoint->in_cables && !endpoint->out_cables)
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
return snd_usbmidi_detect_endpoints(umidi, endpoint, 1);
|
|
|
|
}
|
|
|
|
|
2013-04-01 05:43:12 +08:00
|
|
|
/*
|
|
|
|
* Detects the endpoints and ports of Roland devices.
|
|
|
|
*/
|
2014-08-06 00:44:51 +08:00
|
|
|
static int snd_usbmidi_detect_roland(struct snd_usb_midi *umidi,
|
|
|
|
struct snd_usb_midi_endpoint_info *endpoint)
|
2013-04-01 05:43:12 +08:00
|
|
|
{
|
2014-08-06 00:44:51 +08:00
|
|
|
struct usb_interface *intf;
|
2013-04-01 05:43:12 +08:00
|
|
|
struct usb_host_interface *hostif;
|
2014-08-06 00:44:51 +08:00
|
|
|
u8 *cs_desc;
|
2013-04-01 05:43:12 +08:00
|
|
|
|
|
|
|
intf = umidi->iface;
|
|
|
|
if (!intf)
|
|
|
|
return -ENOENT;
|
|
|
|
hostif = intf->altsetting;
|
|
|
|
/*
|
|
|
|
* Some devices have a descriptor <06 24 F1 02 <inputs> <outputs>>,
|
|
|
|
* some have standard class descriptors, or both kinds, or neither.
|
|
|
|
*/
|
|
|
|
for (cs_desc = hostif->extra;
|
|
|
|
cs_desc < hostif->extra + hostif->extralen && cs_desc[0] >= 2;
|
|
|
|
cs_desc += cs_desc[0]) {
|
|
|
|
if (cs_desc[0] >= 6 &&
|
|
|
|
cs_desc[1] == USB_DT_CS_INTERFACE &&
|
|
|
|
cs_desc[2] == 0xf1 &&
|
|
|
|
cs_desc[3] == 0x02) {
|
|
|
|
endpoint->in_cables = (1 << cs_desc[4]) - 1;
|
|
|
|
endpoint->out_cables = (1 << cs_desc[5]) - 1;
|
|
|
|
return snd_usbmidi_detect_endpoints(umidi, endpoint, 1);
|
|
|
|
} else if (cs_desc[0] >= 7 &&
|
|
|
|
cs_desc[1] == USB_DT_CS_INTERFACE &&
|
|
|
|
cs_desc[2] == UAC_HEADER) {
|
|
|
|
return snd_usbmidi_get_ms_info(umidi, endpoint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Creates the endpoints and their ports for Midiman devices.
|
|
|
|
*/
|
2014-08-06 00:44:51 +08:00
|
|
|
static int snd_usbmidi_create_endpoints_midiman(struct snd_usb_midi *umidi,
|
|
|
|
struct snd_usb_midi_endpoint_info *endpoint)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 22:08:02 +08:00
|
|
|
struct snd_usb_midi_endpoint_info ep_info;
|
2014-08-06 00:44:51 +08:00
|
|
|
struct usb_interface *intf;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct usb_host_interface *hostif;
|
2014-08-06 00:44:51 +08:00
|
|
|
struct usb_interface_descriptor *intfd;
|
|
|
|
struct usb_endpoint_descriptor *epd;
|
2005-04-17 06:20:36 +08:00
|
|
|
int cable, err;
|
|
|
|
|
|
|
|
intf = umidi->iface;
|
|
|
|
if (!intf)
|
|
|
|
return -ENOENT;
|
|
|
|
hostif = intf->altsetting;
|
|
|
|
intfd = get_iface_desc(hostif);
|
|
|
|
/*
|
|
|
|
* The various MidiSport devices have more or less random endpoint
|
|
|
|
* numbers, so we have to identify the endpoints by their index in
|
|
|
|
* the descriptor array, like the driver for that other OS does.
|
|
|
|
*
|
|
|
|
* There is one interrupt input endpoint for all input ports, one
|
|
|
|
* bulk output endpoint for even-numbered ports, and one for odd-
|
|
|
|
* numbered ports. Both bulk output endpoints have corresponding
|
|
|
|
* input bulk endpoints (at indices 1 and 3) which aren't used.
|
|
|
|
*/
|
|
|
|
if (intfd->bNumEndpoints < (endpoint->out_cables > 0x0001 ? 5 : 3)) {
|
2014-02-26 20:02:17 +08:00
|
|
|
dev_dbg(&umidi->dev->dev, "not enough endpoints\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
epd = get_endpoint(hostif, 0);
|
2009-01-04 00:54:53 +08:00
|
|
|
if (!usb_endpoint_dir_in(epd) || !usb_endpoint_xfer_int(epd)) {
|
2014-02-26 20:02:17 +08:00
|
|
|
dev_dbg(&umidi->dev->dev, "endpoint[0] isn't interrupt\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
return -ENXIO;
|
|
|
|
}
|
|
|
|
epd = get_endpoint(hostif, 2);
|
2009-01-04 00:54:53 +08:00
|
|
|
if (!usb_endpoint_dir_out(epd) || !usb_endpoint_xfer_bulk(epd)) {
|
2014-02-26 20:02:17 +08:00
|
|
|
dev_dbg(&umidi->dev->dev, "endpoint[2] isn't bulk output\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
return -ENXIO;
|
|
|
|
}
|
|
|
|
if (endpoint->out_cables > 0x0001) {
|
|
|
|
epd = get_endpoint(hostif, 4);
|
2009-01-04 00:54:53 +08:00
|
|
|
if (!usb_endpoint_dir_out(epd) ||
|
|
|
|
!usb_endpoint_xfer_bulk(epd)) {
|
2014-08-06 00:44:51 +08:00
|
|
|
dev_dbg(&umidi->dev->dev,
|
|
|
|
"endpoint[4] isn't bulk output\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
return -ENXIO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-06 00:44:51 +08:00
|
|
|
ep_info.out_ep = get_endpoint(hostif, 2)->bEndpointAddress &
|
|
|
|
USB_ENDPOINT_NUMBER_MASK;
|
2009-02-16 22:22:39 +08:00
|
|
|
ep_info.out_interval = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
ep_info.out_cables = endpoint->out_cables & 0x5555;
|
2014-08-06 00:44:51 +08:00
|
|
|
err = snd_usbmidi_out_endpoint_create(umidi, &ep_info,
|
|
|
|
&umidi->endpoints[0]);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
2014-08-06 00:44:51 +08:00
|
|
|
ep_info.in_ep = get_endpoint(hostif, 0)->bEndpointAddress &
|
|
|
|
USB_ENDPOINT_NUMBER_MASK;
|
2005-04-17 06:20:36 +08:00
|
|
|
ep_info.in_interval = get_endpoint(hostif, 0)->bInterval;
|
|
|
|
ep_info.in_cables = endpoint->in_cables;
|
2014-08-06 00:44:51 +08:00
|
|
|
err = snd_usbmidi_in_endpoint_create(umidi, &ep_info,
|
|
|
|
&umidi->endpoints[0]);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
if (endpoint->out_cables > 0x0001) {
|
2014-08-06 00:44:51 +08:00
|
|
|
ep_info.out_ep = get_endpoint(hostif, 4)->bEndpointAddress &
|
|
|
|
USB_ENDPOINT_NUMBER_MASK;
|
2005-04-17 06:20:36 +08:00
|
|
|
ep_info.out_cables = endpoint->out_cables & 0xaaaa;
|
2014-08-06 00:44:51 +08:00
|
|
|
err = snd_usbmidi_out_endpoint_create(umidi, &ep_info,
|
|
|
|
&umidi->endpoints[1]);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (cable = 0; cable < 0x10; ++cable) {
|
|
|
|
if (endpoint->out_cables & (1 << cable))
|
2014-08-06 00:44:51 +08:00
|
|
|
snd_usbmidi_init_substream(umidi,
|
|
|
|
SNDRV_RAWMIDI_STREAM_OUTPUT,
|
|
|
|
cable,
|
2005-04-17 06:20:36 +08:00
|
|
|
&umidi->endpoints[cable & 1].out->ports[cable].substream);
|
|
|
|
if (endpoint->in_cables & (1 << cable))
|
2014-08-06 00:44:51 +08:00
|
|
|
snd_usbmidi_init_substream(umidi,
|
|
|
|
SNDRV_RAWMIDI_STREAM_INPUT,
|
|
|
|
cable,
|
2005-04-17 06:20:36 +08:00
|
|
|
&umidi->endpoints[0].in->ports[cable].substream);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-22 15:55:07 +08:00
|
|
|
static const struct snd_rawmidi_global_ops snd_usbmidi_ops = {
|
2006-05-02 22:22:12 +08:00
|
|
|
.get_port_info = snd_usbmidi_get_port_info,
|
|
|
|
};
|
|
|
|
|
2014-08-06 00:44:51 +08:00
|
|
|
static int snd_usbmidi_create_rawmidi(struct snd_usb_midi *umidi,
|
2005-04-17 06:20:36 +08:00
|
|
|
int out_ports, int in_ports)
|
|
|
|
{
|
2005-11-17 22:08:02 +08:00
|
|
|
struct snd_rawmidi *rmidi;
|
2005-04-17 06:20:36 +08:00
|
|
|
int err;
|
|
|
|
|
2009-11-16 19:23:46 +08:00
|
|
|
err = snd_rawmidi_new(umidi->card, "USB MIDI",
|
|
|
|
umidi->next_midi_device++,
|
2005-04-17 06:20:36 +08:00
|
|
|
out_ports, in_ports, &rmidi);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
2009-11-16 19:23:46 +08:00
|
|
|
strcpy(rmidi->name, umidi->card->shortname);
|
2005-04-17 06:20:36 +08:00
|
|
|
rmidi->info_flags = SNDRV_RAWMIDI_INFO_OUTPUT |
|
|
|
|
SNDRV_RAWMIDI_INFO_INPUT |
|
|
|
|
SNDRV_RAWMIDI_INFO_DUPLEX;
|
2006-05-02 22:22:12 +08:00
|
|
|
rmidi->ops = &snd_usbmidi_ops;
|
2005-04-17 06:20:36 +08:00
|
|
|
rmidi->private_data = umidi;
|
|
|
|
rmidi->private_free = snd_usbmidi_rawmidi_free;
|
2014-08-06 00:44:51 +08:00
|
|
|
snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT,
|
|
|
|
&snd_usbmidi_output_ops);
|
|
|
|
snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT,
|
|
|
|
&snd_usbmidi_input_ops);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
umidi->rmidi = rmidi;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Temporarily stop input.
|
|
|
|
*/
|
2014-08-06 00:44:51 +08:00
|
|
|
void snd_usbmidi_input_stop(struct list_head *p)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2014-08-06 00:44:51 +08:00
|
|
|
struct snd_usb_midi *umidi;
|
2009-07-13 19:40:36 +08:00
|
|
|
unsigned int i, j;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-11-17 22:08:02 +08:00
|
|
|
umidi = list_entry(p, struct snd_usb_midi, list);
|
2012-12-03 18:30:50 +08:00
|
|
|
if (!umidi->input_running)
|
|
|
|
return;
|
2005-04-17 06:20:36 +08:00
|
|
|
for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) {
|
2014-08-06 00:44:51 +08:00
|
|
|
struct snd_usb_midi_endpoint *ep = &umidi->endpoints[i];
|
2005-04-17 06:20:36 +08:00
|
|
|
if (ep->in)
|
2009-07-13 19:40:36 +08:00
|
|
|
for (j = 0; j < INPUT_URBS; ++j)
|
|
|
|
usb_kill_urb(ep->in->urbs[j]);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2012-12-03 18:30:50 +08:00
|
|
|
umidi->input_running = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2013-04-04 05:18:51 +08:00
|
|
|
EXPORT_SYMBOL(snd_usbmidi_input_stop);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-08-06 00:44:51 +08:00
|
|
|
static void snd_usbmidi_input_start_ep(struct snd_usb_midi_in_endpoint *ep)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-07-13 19:40:36 +08:00
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
if (!ep)
|
|
|
|
return;
|
|
|
|
for (i = 0; i < INPUT_URBS; ++i) {
|
2014-08-06 00:44:51 +08:00
|
|
|
struct urb *urb = ep->urbs[i];
|
2009-11-16 19:23:46 +08:00
|
|
|
urb->dev = ep->umidi->dev;
|
2005-04-17 06:20:36 +08:00
|
|
|
snd_usbmidi_submit_urb(urb, GFP_KERNEL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Resume input after a call to snd_usbmidi_input_stop().
|
|
|
|
*/
|
2014-08-06 00:44:51 +08:00
|
|
|
void snd_usbmidi_input_start(struct list_head *p)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2014-08-06 00:44:51 +08:00
|
|
|
struct snd_usb_midi *umidi;
|
2005-04-17 06:20:36 +08:00
|
|
|
int i;
|
|
|
|
|
2005-11-17 22:08:02 +08:00
|
|
|
umidi = list_entry(p, struct snd_usb_midi, list);
|
2012-12-03 18:30:50 +08:00
|
|
|
if (umidi->input_running || !umidi->opened[1])
|
|
|
|
return;
|
2005-04-17 06:20:36 +08:00
|
|
|
for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i)
|
|
|
|
snd_usbmidi_input_start_ep(umidi->endpoints[i].in);
|
2012-12-03 18:30:50 +08:00
|
|
|
umidi->input_running = 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2013-04-04 05:18:51 +08:00
|
|
|
EXPORT_SYMBOL(snd_usbmidi_input_start);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-08-06 00:44:50 +08:00
|
|
|
/*
|
|
|
|
* Prepare for suspend. Typically called from the USB suspend callback.
|
|
|
|
*/
|
|
|
|
void snd_usbmidi_suspend(struct list_head *p)
|
|
|
|
{
|
|
|
|
struct snd_usb_midi *umidi;
|
|
|
|
|
|
|
|
umidi = list_entry(p, struct snd_usb_midi, list);
|
|
|
|
mutex_lock(&umidi->mutex);
|
|
|
|
snd_usbmidi_input_stop(p);
|
|
|
|
mutex_unlock(&umidi->mutex);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(snd_usbmidi_suspend);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Resume. Typically called from the USB resume callback.
|
|
|
|
*/
|
|
|
|
void snd_usbmidi_resume(struct list_head *p)
|
|
|
|
{
|
|
|
|
struct snd_usb_midi *umidi;
|
|
|
|
|
|
|
|
umidi = list_entry(p, struct snd_usb_midi, list);
|
|
|
|
mutex_lock(&umidi->mutex);
|
|
|
|
snd_usbmidi_input_start(p);
|
|
|
|
mutex_unlock(&umidi->mutex);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(snd_usbmidi_resume);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Creates and registers everything needed for a MIDI streaming interface.
|
|
|
|
*/
|
2016-01-11 18:33:34 +08:00
|
|
|
int __snd_usbmidi_create(struct snd_card *card,
|
|
|
|
struct usb_interface *iface,
|
|
|
|
struct list_head *midi_list,
|
|
|
|
const struct snd_usb_audio_quirk *quirk,
|
|
|
|
unsigned int usb_id)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2014-08-06 00:44:51 +08:00
|
|
|
struct snd_usb_midi *umidi;
|
2005-11-17 22:08:02 +08:00
|
|
|
struct snd_usb_midi_endpoint_info endpoints[MIDI_MAX_ENDPOINTS];
|
2005-04-17 06:20:36 +08:00
|
|
|
int out_ports, in_ports;
|
|
|
|
int i, err;
|
|
|
|
|
[ALSA] Replace with kzalloc() - others
Documentation,SA11xx UDA1341 driver,Generic drivers,MPU401 UART,OPL3
OPL4,Digigram VX core,I2C cs8427,I2C lib core,I2C tea6330t,L3 drivers
AK4114 receiver,AK4117 receiver,PDAudioCF driver,PPC PMAC driver
SPARC AMD7930 driver,SPARC cs4231 driver,Synth,Common EMU synth
USB generic driver,USB USX2Y
Replace kcalloc(1,..) with kzalloc().
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2005-09-09 20:22:34 +08:00
|
|
|
umidi = kzalloc(sizeof(*umidi), GFP_KERNEL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!umidi)
|
|
|
|
return -ENOMEM;
|
2009-11-16 19:23:46 +08:00
|
|
|
umidi->dev = interface_to_usbdev(iface);
|
|
|
|
umidi->card = card;
|
2005-04-17 06:20:36 +08:00
|
|
|
umidi->iface = iface;
|
|
|
|
umidi->quirk = quirk;
|
|
|
|
umidi->usb_protocol_ops = &snd_usbmidi_standard_ops;
|
2008-02-23 01:34:44 +08:00
|
|
|
spin_lock_init(&umidi->disc_lock);
|
2012-12-03 18:12:46 +08:00
|
|
|
init_rwsem(&umidi->disc_rwsem);
|
2009-10-22 15:06:19 +08:00
|
|
|
mutex_init(&umidi->mutex);
|
2016-01-11 18:33:34 +08:00
|
|
|
if (!usb_id)
|
|
|
|
usb_id = USB_ID(le16_to_cpu(umidi->dev->descriptor.idVendor),
|
2009-11-16 19:23:46 +08:00
|
|
|
le16_to_cpu(umidi->dev->descriptor.idProduct));
|
2016-01-11 18:33:34 +08:00
|
|
|
umidi->usb_id = usb_id;
|
2015-01-19 18:43:50 +08:00
|
|
|
setup_timer(&umidi->error_timer, snd_usbmidi_error_timer,
|
|
|
|
(unsigned long)umidi);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* detect the endpoint(s) to use */
|
|
|
|
memset(endpoints, 0, sizeof(endpoints));
|
2005-09-14 14:36:03 +08:00
|
|
|
switch (quirk ? quirk->type : QUIRK_MIDI_STANDARD_INTERFACE) {
|
|
|
|
case QUIRK_MIDI_STANDARD_INTERFACE:
|
2005-04-17 06:20:36 +08:00
|
|
|
err = snd_usbmidi_get_ms_info(umidi, endpoints);
|
2009-11-16 19:23:46 +08:00
|
|
|
if (umidi->usb_id == USB_ID(0x0763, 0x0150)) /* M-Audio Uno */
|
2007-05-07 15:28:53 +08:00
|
|
|
umidi->usb_protocol_ops =
|
|
|
|
&snd_usbmidi_maudio_broken_running_status_ops;
|
2005-09-14 14:36:03 +08:00
|
|
|
break;
|
2008-07-30 21:13:29 +08:00
|
|
|
case QUIRK_MIDI_US122L:
|
|
|
|
umidi->usb_protocol_ops = &snd_usbmidi_122l_ops;
|
|
|
|
/* fall through */
|
2005-09-14 14:36:03 +08:00
|
|
|
case QUIRK_MIDI_FIXED_ENDPOINT:
|
|
|
|
memcpy(&endpoints[0], quirk->data,
|
2005-11-17 22:08:02 +08:00
|
|
|
sizeof(struct snd_usb_midi_endpoint_info));
|
2005-09-14 14:36:03 +08:00
|
|
|
err = snd_usbmidi_detect_endpoints(umidi, &endpoints[0], 1);
|
|
|
|
break;
|
|
|
|
case QUIRK_MIDI_YAMAHA:
|
|
|
|
err = snd_usbmidi_detect_yamaha(umidi, &endpoints[0]);
|
|
|
|
break;
|
2013-04-01 05:43:12 +08:00
|
|
|
case QUIRK_MIDI_ROLAND:
|
|
|
|
err = snd_usbmidi_detect_roland(umidi, &endpoints[0]);
|
|
|
|
break;
|
2005-09-14 14:36:03 +08:00
|
|
|
case QUIRK_MIDI_MIDIMAN:
|
|
|
|
umidi->usb_protocol_ops = &snd_usbmidi_midiman_ops;
|
|
|
|
memcpy(&endpoints[0], quirk->data,
|
2005-11-17 22:08:02 +08:00
|
|
|
sizeof(struct snd_usb_midi_endpoint_info));
|
2005-09-14 14:36:03 +08:00
|
|
|
err = 0;
|
|
|
|
break;
|
|
|
|
case QUIRK_MIDI_NOVATION:
|
|
|
|
umidi->usb_protocol_ops = &snd_usbmidi_novation_ops;
|
|
|
|
err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints);
|
|
|
|
break;
|
2010-10-23 00:20:48 +08:00
|
|
|
case QUIRK_MIDI_RAW_BYTES:
|
2005-09-14 14:36:03 +08:00
|
|
|
umidi->usb_protocol_ops = &snd_usbmidi_raw_ops;
|
2009-05-27 16:49:30 +08:00
|
|
|
/*
|
|
|
|
* Interface 1 contains isochronous endpoints, but with the same
|
|
|
|
* numbers as in interface 0. Since it is interface 1 that the
|
|
|
|
* USB core has most recently seen, these descriptors are now
|
|
|
|
* associated with the endpoint numbers. This will foul up our
|
|
|
|
* attempts to submit bulk/interrupt URBs to the endpoints in
|
|
|
|
* interface 0, so we have to make sure that the USB core looks
|
|
|
|
* again at interface 0 by calling usb_set_interface() on it.
|
|
|
|
*/
|
2010-10-23 00:20:48 +08:00
|
|
|
if (umidi->usb_id == USB_ID(0x07fd, 0x0001)) /* MOTU Fastlane */
|
|
|
|
usb_set_interface(umidi->dev, 0, 0);
|
2005-09-14 14:36:03 +08:00
|
|
|
err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints);
|
|
|
|
break;
|
|
|
|
case QUIRK_MIDI_EMAGIC:
|
|
|
|
umidi->usb_protocol_ops = &snd_usbmidi_emagic_ops;
|
|
|
|
memcpy(&endpoints[0], quirk->data,
|
2005-11-17 22:08:02 +08:00
|
|
|
sizeof(struct snd_usb_midi_endpoint_info));
|
2005-09-14 14:36:03 +08:00
|
|
|
err = snd_usbmidi_detect_endpoints(umidi, &endpoints[0], 1);
|
|
|
|
break;
|
2006-02-08 00:11:06 +08:00
|
|
|
case QUIRK_MIDI_CME:
|
2007-08-16 14:44:51 +08:00
|
|
|
umidi->usb_protocol_ops = &snd_usbmidi_cme_ops;
|
2005-09-14 14:36:03 +08:00
|
|
|
err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints);
|
|
|
|
break;
|
2010-05-21 03:31:10 +08:00
|
|
|
case QUIRK_MIDI_AKAI:
|
|
|
|
umidi->usb_protocol_ops = &snd_usbmidi_akai_ops;
|
|
|
|
err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints);
|
|
|
|
/* endpoint 1 is input-only */
|
|
|
|
endpoints[1].out_cables = 0;
|
|
|
|
break;
|
2011-08-26 19:19:49 +08:00
|
|
|
case QUIRK_MIDI_FTDI:
|
|
|
|
umidi->usb_protocol_ops = &snd_usbmidi_ftdi_ops;
|
|
|
|
|
|
|
|
/* set baud rate to 31250 (48 MHz / 16 / 96) */
|
|
|
|
err = usb_control_msg(umidi->dev, usb_sndctrlpipe(umidi->dev, 0),
|
|
|
|
3, 0x40, 0x60, 0, NULL, 0, 1000);
|
|
|
|
if (err < 0)
|
|
|
|
break;
|
|
|
|
|
2015-11-16 05:38:29 +08:00
|
|
|
err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints);
|
|
|
|
break;
|
|
|
|
case QUIRK_MIDI_CH345:
|
2015-11-16 05:39:08 +08:00
|
|
|
umidi->usb_protocol_ops = &snd_usbmidi_ch345_broken_sysex_ops;
|
2011-08-26 19:19:49 +08:00
|
|
|
err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints);
|
|
|
|
break;
|
2005-09-14 14:36:03 +08:00
|
|
|
default:
|
2014-08-06 00:44:51 +08:00
|
|
|
dev_err(&umidi->dev->dev, "invalid quirk type %d\n",
|
|
|
|
quirk->type);
|
2005-09-14 14:36:03 +08:00
|
|
|
err = -ENXIO;
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
if (err < 0) {
|
|
|
|
kfree(umidi);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create rawmidi device */
|
|
|
|
out_ports = 0;
|
|
|
|
in_ports = 0;
|
|
|
|
for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) {
|
2009-11-20 13:56:52 +08:00
|
|
|
out_ports += hweight16(endpoints[i].out_cables);
|
|
|
|
in_ports += hweight16(endpoints[i].in_cables);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
err = snd_usbmidi_create_rawmidi(umidi, out_ports, in_ports);
|
|
|
|
if (err < 0) {
|
|
|
|
kfree(umidi);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create endpoint/port structures */
|
|
|
|
if (quirk && quirk->type == QUIRK_MIDI_MIDIMAN)
|
|
|
|
err = snd_usbmidi_create_endpoints_midiman(umidi, &endpoints[0]);
|
|
|
|
else
|
|
|
|
err = snd_usbmidi_create_endpoints(umidi, endpoints);
|
|
|
|
if (err < 0) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2013-04-15 21:59:51 +08:00
|
|
|
usb_autopm_get_interface_no_resume(umidi->iface);
|
|
|
|
|
2009-11-16 19:23:46 +08:00
|
|
|
list_add_tail(&umidi->list, midi_list);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2016-01-11 18:33:34 +08:00
|
|
|
EXPORT_SYMBOL(__snd_usbmidi_create);
|