38 #include <linux/kernel.h>
39 #include <linux/types.h>
40 #include <linux/bitops.h>
43 #include <linux/string.h>
45 #include <linux/slab.h>
48 #include <linux/wait.h>
49 #include <linux/usb/audio.h>
50 #include <linux/module.h>
70 #define ERROR_DELAY_JIFFIES (HZ / 10)
99 struct snd_usb_midi_endpoint;
154 #define STATE_UNKNOWN 0
155 #define STATE_1PARAM 1
156 #define STATE_2PARAM_1 2
157 #define STATE_2PARAM_2 3
158 #define STATE_SYSEX_0 4
159 #define STATE_SYSEX_1 5
160 #define STATE_SYSEX_2 6
182 static const uint8_t snd_usbmidi_cin_length[] = {
183 0, 0, 2, 3, 3, 1, 2, 3, 3, 3, 3, 3, 2, 2, 3, 1
192 if (err < 0 && err != -
ENODEV)
200 static int snd_usbmidi_urb_error(
int status)
226 struct usbmidi_in_port*
port = &ep->
ports[portidx];
228 if (!port->substream) {
232 if (!
test_bit(port->substream->number, &ep->
umidi->input_triggered))
238 static void dump_urb(
const char *
type,
const u8 *data,
int length)
246 #define dump_urb(type, data, length)
252 static void snd_usbmidi_in_urb_complete(
struct urb* urb)
256 if (urb->status == 0) {
257 dump_urb(
"received", urb->transfer_buffer, urb->actual_length);
258 ep->
umidi->usb_protocol_ops->input(ep, urb->transfer_buffer,
261 int err = snd_usbmidi_urb_error(urb->status);
272 urb->dev = ep->
umidi->dev;
276 static void snd_usbmidi_out_urb_complete(
struct urb* urb)
278 struct out_urb_context *
context = urb->context;
280 unsigned int urb_index;
283 urb_index = context - ep->
urbs;
290 if (urb->status < 0) {
291 int err = snd_usbmidi_urb_error(urb->status);
299 snd_usbmidi_do_output(ep);
308 unsigned int urb_index;
313 if (ep->
umidi->disconnected) {
321 urb = ep->
urbs[urb_index].urb;
322 urb->transfer_buffer_length = 0;
323 ep->
umidi->usb_protocol_ops->output(ep, urb);
324 if (urb->transfer_buffer_length == 0)
327 dump_urb(
"sending", urb->transfer_buffer,
328 urb->transfer_buffer_length);
329 urb->dev = ep->
umidi->dev;
330 if (snd_usbmidi_submit_urb(urb,
GFP_ATOMIC) < 0)
343 static void snd_usbmidi_out_tasklet(
unsigned long data)
347 snd_usbmidi_do_output(ep);
351 static void snd_usbmidi_error_timer(
unsigned long data)
371 snd_usbmidi_do_output(umidi->
endpoints[i].out);
378 const void *data,
int len)
387 buf, len,
NULL, 250);
404 if (buffer[i] != 0) {
405 int cable = buffer[
i] >> 4;
406 int length = snd_usbmidi_cin_length[buffer[
i] & 0x0f];
407 snd_usbmidi_input_data(ep, cable, &buffer[i + 1], length);
412 uint8_t* buffer,
int buffer_length)
417 if (buffer[i + 3] != 0) {
418 int port = buffer[i + 3] >> 4;
419 int length = buffer[i + 3] & 3;
420 snd_usbmidi_input_data(ep, port, &buffer[i], length);
428 static void snd_usbmidi_maudio_broken_running_status_input(
430 uint8_t* buffer,
int buffer_length)
435 if (buffer[i] != 0) {
436 int cable = buffer[
i] >> 4;
437 u8 cin = buffer[
i] & 0x0f;
438 struct usbmidi_in_port *port = &ep->
ports[cable];
441 length = snd_usbmidi_cin_length[cin];
442 if (cin == 0xf && buffer[i + 1] >= 0xf8)
444 else if (cin >= 0x8 && cin <= 0
xe)
446 port->running_status_length = length - 1;
447 else if (cin == 0x4 &&
448 port->running_status_length != 0 &&
449 buffer[i + 1] < 0x80)
451 length = port->running_status_length;
459 port->running_status_length = 0;
460 snd_usbmidi_input_data(ep, cable, &buffer[i + 1], length);
469 uint8_t *buffer,
int buffer_length)
471 if (buffer_length < 2 || (buffer[0] & 0x0f) != 0x0f)
472 snd_usbmidi_standard_input(ep, buffer, buffer_length);
474 snd_usbmidi_input_data(ep, buffer[0] >> 4,
475 &buffer[1], buffer_length - 1);
481 static void snd_usbmidi_output_standard_packet(
struct urb* urb,
uint8_t p0,
485 uint8_t* buf = (
uint8_t*)urb->transfer_buffer + urb->transfer_buffer_length;
490 urb->transfer_buffer_length += 4;
496 static void snd_usbmidi_output_midiman_packet(
struct urb* urb,
uint8_t p0,
500 uint8_t* buf = (
uint8_t*)urb->transfer_buffer + urb->transfer_buffer_length;
504 buf[3] = (p0 & 0xf0) | snd_usbmidi_cin_length[p0 & 0x0f];
505 urb->transfer_buffer_length += 4;
511 static void snd_usbmidi_transmit_byte(
struct usbmidi_out_port* port,
516 port->ep->umidi->usb_protocol_ops->output_packet;
519 output_packet(urb, p0 | 0x0f, b, 0, 0);
520 }
else if (b >= 0xf0) {
540 output_packet(urb, p0 | 0x05, 0xf6, 0, 0);
544 switch (port->state) {
546 output_packet(urb, p0 | 0x05, 0xf7, 0, 0);
549 output_packet(urb, p0 | 0x06, port->data[0], 0xf7, 0);
552 output_packet(urb, p0 | 0x07, port->data[0], port->data[1], 0xf7);
558 }
else if (b >= 0x80) {
560 if (b >= 0xc0 && b <= 0xdf)
565 switch (port->state) {
567 if (port->data[0] < 0xf0) {
568 p0 |= port->data[0] >> 4;
573 output_packet(urb, p0, port->data[0], b, 0);
580 if (port->data[0] < 0xf0) {
581 p0 |= port->data[0] >> 4;
587 output_packet(urb, p0, port->data[0], port->data[1], b);
598 output_packet(urb, p0 | 0x04, port->data[0], port->data[1], b);
611 for (p = 0; p < 0x10; ++
p) {
612 struct usbmidi_out_port* port = &ep->
ports[
p];
615 while (urb->transfer_buffer_length + 3 < ep->
max_transfer) {
621 snd_usbmidi_transmit_byte(port, b, urb);
627 .input = snd_usbmidi_standard_input,
628 .output = snd_usbmidi_standard_output,
629 .output_packet = snd_usbmidi_output_standard_packet,
633 .input = snd_usbmidi_midiman_input,
634 .output = snd_usbmidi_standard_output,
635 .output_packet = snd_usbmidi_output_midiman_packet,
638 static struct usb_protocol_ops snd_usbmidi_maudio_broken_running_status_ops = {
639 .input = snd_usbmidi_maudio_broken_running_status_input,
640 .output = snd_usbmidi_standard_output,
641 .output_packet = snd_usbmidi_output_standard_packet,
645 .input = snd_usbmidi_cme_input,
646 .output = snd_usbmidi_standard_output,
647 .output_packet = snd_usbmidi_output_standard_packet,
666 uint8_t *buffer,
int buffer_length)
668 unsigned int pos = 0;
669 unsigned int len = (
unsigned int)buffer_length;
671 unsigned int port = (buffer[
pos] >> 4) - 1;
674 if (pos + msg_len <= len && port < 2)
675 snd_usbmidi_input_data(ep, 0, &buffer[pos], msg_len);
680 #define MAX_AKAI_SYSEX_LEN 9
690 if (!ep->
ports[0].active)
693 msg = urb->transfer_buffer + urb->transfer_buffer_length;
697 while (urb->transfer_buffer_length < buf_end) {
701 ep->
ports[0].active = 0;
705 for (pos = 0; pos < count && tmp[
pos] != 0xF0; pos++)
714 for (end = 1; end < count && tmp[
end] < 0xF0; end++)
718 if (end < count && tmp[end] == 0xF0) {
724 if (end < count && tmp[end] == 0xF7) {
727 msg[0] = 0x10 |
count;
728 memcpy(&msg[1], tmp, count);
730 urb->transfer_buffer_length += count + 1;
736 ep->
ports[0].active = 0;
745 .input = snd_usbmidi_akai_input,
746 .output = snd_usbmidi_akai_output,
756 uint8_t* buffer,
int buffer_length)
758 if (buffer_length < 2 || !buffer[0] || buffer_length < buffer[0] + 1)
760 snd_usbmidi_input_data(ep, 0, &buffer[2], buffer[0] - 1);
769 if (!ep->
ports[0].active)
771 transfer_buffer = urb->transfer_buffer;
776 ep->
ports[0].active = 0;
779 transfer_buffer[0] = 0;
780 transfer_buffer[1] =
count;
781 urb->transfer_buffer_length = 2 +
count;
785 .input = snd_usbmidi_novation_input,
786 .output = snd_usbmidi_novation_output,
794 uint8_t* buffer,
int buffer_length)
796 snd_usbmidi_input_data(ep, 0, buffer, buffer_length);
804 if (!ep->
ports[0].active)
807 urb->transfer_buffer,
810 ep->
ports[0].active = 0;
813 urb->transfer_buffer_length =
count;
817 .input = snd_usbmidi_raw_input,
818 .output = snd_usbmidi_raw_output,
826 uint8_t* buffer,
int buffer_length)
828 if (buffer_length > 2)
829 snd_usbmidi_input_data(ep, 0, buffer + 2, buffer_length - 2);
833 .input = snd_usbmidi_ftdi_input,
834 .output = snd_usbmidi_raw_output,
838 uint8_t *buffer,
int buffer_length)
840 if (buffer_length != 9)
843 while (buffer_length && buffer[buffer_length - 1] == 0xFD)
846 snd_usbmidi_input_data(ep, 0, buffer, buffer_length);
854 if (!ep->
ports[0].active)
865 urb->transfer_buffer,
868 ep->
ports[0].active = 0;
877 .input = snd_usbmidi_us122l_input,
878 .output = snd_usbmidi_us122l_output,
887 static const u8 init_data[] = {
897 send_bulk_static_data(ep, init_data,
sizeof(init_data));
899 send_bulk_static_data(ep, init_data,
sizeof(init_data));
904 static const u8 finish_data[] = {
915 send_bulk_static_data(ep, finish_data,
sizeof(finish_data));
919 uint8_t* buffer,
int buffer_length)
925 if (buffer[i] == 0xff) {
934 while (buffer_length > 0) {
937 if (buffer[i] == 0xf5)
939 snd_usbmidi_input_data(ep, ep->
current_port, buffer, i);
943 if (buffer_length <= 0)
951 if (buffer_length <= 0)
953 if (buffer[0] < 0x80) {
966 uint8_t* buf = urb->transfer_buffer;
970 for (i = 0; i < 0x10; ++
i) {
972 int portnum = (port0 +
i) & 15;
973 struct usbmidi_out_port* port = &ep->
ports[portnum];
987 buf[1] = (portnum + 1) & 15;
1002 if (buf_free < ep->max_transfer && buf_free > 0) {
1010 .input = snd_usbmidi_emagic_input,
1011 .output = snd_usbmidi_emagic_output,
1012 .init_out_endpoint = snd_usbmidi_emagic_init_out,
1013 .finish_out_endpoint = snd_usbmidi_emagic_finish_out,
1017 static void update_roland_altsetting(
struct snd_usb_midi* umidi)
1020 struct usb_host_interface *hostif;
1024 intf = umidi->
iface;
1025 is_light_load = intf->cur_altsetting != intf->altsetting;
1048 update_roland_altsetting(umidi);
1064 struct usbmidi_out_port* port =
NULL;
1070 for (j = 0; j < 0x10; ++
j)
1071 if (umidi->
endpoints[i].out->ports[j].substream == substream) {
1079 err = usb_autopm_get_interface(umidi->
iface);
1080 port->autopm_reference = err >= 0;
1081 if (err < 0 && err != -
EACCES)
1085 substream_open(substream, 1);
1092 struct usbmidi_out_port *port = substream->
runtime->private_data;
1094 substream_open(substream, 0);
1095 if (port->autopm_reference)
1096 usb_autopm_put_interface(umidi->
iface);
1102 struct usbmidi_out_port* port = (
struct usbmidi_out_port*)substream->
runtime->private_data;
1106 if (port->ep->umidi->disconnected) {
1113 tasklet_schedule(&port->ep->tasklet);
1119 struct usbmidi_out_port* port = substream->
runtime->private_data;
1125 if (ep->
umidi->disconnected)
1142 }
while (drain_urbs && timeout);
1150 substream_open(substream, 1);
1156 substream_open(substream, 0);
1171 .open = snd_usbmidi_output_open,
1172 .close = snd_usbmidi_output_close,
1173 .trigger = snd_usbmidi_output_trigger,
1174 .drain = snd_usbmidi_output_drain,
1178 .open = snd_usbmidi_input_open,
1179 .close = snd_usbmidi_input_close,
1180 .trigger = snd_usbmidi_input_trigger
1183 static void free_urb_and_buffer(
struct snd_usb_midi *umidi,
struct urb *urb,
1184 unsigned int buffer_length)
1187 urb->transfer_buffer, urb->transfer_dma);
1201 free_urb_and_buffer(ep->
umidi, ep->
urbs[i],
1202 ep->
urbs[i]->transfer_buffer_length);
1209 static int snd_usbmidi_in_endpoint_create(
struct snd_usb_midi* umidi,
1211 struct snd_usb_midi_endpoint*
rep)
1228 snd_usbmidi_in_endpoint_delete(ep);
1233 pipe = usb_rcvintpipe(umidi->
dev, ep_info->
in_ep);
1235 pipe = usb_rcvbulkpipe(umidi->
dev, ep_info->
in_ep);
1236 length = usb_maxpacket(umidi->
dev, pipe, 0);
1239 &ep->
urbs[i]->transfer_dma);
1241 snd_usbmidi_in_endpoint_delete(ep);
1245 usb_fill_int_urb(ep->
urbs[i], umidi->
dev,
1246 pipe, buffer, length,
1247 snd_usbmidi_in_urb_complete,
1250 usb_fill_bulk_urb(ep->
urbs[i], umidi->
dev,
1251 pipe, buffer, length,
1252 snd_usbmidi_in_urb_complete, ep);
1253 ep->
urbs[
i]->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
1269 if (ep->
urbs[i].urb) {
1270 free_urb_and_buffer(ep->
umidi, ep->
urbs[i].urb,
1278 snd_usbmidi_out_endpoint_clear(ep);
1285 static int snd_usbmidi_out_endpoint_create(
struct snd_usb_midi* umidi,
1287 struct snd_usb_midi_endpoint* rep)
1302 if (!ep->
urbs[i].urb) {
1303 snd_usbmidi_out_endpoint_delete(ep);
1306 ep->
urbs[
i].ep = ep;
1309 pipe = usb_sndintpipe(umidi->
dev, ep_info->
out_ep);
1311 pipe = usb_sndbulkpipe(umidi->
dev, ep_info->
out_ep);
1320 case USB_ID(0x0a92, 0x1020):
1321 case
USB_ID(0x1430, 0x474b):
1322 case
USB_ID(0x15ca, 0x0101):
1323 case
USB_ID(0x15ca, 0x1806):
1324 case
USB_ID(0x1a86, 0x752d):
1325 case
USB_ID(0xfc08, 0x0101):
1331 case USB_ID(0x0644, 0x800E):
1332 case
USB_ID(0x0644, 0x800F):
1339 &ep->
urbs[i].urb->transfer_dma);
1341 snd_usbmidi_out_endpoint_delete(ep);
1345 usb_fill_int_urb(ep->
urbs[i].urb, umidi->
dev,
1347 snd_usbmidi_out_urb_complete,
1350 usb_fill_bulk_urb(ep->
urbs[i].urb, umidi->
dev,
1352 snd_usbmidi_out_urb_complete,
1354 ep->
urbs[
i].urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
1361 for (i = 0; i < 0x10; ++
i)
1364 ep->
ports[
i].cable = i << 4;
1377 static void snd_usbmidi_free(
struct snd_usb_midi* umidi)
1382 struct snd_usb_midi_endpoint* ep = &umidi->
endpoints[
i];
1384 snd_usbmidi_out_endpoint_delete(ep->out);
1386 snd_usbmidi_in_endpoint_delete(ep->in);
1410 struct snd_usb_midi_endpoint* ep = &umidi->
endpoints[
i];
1418 ep->out->active_urbs = 0;
1419 if (ep->out->drain_urbs) {
1420 ep->out->drain_urbs = 0;
1421 wake_up(&ep->out->drain_wait);
1429 snd_usbmidi_out_endpoint_clear(ep->out);
1431 snd_usbmidi_in_endpoint_delete(ep->in);
1438 static void snd_usbmidi_rawmidi_free(
struct snd_rawmidi *rmidi)
1441 snd_usbmidi_free(umidi);
1451 if (substream->
number == number)
1468 } snd_usbmidi_port_info[] = {
1469 #define PORT_INFO(vendor, product, num, name_, voices_, flags) \
1470 { .id = USB_ID(vendor, product), \
1471 .port = num, .voices = voices_, \
1472 .name = name_, .seq_flags = flags }
1473 #define EXTERNAL_PORT(vendor, product, num, name) \
1474 PORT_INFO(vendor, product, num, name, 0, \
1475 SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC | \
1476 SNDRV_SEQ_PORT_TYPE_HARDWARE | \
1477 SNDRV_SEQ_PORT_TYPE_PORT)
1478 #define CONTROL_PORT(vendor, product, num, name) \
1479 PORT_INFO(vendor, product, num, name, 0, \
1480 SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC | \
1481 SNDRV_SEQ_PORT_TYPE_HARDWARE)
1482 #define ROLAND_SYNTH_PORT(vendor, product, num, name, voices) \
1483 PORT_INFO(vendor, product, num, name, voices, \
1484 SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC | \
1485 SNDRV_SEQ_PORT_TYPE_MIDI_GM | \
1486 SNDRV_SEQ_PORT_TYPE_MIDI_GM2 | \
1487 SNDRV_SEQ_PORT_TYPE_MIDI_GS | \
1488 SNDRV_SEQ_PORT_TYPE_MIDI_XG | \
1489 SNDRV_SEQ_PORT_TYPE_HARDWARE | \
1490 SNDRV_SEQ_PORT_TYPE_SYNTHESIZER)
1491 #define SOUNDCANVAS_PORT(vendor, product, num, name, voices) \
1492 PORT_INFO(vendor, product, num, name, voices, \
1493 SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC | \
1494 SNDRV_SEQ_PORT_TYPE_MIDI_GM | \
1495 SNDRV_SEQ_PORT_TYPE_MIDI_GM2 | \
1496 SNDRV_SEQ_PORT_TYPE_MIDI_GS | \
1497 SNDRV_SEQ_PORT_TYPE_MIDI_XG | \
1498 SNDRV_SEQ_PORT_TYPE_MIDI_MT32 | \
1499 SNDRV_SEQ_PORT_TYPE_HARDWARE | \
1500 SNDRV_SEQ_PORT_TYPE_SYNTHESIZER)
1582 PORT_INFO(0x09e8, 0x0062, 1,
"%s MIDI", 0,
1587 PORT_INFO(0x133e, 0x0815, 1,
"%s Synth", 0,
1597 for (i = 0; i <
ARRAY_SIZE(snd_usbmidi_port_info); ++
i) {
1598 if (snd_usbmidi_port_info[i].
id == umidi->
usb_id &&
1599 snd_usbmidi_port_info[i].port == number)
1600 return &snd_usbmidi_port_info[
i];
1605 static void snd_usbmidi_get_port_info(
struct snd_rawmidi *rmidi,
int number,
1612 port_info = find_port_info(umidi, number);
1619 static void snd_usbmidi_init_substream(
struct snd_usb_midi* umidi,
1620 int stream,
int number,
1623 struct port_info *port_info;
1624 const char *name_format;
1633 port_info = find_port_info(umidi, number);
1634 name_format = port_info ? port_info->
name :
"%s MIDI %d";
1636 name_format, umidi->
card->shortname, number + 1);
1638 *rsubstream = substream;
1644 static int snd_usbmidi_create_endpoints(
struct snd_usb_midi* umidi,
1648 int out_ports = 0, in_ports = 0;
1651 if (endpoints[i].out_cables) {
1652 err = snd_usbmidi_out_endpoint_create(umidi, &endpoints[i],
1657 if (endpoints[i].in_cables) {
1658 err = snd_usbmidi_in_endpoint_create(umidi, &endpoints[i],
1664 for (j = 0; j < 0x10; ++
j) {
1665 if (endpoints[i].out_cables & (1 << j)) {
1667 &umidi->
endpoints[i].out->ports[j].substream);
1670 if (endpoints[i].in_cables & (1 << j)) {
1672 &umidi->
endpoints[i].in->ports[j].substream);
1678 out_ports, in_ports);
1685 static int snd_usbmidi_get_ms_info(
struct snd_usb_midi* umidi,
1689 struct usb_host_interface *hostif;
1692 struct usb_host_endpoint *hostep;
1697 intf = umidi->
iface;
1700 hostif = &intf->altsetting[0];
1703 if (hostif->extralen >= 7 &&
1714 hostep = &hostif->endpoint[
i];
1716 if (!usb_endpoint_xfer_bulk(ep) && !usb_endpoint_xfer_int(ep))
1719 if (hostep->extralen < 4 ||
1724 if (usb_endpoint_dir_out(ep)) {
1725 if (endpoints[epidx].out_ep) {
1726 if (++epidx >= MIDI_MAX_ENDPOINTS) {
1731 endpoints[epidx].
out_ep = usb_endpoint_num(ep);
1732 if (usb_endpoint_xfer_int(ep))
1745 if (endpoints[epidx].in_ep) {
1746 if (++epidx >= MIDI_MAX_ENDPOINTS) {
1751 endpoints[epidx].
in_ep = usb_endpoint_num(ep);
1752 if (usb_endpoint_xfer_int(ep))
1764 static int roland_load_info(
struct snd_kcontrol *kcontrol,
1767 static const char *
const names[] = {
"High Load",
"Light Load" };
1772 static int roland_load_get(
struct snd_kcontrol *kcontrol,
1779 static int roland_load_put(
struct snd_kcontrol *kcontrol,
1785 if (value->
value.enumerated.item[0] > 1)
1797 .name =
"MIDI Input Mode",
1798 .info = roland_load_info,
1799 .get = roland_load_get,
1800 .put = roland_load_put,
1808 static void snd_usbmidi_switch_roland_altsetting(
struct snd_usb_midi* umidi)
1811 struct usb_host_interface *hostif;
1814 intf = umidi->
iface;
1815 if (!intf || intf->num_altsetting != 2)
1818 hostif = &intf->altsetting[1];
1838 static int snd_usbmidi_detect_endpoints(
struct snd_usb_midi* umidi,
1843 struct usb_host_interface *hostif;
1846 int i, out_eps = 0, in_eps = 0;
1849 snd_usbmidi_switch_roland_altsetting(umidi);
1851 if (endpoint[0].out_ep || endpoint[0].in_ep)
1854 intf = umidi->
iface;
1855 if (!intf || intf->num_altsetting < 1)
1857 hostif = intf->cur_altsetting;
1862 if (!usb_endpoint_xfer_bulk(epd) &&
1863 !usb_endpoint_xfer_int(epd))
1865 if (out_eps < max_endpoints &&
1866 usb_endpoint_dir_out(epd)) {
1867 endpoint[out_eps].
out_ep = usb_endpoint_num(epd);
1868 if (usb_endpoint_xfer_int(epd))
1872 if (in_eps < max_endpoints &&
1873 usb_endpoint_dir_in(epd)) {
1874 endpoint[in_eps].
in_ep = usb_endpoint_num(epd);
1875 if (usb_endpoint_xfer_int(epd))
1880 return (out_eps || in_eps) ? 0 : -
ENOENT;
1886 static int snd_usbmidi_detect_per_port_endpoints(
struct snd_usb_midi* umidi,
1891 err = snd_usbmidi_detect_endpoints(umidi, endpoints, MIDI_MAX_ENDPOINTS);
1893 if (endpoints[i].out_ep)
1895 if (endpoints[i].in_ep)
1904 static int snd_usbmidi_detect_yamaha(
struct snd_usb_midi* umidi,
1908 struct usb_host_interface *hostif;
1912 intf = umidi->
iface;
1915 hostif = intf->altsetting;
1924 for (cs_desc = hostif->extra;
1925 cs_desc < hostif->
extra + hostif->extralen && cs_desc[0] >= 2;
1926 cs_desc += cs_desc[0]) {
1937 return snd_usbmidi_detect_endpoints(umidi, endpoint, 1);
1943 static int snd_usbmidi_create_endpoints_midiman(
struct snd_usb_midi* umidi,
1948 struct usb_host_interface *hostif;
1953 intf = umidi->
iface;
1956 hostif = intf->altsetting;
1974 if (!usb_endpoint_dir_in(epd) || !usb_endpoint_xfer_int(epd)) {
1979 if (!usb_endpoint_dir_out(epd) || !usb_endpoint_xfer_bulk(epd)) {
1985 if (!usb_endpoint_dir_out(epd) ||
1986 !usb_endpoint_xfer_bulk(epd)) {
1995 err = snd_usbmidi_out_endpoint_create(umidi, &ep_info, &umidi->
endpoints[0]);
2002 err = snd_usbmidi_in_endpoint_create(umidi, &ep_info, &umidi->
endpoints[0]);
2009 err = snd_usbmidi_out_endpoint_create(umidi, &ep_info, &umidi->
endpoints[1]);
2014 for (cable = 0; cable < 0x10; ++cable) {
2017 &umidi->
endpoints[cable & 1].out->ports[cable].substream);
2020 &umidi->
endpoints[0].in->ports[cable].substream);
2026 .get_port_info = snd_usbmidi_get_port_info,
2029 static int snd_usbmidi_create_rawmidi(
struct snd_usb_midi* umidi,
2030 int out_ports,
int in_ports)
2037 out_ports, in_ports, &rmidi);
2044 rmidi->
ops = &snd_usbmidi_ops;
2050 umidi->
rmidi = rmidi;
2064 struct snd_usb_midi_endpoint* ep = &umidi->
endpoints[
i];
2078 struct urb* urb = ep->
urbs[
i];
2079 urb->dev = ep->
umidi->dev;
2094 snd_usbmidi_input_start_ep(umidi->
endpoints[i].in);
2107 int out_ports, in_ports;
2113 umidi->
dev = interface_to_usbdev(iface);
2115 umidi->
iface = iface;
2116 umidi->
quirk = quirk;
2123 umidi->
error_timer.function = snd_usbmidi_error_timer;
2127 memset(endpoints, 0,
sizeof(endpoints));
2129 case QUIRK_MIDI_STANDARD_INTERFACE:
2130 err = snd_usbmidi_get_ms_info(umidi, endpoints);
2133 &snd_usbmidi_maudio_broken_running_status_ops;
2141 err = snd_usbmidi_detect_endpoints(umidi, &endpoints[0], 1);
2144 err = snd_usbmidi_detect_yamaha(umidi, &endpoints[0]);
2154 err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints);
2169 err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints);
2175 err = snd_usbmidi_detect_endpoints(umidi, &endpoints[0], 1);
2179 err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints);
2183 err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints);
2192 3, 0x40, 0x60, 0,
NULL, 0, 1000);
2196 err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints);
2212 out_ports +=
hweight16(endpoints[i].out_cables);
2213 in_ports +=
hweight16(endpoints[i].in_cables);
2215 err = snd_usbmidi_create_rawmidi(umidi, out_ports, in_ports);
2223 err = snd_usbmidi_create_endpoints_midiman(umidi, &endpoints[0]);
2225 err = snd_usbmidi_create_endpoints(umidi, endpoints);
2227 snd_usbmidi_free(umidi);
2234 snd_usbmidi_input_start_ep(umidi->
endpoints[i].in);