[ALSA] sound/usb/usbaudio.c: fix build with CONFIG_PM=n
[safe/jmp/linux-2.6] / sound / usb / usbmidi.c
index 7f7e371..6330788 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * usbmidi.c - ALSA USB MIDI driver
  *
- * Copyright (c) 2002-2005 Clemens Ladisch
+ * Copyright (c) 2002-2007 Clemens Ladisch
  * All rights reserved.
  *
  * Based on the OSS usb-midi driver by NAGANO Daisuke,
@@ -48,6 +48,7 @@
 #include <linux/usb.h>
 #include <sound/core.h>
 #include <sound/rawmidi.h>
+#include <sound/asequencer.h>
 #include "usbaudio.h"
 
 
@@ -144,6 +145,7 @@ struct snd_usb_midi_in_endpoint {
        struct urb* urb;
        struct usbmidi_in_port {
                struct snd_rawmidi_substream *substream;
+               u8 running_status_length;
        } ports[0x10];
        u8 seen_f5;
        u8 error_resubmit;
@@ -180,9 +182,9 @@ static int snd_usbmidi_urb_error(int status)
        case -ENODEV:
                return -ENODEV;
        /* errors that might occur during unplugging */
-       case -EPROTO:    /* EHCI */
-       case -ETIMEDOUT: /* OHCI */
-       case -EILSEQ:    /* UHCI */
+       case -EPROTO:
+       case -ETIME:
+       case -EILSEQ:
                return -EIO;
        default:
                snd_printk(KERN_ERR "urb status %d\n", status);
@@ -222,7 +224,7 @@ static void dump_urb(const char *type, const u8 *data, int length)
 /*
  * Processes the data read from the device.
  */
-static void snd_usbmidi_in_urb_complete(struct urb* urb, struct pt_regs *regs)
+static void snd_usbmidi_in_urb_complete(struct urb* urb)
 {
        struct snd_usb_midi_in_endpoint* ep = urb->context;
 
@@ -246,7 +248,7 @@ static void snd_usbmidi_in_urb_complete(struct urb* urb, struct pt_regs *regs)
        snd_usbmidi_submit_urb(urb, GFP_ATOMIC);
 }
 
-static void snd_usbmidi_out_urb_complete(struct urb* urb, struct pt_regs *regs)
+static void snd_usbmidi_out_urb_complete(struct urb* urb)
 {
        struct snd_usb_midi_out_endpoint* ep = urb->context;
 
@@ -322,10 +324,9 @@ static int send_bulk_static_data(struct snd_usb_midi_out_endpoint* ep,
                                 const void *data, int len)
 {
        int err;
-       void *buf = kmalloc(len, GFP_KERNEL);
+       void *buf = kmemdup(data, len, GFP_KERNEL);
        if (!buf)
                return -ENOMEM;
-       memcpy(buf, data, len);
        dump_urb("sending", buf, len);
        err = usb_bulk_msg(ep->umidi->chip->dev, ep->urb->pipe, buf, len,
                           NULL, 250);
@@ -366,6 +367,60 @@ static void snd_usbmidi_midiman_input(struct snd_usb_midi_in_endpoint* ep,
 }
 
 /*
+ * 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(
+                                       struct snd_usb_midi_in_endpoint* ep,
+                                       uint8_t* buffer, int buffer_length)
+{
+       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;
+                       
+                       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;
+                       snd_usbmidi_input_data(ep, cable, &buffer[i + 1], length);
+               }
+}
+
+/*
+ * 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);
+}
+
+/*
  * Adds one USB MIDI packet to the output buffer.
  */
 static void snd_usbmidi_output_standard_packet(struct urb* urb, uint8_t p0,
@@ -525,6 +580,18 @@ static struct usb_protocol_ops snd_usbmidi_midiman_ops = {
        .output_packet = snd_usbmidi_output_midiman_packet,
 };
 
+static struct usb_protocol_ops snd_usbmidi_maudio_broken_running_status_ops = {
+       .input = snd_usbmidi_maudio_broken_running_status_input,
+       .output = snd_usbmidi_standard_output, 
+       .output_packet = snd_usbmidi_output_standard_packet,
+};
+
+static struct usb_protocol_ops snd_usbmidi_cme_ops = {
+       .input = snd_usbmidi_cme_input,
+       .output = snd_usbmidi_standard_output,
+       .output_packet = snd_usbmidi_output_standard_packet,
+};
+
 /*
  * 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
@@ -871,10 +938,10 @@ static int snd_usbmidi_in_endpoint_create(struct snd_usb_midi* umidi,
 
 static unsigned int snd_usbmidi_count_bits(unsigned int x)
 {
-       unsigned int bits = 0;
+       unsigned int bits;
 
-       for (; x; x >>= 1)
-               bits += x & 1;
+       for (bits = 0; x; ++bits)
+               x &= x - 1;
        return bits;
 }
 
@@ -916,17 +983,29 @@ static int snd_usbmidi_out_endpoint_create(struct snd_usb_midi* umidi,
                snd_usbmidi_out_endpoint_delete(ep);
                return -ENOMEM;
        }
-       /* we never use interrupt output pipes */
-       pipe = usb_sndbulkpipe(umidi->chip->dev, ep_info->out_ep);
-       ep->max_transfer = usb_maxpacket(umidi->chip->dev, pipe, 1);
+       if (ep_info->out_interval)
+               pipe = usb_sndintpipe(umidi->chip->dev, ep_info->out_ep);
+       else
+               pipe = usb_sndbulkpipe(umidi->chip->dev, ep_info->out_ep);
+       if (umidi->chip->usb_id == USB_ID(0x0a92, 0x1020)) /* ESI M4U */
+               /* FIXME: we need more URBs to get reasonable bandwidth here: */
+               ep->max_transfer = 4;
+       else
+               ep->max_transfer = usb_maxpacket(umidi->chip->dev, pipe, 1);
        buffer = usb_buffer_alloc(umidi->chip->dev, ep->max_transfer,
                                  GFP_KERNEL, &ep->urb->transfer_dma);
        if (!buffer) {
                snd_usbmidi_out_endpoint_delete(ep);
                return -ENOMEM;
        }
-       usb_fill_bulk_urb(ep->urb, umidi->chip->dev, pipe, buffer,
-                         ep->max_transfer, snd_usbmidi_out_urb_complete, ep);
+       if (ep_info->out_interval)
+               usb_fill_int_urb(ep->urb, umidi->chip->dev, pipe, buffer,
+                                ep->max_transfer, snd_usbmidi_out_urb_complete,
+                                ep, ep_info->out_interval);
+       else
+               usb_fill_bulk_urb(ep->urb, umidi->chip->dev,
+                                 pipe, buffer, ep->max_transfer,
+                                 snd_usbmidi_out_urb_complete, ep);
        ep->urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
 
        spin_lock_init(&ep->buffer_lock);
@@ -981,7 +1060,7 @@ void snd_usbmidi_disconnect(struct list_head* p)
                        if (umidi->usb_protocol_ops->finish_out_endpoint)
                                umidi->usb_protocol_ops->finish_out_endpoint(ep->out);
                }
-               if (ep->in && ep->in->urb)
+               if (ep->in)
                        usb_kill_urb(ep->in->urb);
        }
 }
@@ -1010,97 +1089,157 @@ static struct snd_rawmidi_substream *snd_usbmidi_find_substream(struct snd_usb_m
  * "(product) MIDI (n)" schema because they aren't external MIDI ports,
  * such as internal control or synthesizer ports.
  */
-static struct {
+static struct port_info {
        u32 id;
-       int port;
-       const char *name_format;
-} snd_usbmidi_port_names[] = {
+       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)
+#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)
        /* Roland UA-100 */
-       { USB_ID(0x0582, 0x0000), 2, "%s Control" },
+       CONTROL_PORT(0x0582, 0x0000, 2, "%s Control"),
        /* Roland SC-8850 */
-       { USB_ID(0x0582, 0x0003), 0, "%s Part A" },
-       { USB_ID(0x0582, 0x0003), 1, "%s Part B" },
-       { USB_ID(0x0582, 0x0003), 2, "%s Part C" },
-       { USB_ID(0x0582, 0x0003), 3, "%s Part D" },
-       { USB_ID(0x0582, 0x0003), 4, "%s MIDI 1" },
-       { USB_ID(0x0582, 0x0003), 5, "%s MIDI 2" },
+       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"),
        /* Roland U-8 */
-       { USB_ID(0x0582, 0x0004), 0, "%s MIDI" },
-       { USB_ID(0x0582, 0x0004), 1, "%s Control" },
+       EXTERNAL_PORT(0x0582, 0x0004, 0, "%s MIDI"),
+       CONTROL_PORT(0x0582, 0x0004, 1, "%s Control"),
        /* Roland SC-8820 */
-       { USB_ID(0x0582, 0x0007), 0, "%s Part A" },
-       { USB_ID(0x0582, 0x0007), 1, "%s Part B" },
-       { USB_ID(0x0582, 0x0007), 2, "%s MIDI" },
+       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"),
        /* Roland SK-500 */
-       { USB_ID(0x0582, 0x000b), 0, "%s Part A" },
-       { USB_ID(0x0582, 0x000b), 1, "%s Part B" },
-       { USB_ID(0x0582, 0x000b), 2, "%s MIDI" },
+       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"),
        /* Roland SC-D70 */
-       { USB_ID(0x0582, 0x000c), 0, "%s Part A" },
-       { USB_ID(0x0582, 0x000c), 1, "%s Part B" },
-       { USB_ID(0x0582, 0x000c), 2, "%s MIDI" },
+       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"),
        /* Edirol UM-880 */
-       { USB_ID(0x0582, 0x0014), 8, "%s Control" },
+       CONTROL_PORT(0x0582, 0x0014, 8, "%s Control"),
        /* Edirol SD-90 */
-       { USB_ID(0x0582, 0x0016), 0, "%s Part A" },
-       { USB_ID(0x0582, 0x0016), 1, "%s Part B" },
-       { USB_ID(0x0582, 0x0016), 2, "%s MIDI 1" },
-       { USB_ID(0x0582, 0x0016), 3, "%s MIDI 2" },
+       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"),
        /* Edirol UM-550 */
-       { USB_ID(0x0582, 0x0023), 5, "%s Control" },
+       CONTROL_PORT(0x0582, 0x0023, 5, "%s Control"),
        /* Edirol SD-20 */
-       { USB_ID(0x0582, 0x0027), 0, "%s Part A" },
-       { USB_ID(0x0582, 0x0027), 1, "%s Part B" },
-       { USB_ID(0x0582, 0x0027), 2, "%s MIDI" },
+       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"),
        /* Edirol SD-80 */
-       { USB_ID(0x0582, 0x0029), 0, "%s Part A" },
-       { USB_ID(0x0582, 0x0029), 1, "%s Part B" },
-       { USB_ID(0x0582, 0x0029), 2, "%s MIDI 1" },
-       { USB_ID(0x0582, 0x0029), 3, "%s MIDI 2" },
+       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"),
        /* Edirol UA-700 */
-       { USB_ID(0x0582, 0x002b), 0, "%s MIDI" },
-       { USB_ID(0x0582, 0x002b), 1, "%s Control" },
+       EXTERNAL_PORT(0x0582, 0x002b, 0, "%s MIDI"),
+       CONTROL_PORT(0x0582, 0x002b, 1, "%s Control"),
        /* Roland VariOS */
-       { USB_ID(0x0582, 0x002f), 0, "%s MIDI" },
-       { USB_ID(0x0582, 0x002f), 1, "%s External MIDI" },
-       { USB_ID(0x0582, 0x002f), 2, "%s Sync" },
+       EXTERNAL_PORT(0x0582, 0x002f, 0, "%s MIDI"),
+       EXTERNAL_PORT(0x0582, 0x002f, 1, "%s External MIDI"),
+       EXTERNAL_PORT(0x0582, 0x002f, 2, "%s Sync"),
        /* Edirol PCR */
-       { USB_ID(0x0582, 0x0033), 0, "%s MIDI" },
-       { USB_ID(0x0582, 0x0033), 1, "%s 1" },
-       { USB_ID(0x0582, 0x0033), 2, "%s 2" },
+       EXTERNAL_PORT(0x0582, 0x0033, 0, "%s MIDI"),
+       EXTERNAL_PORT(0x0582, 0x0033, 1, "%s 1"),
+       EXTERNAL_PORT(0x0582, 0x0033, 2, "%s 2"),
        /* BOSS GS-10 */
-       { USB_ID(0x0582, 0x003b), 0, "%s MIDI" },
-       { USB_ID(0x0582, 0x003b), 1, "%s Control" },
+       EXTERNAL_PORT(0x0582, 0x003b, 0, "%s MIDI"),
+       CONTROL_PORT(0x0582, 0x003b, 1, "%s Control"),
        /* Edirol UA-1000 */
-       { USB_ID(0x0582, 0x0044), 0, "%s MIDI" },
-       { USB_ID(0x0582, 0x0044), 1, "%s Control" },
+       EXTERNAL_PORT(0x0582, 0x0044, 0, "%s MIDI"),
+       CONTROL_PORT(0x0582, 0x0044, 1, "%s Control"),
        /* Edirol UR-80 */
-       { USB_ID(0x0582, 0x0048), 0, "%s MIDI" },
-       { USB_ID(0x0582, 0x0048), 1, "%s 1" },
-       { USB_ID(0x0582, 0x0048), 2, "%s 2" },
+       EXTERNAL_PORT(0x0582, 0x0048, 0, "%s MIDI"),
+       EXTERNAL_PORT(0x0582, 0x0048, 1, "%s 1"),
+       EXTERNAL_PORT(0x0582, 0x0048, 2, "%s 2"),
        /* Edirol PCR-A */
-       { USB_ID(0x0582, 0x004d), 0, "%s MIDI" },
-       { USB_ID(0x0582, 0x004d), 1, "%s 1" },
-       { USB_ID(0x0582, 0x004d), 2, "%s 2" },
+       EXTERNAL_PORT(0x0582, 0x004d, 0, "%s MIDI"),
+       EXTERNAL_PORT(0x0582, 0x004d, 1, "%s 1"),
+       EXTERNAL_PORT(0x0582, 0x004d, 2, "%s 2"),
        /* Edirol UM-3EX */
-       { USB_ID(0x0582, 0x009a), 3, "%s Control" },
+       CONTROL_PORT(0x0582, 0x009a, 3, "%s Control"),
        /* M-Audio MidiSport 8x8 */
-       { USB_ID(0x0763, 0x1031), 8, "%s Control" },
-       { USB_ID(0x0763, 0x1033), 8, "%s Control" },
+       CONTROL_PORT(0x0763, 0x1031, 8, "%s Control"),
+       CONTROL_PORT(0x0763, 0x1033, 8, "%s Control"),
        /* MOTU Fastlane */
-       { USB_ID(0x07fd, 0x0001), 0, "%s MIDI A" },
-       { USB_ID(0x07fd, 0x0001), 1, "%s MIDI B" },
+       EXTERNAL_PORT(0x07fd, 0x0001, 0, "%s MIDI A"),
+       EXTERNAL_PORT(0x07fd, 0x0001, 1, "%s MIDI B"),
        /* Emagic Unitor8/AMT8/MT4 */
-       { USB_ID(0x086a, 0x0001), 8, "%s Broadcast" },
-       { USB_ID(0x086a, 0x0002), 8, "%s Broadcast" },
-       { USB_ID(0x086a, 0x0003), 4, "%s Broadcast" },
+       EXTERNAL_PORT(0x086a, 0x0001, 8, "%s Broadcast"),
+       EXTERNAL_PORT(0x086a, 0x0002, 8, "%s Broadcast"),
+       EXTERNAL_PORT(0x086a, 0x0003, 4, "%s Broadcast"),
 };
 
+static struct port_info *find_port_info(struct snd_usb_midi* umidi, int number)
+{
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(snd_usbmidi_port_info); ++i) {
+               if (snd_usbmidi_port_info[i].id == umidi->chip->usb_id &&
+                   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;
+       }
+}
+
 static void snd_usbmidi_init_substream(struct snd_usb_midi* umidi,
                                       int stream, int number,
                                       struct snd_rawmidi_substream ** rsubstream)
 {
-       int i;
+       struct port_info *port_info;
        const char *name_format;
 
        struct snd_rawmidi_substream *substream = snd_usbmidi_find_substream(umidi, stream, number);
@@ -1110,14 +1249,8 @@ static void snd_usbmidi_init_substream(struct snd_usb_midi* umidi,
        }
 
        /* TODO: read port name from jack descriptor */
-       name_format = "%s MIDI %d";
-       for (i = 0; i < ARRAY_SIZE(snd_usbmidi_port_names); ++i) {
-               if (snd_usbmidi_port_names[i].id == umidi->chip->usb_id &&
-                   snd_usbmidi_port_names[i].port == number) {
-                       name_format = snd_usbmidi_port_names[i].name_format;
-                       break;
-               }
-       }
+       port_info = find_port_info(umidi, number);
+       name_format = port_info ? port_info->name : "%s MIDI %d";
        snprintf(substream->name, sizeof(substream->name),
                 name_format, umidi->chip->card->shortname, number + 1);
 
@@ -1218,6 +1351,13 @@ static int snd_usbmidi_get_ms_info(struct snd_usb_midi* umidi,
                        endpoints[epidx].out_ep = ep->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
                        if ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT)
                                endpoints[epidx].out_interval = ep->bInterval;
+                       else if (snd_usb_get_speed(umidi->chip->dev) == USB_SPEED_LOW)
+                               /*
+                                * 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;
                        endpoints[epidx].out_cables = (1 << ms_ep->bNumEmbMIDIJack) - 1;
                        snd_printdd(KERN_INFO "EP %02X: %d jack(s)\n",
                                    ep->bEndpointAddress, ms_ep->bNumEmbMIDIJack);
@@ -1231,6 +1371,8 @@ static int snd_usbmidi_get_ms_info(struct snd_usb_midi* umidi,
                        endpoints[epidx].in_ep = ep->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
                        if ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT)
                                endpoints[epidx].in_interval = ep->bInterval;
+                       else if (snd_usb_get_speed(umidi->chip->dev) == USB_SPEED_LOW)
+                               endpoints[epidx].in_interval = 1;
                        endpoints[epidx].in_cables = (1 << ms_ep->bNumEmbMIDIJack) - 1;
                        snd_printdd(KERN_INFO "EP %02X: %d jack(s)\n",
                                    ep->bEndpointAddress, ms_ep->bNumEmbMIDIJack);
@@ -1358,7 +1500,7 @@ static int snd_usbmidi_detect_yamaha(struct snd_usb_midi* umidi,
        for (cs_desc = hostif->extra;
             cs_desc < hostif->extra + hostif->extralen && cs_desc[0] >= 2;
             cs_desc += cs_desc[0]) {
-               if (cs_desc[1] == CS_AUDIO_INTERFACE) {
+               if (cs_desc[1] == USB_DT_CS_INTERFACE) {
                        if (cs_desc[2] == MIDI_IN_JACK)
                                endpoint->in_cables = (endpoint->in_cables << 1) | 1;
                        else if (cs_desc[2] == MIDI_OUT_JACK)
@@ -1457,6 +1599,10 @@ static int snd_usbmidi_create_endpoints_midiman(struct snd_usb_midi* umidi,
        return 0;
 }
 
+static struct snd_rawmidi_global_ops snd_usbmidi_ops = {
+       .get_port_info = snd_usbmidi_get_port_info,
+};
+
 static int snd_usbmidi_create_rawmidi(struct snd_usb_midi* umidi,
                                      int out_ports, int in_ports)
 {
@@ -1472,6 +1618,7 @@ static int snd_usbmidi_create_rawmidi(struct snd_usb_midi* umidi,
        rmidi->info_flags = SNDRV_RAWMIDI_INFO_OUTPUT |
                            SNDRV_RAWMIDI_INFO_INPUT |
                            SNDRV_RAWMIDI_INFO_DUPLEX;
+       rmidi->ops = &snd_usbmidi_ops;
        rmidi->private_data = umidi;
        rmidi->private_free = snd_usbmidi_rawmidi_free;
        snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_usbmidi_output_ops);
@@ -1547,6 +1694,9 @@ int snd_usb_create_midi_interface(struct snd_usb_audio* chip,
        switch (quirk ? quirk->type : QUIRK_MIDI_STANDARD_INTERFACE) {
        case QUIRK_MIDI_STANDARD_INTERFACE:
                err = snd_usbmidi_get_ms_info(umidi, endpoints);
+               if (chip->usb_id == USB_ID(0x0763, 0x0150)) /* M-Audio Uno */
+                       umidi->usb_protocol_ops =
+                               &snd_usbmidi_maudio_broken_running_status_ops;
                break;
        case QUIRK_MIDI_FIXED_ENDPOINT:
                memcpy(&endpoints[0], quirk->data,
@@ -1576,7 +1726,8 @@ int snd_usb_create_midi_interface(struct snd_usb_audio* chip,
                       sizeof(struct snd_usb_midi_endpoint_info));
                err = snd_usbmidi_detect_endpoints(umidi, &endpoints[0], 1);
                break;
-       case QUIRK_MIDI_MIDITECH:
+       case QUIRK_MIDI_CME:
+               umidi->usb_protocol_ops = &snd_usbmidi_cme_ops;
                err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints);
                break;
        default: