aboutsummaryrefslogtreecommitdiffstats
path: root/sound/usb/usbmidi.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/usb/usbmidi.c')
-rw-r--r--sound/usb/usbmidi.c208
1 files changed, 155 insertions, 53 deletions
diff --git a/sound/usb/usbmidi.c b/sound/usb/usbmidi.c
index 0eff19ceb7e1..6e89b8368d9a 100644
--- a/sound/usb/usbmidi.c
+++ b/sound/usb/usbmidi.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * usbmidi.c - ALSA USB MIDI driver 2 * usbmidi.c - ALSA USB MIDI driver
3 * 3 *
4 * Copyright (c) 2002-2007 Clemens Ladisch 4 * Copyright (c) 2002-2009 Clemens Ladisch
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Based on the OSS usb-midi driver by NAGANO Daisuke, 7 * Based on the OSS usb-midi driver by NAGANO Daisuke,
@@ -47,6 +47,7 @@
47#include <linux/usb.h> 47#include <linux/usb.h>
48#include <linux/wait.h> 48#include <linux/wait.h>
49#include <sound/core.h> 49#include <sound/core.h>
50#include <sound/control.h>
50#include <sound/rawmidi.h> 51#include <sound/rawmidi.h>
51#include <sound/asequencer.h> 52#include <sound/asequencer.h>
52#include "usbaudio.h" 53#include "usbaudio.h"
@@ -101,7 +102,8 @@ struct usb_protocol_ops {
101}; 102};
102 103
103struct snd_usb_midi { 104struct snd_usb_midi {
104 struct snd_usb_audio *chip; 105 struct usb_device *dev;
106 struct snd_card *card;
105 struct usb_interface *iface; 107 struct usb_interface *iface;
106 const struct snd_usb_audio_quirk *quirk; 108 const struct snd_usb_audio_quirk *quirk;
107 struct snd_rawmidi *rmidi; 109 struct snd_rawmidi *rmidi;
@@ -109,13 +111,19 @@ struct snd_usb_midi {
109 struct list_head list; 111 struct list_head list;
110 struct timer_list error_timer; 112 struct timer_list error_timer;
111 spinlock_t disc_lock; 113 spinlock_t disc_lock;
114 struct mutex mutex;
115 u32 usb_id;
116 int next_midi_device;
112 117
113 struct snd_usb_midi_endpoint { 118 struct snd_usb_midi_endpoint {
114 struct snd_usb_midi_out_endpoint *out; 119 struct snd_usb_midi_out_endpoint *out;
115 struct snd_usb_midi_in_endpoint *in; 120 struct snd_usb_midi_in_endpoint *in;
116 } endpoints[MIDI_MAX_ENDPOINTS]; 121 } endpoints[MIDI_MAX_ENDPOINTS];
117 unsigned long input_triggered; 122 unsigned long input_triggered;
123 unsigned int opened;
118 unsigned char disconnected; 124 unsigned char disconnected;
125
126 struct snd_kcontrol *roland_load_ctl;
119}; 127};
120 128
121struct snd_usb_midi_out_endpoint { 129struct snd_usb_midi_out_endpoint {
@@ -255,7 +263,7 @@ static void snd_usbmidi_in_urb_complete(struct urb* urb)
255 } 263 }
256 } 264 }
257 265
258 urb->dev = ep->umidi->chip->dev; 266 urb->dev = ep->umidi->dev;
259 snd_usbmidi_submit_urb(urb, GFP_ATOMIC); 267 snd_usbmidi_submit_urb(urb, GFP_ATOMIC);
260} 268}
261 269
@@ -296,7 +304,7 @@ static void snd_usbmidi_do_output(struct snd_usb_midi_out_endpoint* ep)
296 unsigned long flags; 304 unsigned long flags;
297 305
298 spin_lock_irqsave(&ep->buffer_lock, flags); 306 spin_lock_irqsave(&ep->buffer_lock, flags);
299 if (ep->umidi->chip->shutdown) { 307 if (ep->umidi->disconnected) {
300 spin_unlock_irqrestore(&ep->buffer_lock, flags); 308 spin_unlock_irqrestore(&ep->buffer_lock, flags);
301 return; 309 return;
302 } 310 }
@@ -312,7 +320,7 @@ static void snd_usbmidi_do_output(struct snd_usb_midi_out_endpoint* ep)
312 320
313 dump_urb("sending", urb->transfer_buffer, 321 dump_urb("sending", urb->transfer_buffer,
314 urb->transfer_buffer_length); 322 urb->transfer_buffer_length);
315 urb->dev = ep->umidi->chip->dev; 323 urb->dev = ep->umidi->dev;
316 if (snd_usbmidi_submit_urb(urb, GFP_ATOMIC) < 0) 324 if (snd_usbmidi_submit_urb(urb, GFP_ATOMIC) < 0)
317 break; 325 break;
318 ep->active_urbs |= 1 << urb_index; 326 ep->active_urbs |= 1 << urb_index;
@@ -349,7 +357,7 @@ static void snd_usbmidi_error_timer(unsigned long data)
349 if (in && in->error_resubmit) { 357 if (in && in->error_resubmit) {
350 in->error_resubmit = 0; 358 in->error_resubmit = 0;
351 for (j = 0; j < INPUT_URBS; ++j) { 359 for (j = 0; j < INPUT_URBS; ++j) {
352 in->urbs[j]->dev = umidi->chip->dev; 360 in->urbs[j]->dev = umidi->dev;
353 snd_usbmidi_submit_urb(in->urbs[j], GFP_ATOMIC); 361 snd_usbmidi_submit_urb(in->urbs[j], GFP_ATOMIC);
354 } 362 }
355 } 363 }
@@ -369,7 +377,7 @@ static int send_bulk_static_data(struct snd_usb_midi_out_endpoint* ep,
369 return -ENOMEM; 377 return -ENOMEM;
370 dump_urb("sending", buf, len); 378 dump_urb("sending", buf, len);
371 if (ep->urbs[0].urb) 379 if (ep->urbs[0].urb)
372 err = usb_bulk_msg(ep->umidi->chip->dev, ep->urbs[0].urb->pipe, 380 err = usb_bulk_msg(ep->umidi->dev, ep->urbs[0].urb->pipe,
373 buf, len, NULL, 250); 381 buf, len, NULL, 250);
374 kfree(buf); 382 kfree(buf);
375 return err; 383 return err;
@@ -724,8 +732,7 @@ static void snd_usbmidi_us122l_output(struct snd_usb_midi_out_endpoint *ep,
724 732
725 if (!ep->ports[0].active) 733 if (!ep->ports[0].active)
726 return; 734 return;
727 count = snd_usb_get_speed(ep->umidi->chip->dev) == USB_SPEED_HIGH 735 count = snd_usb_get_speed(ep->umidi->dev) == USB_SPEED_HIGH ? 1 : 2;
728 ? 1 : 2;
729 count = snd_rawmidi_transmit(ep->ports[0].substream, 736 count = snd_rawmidi_transmit(ep->ports[0].substream,
730 urb->transfer_buffer, 737 urb->transfer_buffer,
731 count); 738 count);
@@ -879,6 +886,50 @@ static struct usb_protocol_ops snd_usbmidi_emagic_ops = {
879}; 886};
880 887
881 888
889static void update_roland_altsetting(struct snd_usb_midi* umidi)
890{
891 struct usb_interface *intf;
892 struct usb_host_interface *hostif;
893 struct usb_interface_descriptor *intfd;
894 int is_light_load;
895
896 intf = umidi->iface;
897 is_light_load = intf->cur_altsetting != intf->altsetting;
898 if (umidi->roland_load_ctl->private_value == is_light_load)
899 return;
900 hostif = &intf->altsetting[umidi->roland_load_ctl->private_value];
901 intfd = get_iface_desc(hostif);
902 snd_usbmidi_input_stop(&umidi->list);
903 usb_set_interface(umidi->dev, intfd->bInterfaceNumber,
904 intfd->bAlternateSetting);
905 snd_usbmidi_input_start(&umidi->list);
906}
907
908static void substream_open(struct snd_rawmidi_substream *substream, int open)
909{
910 struct snd_usb_midi* umidi = substream->rmidi->private_data;
911 struct snd_kcontrol *ctl;
912
913 mutex_lock(&umidi->mutex);
914 if (open) {
915 if (umidi->opened++ == 0 && umidi->roland_load_ctl) {
916 ctl = umidi->roland_load_ctl;
917 ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
918 snd_ctl_notify(umidi->card,
919 SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
920 update_roland_altsetting(umidi);
921 }
922 } else {
923 if (--umidi->opened == 0 && umidi->roland_load_ctl) {
924 ctl = umidi->roland_load_ctl;
925 ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
926 snd_ctl_notify(umidi->card,
927 SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
928 }
929 }
930 mutex_unlock(&umidi->mutex);
931}
932
882static int snd_usbmidi_output_open(struct snd_rawmidi_substream *substream) 933static int snd_usbmidi_output_open(struct snd_rawmidi_substream *substream)
883{ 934{
884 struct snd_usb_midi* umidi = substream->rmidi->private_data; 935 struct snd_usb_midi* umidi = substream->rmidi->private_data;
@@ -898,11 +949,13 @@ static int snd_usbmidi_output_open(struct snd_rawmidi_substream *substream)
898 } 949 }
899 substream->runtime->private_data = port; 950 substream->runtime->private_data = port;
900 port->state = STATE_UNKNOWN; 951 port->state = STATE_UNKNOWN;
952 substream_open(substream, 1);
901 return 0; 953 return 0;
902} 954}
903 955
904static int snd_usbmidi_output_close(struct snd_rawmidi_substream *substream) 956static int snd_usbmidi_output_close(struct snd_rawmidi_substream *substream)
905{ 957{
958 substream_open(substream, 0);
906 return 0; 959 return 0;
907} 960}
908 961
@@ -912,7 +965,7 @@ static void snd_usbmidi_output_trigger(struct snd_rawmidi_substream *substream,
912 965
913 port->active = up; 966 port->active = up;
914 if (up) { 967 if (up) {
915 if (port->ep->umidi->chip->shutdown) { 968 if (port->ep->umidi->disconnected) {
916 /* gobble up remaining bytes to prevent wait in 969 /* gobble up remaining bytes to prevent wait in
917 * snd_rawmidi_drain_output */ 970 * snd_rawmidi_drain_output */
918 while (!snd_rawmidi_transmit_empty(substream)) 971 while (!snd_rawmidi_transmit_empty(substream))
@@ -954,11 +1007,13 @@ static void snd_usbmidi_output_drain(struct snd_rawmidi_substream *substream)
954 1007
955static int snd_usbmidi_input_open(struct snd_rawmidi_substream *substream) 1008static int snd_usbmidi_input_open(struct snd_rawmidi_substream *substream)
956{ 1009{
1010 substream_open(substream, 1);
957 return 0; 1011 return 0;
958} 1012}
959 1013
960static int snd_usbmidi_input_close(struct snd_rawmidi_substream *substream) 1014static int snd_usbmidi_input_close(struct snd_rawmidi_substream *substream)
961{ 1015{
1016 substream_open(substream, 0);
962 return 0; 1017 return 0;
963} 1018}
964 1019
@@ -988,7 +1043,7 @@ static struct snd_rawmidi_ops snd_usbmidi_input_ops = {
988static void free_urb_and_buffer(struct snd_usb_midi *umidi, struct urb *urb, 1043static void free_urb_and_buffer(struct snd_usb_midi *umidi, struct urb *urb,
989 unsigned int buffer_length) 1044 unsigned int buffer_length)
990{ 1045{
991 usb_buffer_free(umidi->chip->dev, buffer_length, 1046 usb_buffer_free(umidi->dev, buffer_length,
992 urb->transfer_buffer, urb->transfer_dma); 1047 urb->transfer_buffer, urb->transfer_dma);
993 usb_free_urb(urb); 1048 usb_free_urb(urb);
994} 1049}
@@ -1035,24 +1090,24 @@ static int snd_usbmidi_in_endpoint_create(struct snd_usb_midi* umidi,
1035 } 1090 }
1036 } 1091 }
1037 if (ep_info->in_interval) 1092 if (ep_info->in_interval)
1038 pipe = usb_rcvintpipe(umidi->chip->dev, ep_info->in_ep); 1093 pipe = usb_rcvintpipe(umidi->dev, ep_info->in_ep);
1039 else 1094 else
1040 pipe = usb_rcvbulkpipe(umidi->chip->dev, ep_info->in_ep); 1095 pipe = usb_rcvbulkpipe(umidi->dev, ep_info->in_ep);
1041 length = usb_maxpacket(umidi->chip->dev, pipe, 0); 1096 length = usb_maxpacket(umidi->dev, pipe, 0);
1042 for (i = 0; i < INPUT_URBS; ++i) { 1097 for (i = 0; i < INPUT_URBS; ++i) {
1043 buffer = usb_buffer_alloc(umidi->chip->dev, length, GFP_KERNEL, 1098 buffer = usb_buffer_alloc(umidi->dev, length, GFP_KERNEL,
1044 &ep->urbs[i]->transfer_dma); 1099 &ep->urbs[i]->transfer_dma);
1045 if (!buffer) { 1100 if (!buffer) {
1046 snd_usbmidi_in_endpoint_delete(ep); 1101 snd_usbmidi_in_endpoint_delete(ep);
1047 return -ENOMEM; 1102 return -ENOMEM;
1048 } 1103 }
1049 if (ep_info->in_interval) 1104 if (ep_info->in_interval)
1050 usb_fill_int_urb(ep->urbs[i], umidi->chip->dev, 1105 usb_fill_int_urb(ep->urbs[i], umidi->dev,
1051 pipe, buffer, length, 1106 pipe, buffer, length,
1052 snd_usbmidi_in_urb_complete, 1107 snd_usbmidi_in_urb_complete,
1053 ep, ep_info->in_interval); 1108 ep, ep_info->in_interval);
1054 else 1109 else
1055 usb_fill_bulk_urb(ep->urbs[i], umidi->chip->dev, 1110 usb_fill_bulk_urb(ep->urbs[i], umidi->dev,
1056 pipe, buffer, length, 1111 pipe, buffer, length,
1057 snd_usbmidi_in_urb_complete, ep); 1112 snd_usbmidi_in_urb_complete, ep);
1058 ep->urbs[i]->transfer_flags = URB_NO_TRANSFER_DMA_MAP; 1113 ep->urbs[i]->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
@@ -1062,15 +1117,6 @@ static int snd_usbmidi_in_endpoint_create(struct snd_usb_midi* umidi,
1062 return 0; 1117 return 0;
1063} 1118}
1064 1119
1065static unsigned int snd_usbmidi_count_bits(unsigned int x)
1066{
1067 unsigned int bits;
1068
1069 for (bits = 0; x; ++bits)
1070 x &= x - 1;
1071 return bits;
1072}
1073
1074/* 1120/*
1075 * Frees an output endpoint. 1121 * Frees an output endpoint.
1076 * May be called when ep hasn't been initialized completely. 1122 * May be called when ep hasn't been initialized completely.
@@ -1113,15 +1159,15 @@ static int snd_usbmidi_out_endpoint_create(struct snd_usb_midi* umidi,
1113 ep->urbs[i].ep = ep; 1159 ep->urbs[i].ep = ep;
1114 } 1160 }
1115 if (ep_info->out_interval) 1161 if (ep_info->out_interval)
1116 pipe = usb_sndintpipe(umidi->chip->dev, ep_info->out_ep); 1162 pipe = usb_sndintpipe(umidi->dev, ep_info->out_ep);
1117 else 1163 else
1118 pipe = usb_sndbulkpipe(umidi->chip->dev, ep_info->out_ep); 1164 pipe = usb_sndbulkpipe(umidi->dev, ep_info->out_ep);
1119 if (umidi->chip->usb_id == USB_ID(0x0a92, 0x1020)) /* ESI M4U */ 1165 if (umidi->usb_id == USB_ID(0x0a92, 0x1020)) /* ESI M4U */
1120 ep->max_transfer = 4; 1166 ep->max_transfer = 4;
1121 else 1167 else
1122 ep->max_transfer = usb_maxpacket(umidi->chip->dev, pipe, 1); 1168 ep->max_transfer = usb_maxpacket(umidi->dev, pipe, 1);
1123 for (i = 0; i < OUTPUT_URBS; ++i) { 1169 for (i = 0; i < OUTPUT_URBS; ++i) {
1124 buffer = usb_buffer_alloc(umidi->chip->dev, 1170 buffer = usb_buffer_alloc(umidi->dev,
1125 ep->max_transfer, GFP_KERNEL, 1171 ep->max_transfer, GFP_KERNEL,
1126 &ep->urbs[i].urb->transfer_dma); 1172 &ep->urbs[i].urb->transfer_dma);
1127 if (!buffer) { 1173 if (!buffer) {
@@ -1129,12 +1175,12 @@ static int snd_usbmidi_out_endpoint_create(struct snd_usb_midi* umidi,
1129 return -ENOMEM; 1175 return -ENOMEM;
1130 } 1176 }
1131 if (ep_info->out_interval) 1177 if (ep_info->out_interval)
1132 usb_fill_int_urb(ep->urbs[i].urb, umidi->chip->dev, 1178 usb_fill_int_urb(ep->urbs[i].urb, umidi->dev,
1133 pipe, buffer, ep->max_transfer, 1179 pipe, buffer, ep->max_transfer,
1134 snd_usbmidi_out_urb_complete, 1180 snd_usbmidi_out_urb_complete,
1135 &ep->urbs[i], ep_info->out_interval); 1181 &ep->urbs[i], ep_info->out_interval);
1136 else 1182 else
1137 usb_fill_bulk_urb(ep->urbs[i].urb, umidi->chip->dev, 1183 usb_fill_bulk_urb(ep->urbs[i].urb, umidi->dev,
1138 pipe, buffer, ep->max_transfer, 1184 pipe, buffer, ep->max_transfer,
1139 snd_usbmidi_out_urb_complete, 1185 snd_usbmidi_out_urb_complete,
1140 &ep->urbs[i]); 1186 &ep->urbs[i]);
@@ -1172,6 +1218,7 @@ static void snd_usbmidi_free(struct snd_usb_midi* umidi)
1172 if (ep->in) 1218 if (ep->in)
1173 snd_usbmidi_in_endpoint_delete(ep->in); 1219 snd_usbmidi_in_endpoint_delete(ep->in);
1174 } 1220 }
1221 mutex_destroy(&umidi->mutex);
1175 kfree(umidi); 1222 kfree(umidi);
1176} 1223}
1177 1224
@@ -1367,7 +1414,7 @@ static struct port_info *find_port_info(struct snd_usb_midi* umidi, int number)
1367 int i; 1414 int i;
1368 1415
1369 for (i = 0; i < ARRAY_SIZE(snd_usbmidi_port_info); ++i) { 1416 for (i = 0; i < ARRAY_SIZE(snd_usbmidi_port_info); ++i) {
1370 if (snd_usbmidi_port_info[i].id == umidi->chip->usb_id && 1417 if (snd_usbmidi_port_info[i].id == umidi->usb_id &&
1371 snd_usbmidi_port_info[i].port == number) 1418 snd_usbmidi_port_info[i].port == number)
1372 return &snd_usbmidi_port_info[i]; 1419 return &snd_usbmidi_port_info[i];
1373 } 1420 }
@@ -1405,7 +1452,7 @@ static void snd_usbmidi_init_substream(struct snd_usb_midi* umidi,
1405 port_info = find_port_info(umidi, number); 1452 port_info = find_port_info(umidi, number);
1406 name_format = port_info ? port_info->name : "%s MIDI %d"; 1453 name_format = port_info ? port_info->name : "%s MIDI %d";
1407 snprintf(substream->name, sizeof(substream->name), 1454 snprintf(substream->name, sizeof(substream->name),
1408 name_format, umidi->chip->card->shortname, number + 1); 1455 name_format, umidi->card->shortname, number + 1);
1409 1456
1410 *rsubstream = substream; 1457 *rsubstream = substream;
1411} 1458}
@@ -1503,7 +1550,7 @@ static int snd_usbmidi_get_ms_info(struct snd_usb_midi* umidi,
1503 endpoints[epidx].out_ep = usb_endpoint_num(ep); 1550 endpoints[epidx].out_ep = usb_endpoint_num(ep);
1504 if (usb_endpoint_xfer_int(ep)) 1551 if (usb_endpoint_xfer_int(ep))
1505 endpoints[epidx].out_interval = ep->bInterval; 1552 endpoints[epidx].out_interval = ep->bInterval;
1506 else if (snd_usb_get_speed(umidi->chip->dev) == USB_SPEED_LOW) 1553 else if (snd_usb_get_speed(umidi->dev) == USB_SPEED_LOW)
1507 /* 1554 /*
1508 * Low speed bulk transfers don't exist, so 1555 * Low speed bulk transfers don't exist, so
1509 * force interrupt transfers for devices like 1556 * force interrupt transfers for devices like
@@ -1523,7 +1570,7 @@ static int snd_usbmidi_get_ms_info(struct snd_usb_midi* umidi,
1523 endpoints[epidx].in_ep = usb_endpoint_num(ep); 1570 endpoints[epidx].in_ep = usb_endpoint_num(ep);
1524 if (usb_endpoint_xfer_int(ep)) 1571 if (usb_endpoint_xfer_int(ep))
1525 endpoints[epidx].in_interval = ep->bInterval; 1572 endpoints[epidx].in_interval = ep->bInterval;
1526 else if (snd_usb_get_speed(umidi->chip->dev) == USB_SPEED_LOW) 1573 else if (snd_usb_get_speed(umidi->dev) == USB_SPEED_LOW)
1527 endpoints[epidx].in_interval = 1; 1574 endpoints[epidx].in_interval = 1;
1528 endpoints[epidx].in_cables = (1 << ms_ep->bNumEmbMIDIJack) - 1; 1575 endpoints[epidx].in_cables = (1 << ms_ep->bNumEmbMIDIJack) - 1;
1529 snd_printdd(KERN_INFO "EP %02X: %d jack(s)\n", 1576 snd_printdd(KERN_INFO "EP %02X: %d jack(s)\n",
@@ -1533,6 +1580,52 @@ static int snd_usbmidi_get_ms_info(struct snd_usb_midi* umidi,
1533 return 0; 1580 return 0;
1534} 1581}
1535 1582
1583static int roland_load_info(struct snd_kcontrol *kcontrol,
1584 struct snd_ctl_elem_info *info)
1585{
1586 static const char *const names[] = { "High Load", "Light Load" };
1587
1588 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1589 info->count = 1;
1590 info->value.enumerated.items = 2;
1591 if (info->value.enumerated.item > 1)
1592 info->value.enumerated.item = 1;
1593 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
1594 return 0;
1595}
1596
1597static int roland_load_get(struct snd_kcontrol *kcontrol,
1598 struct snd_ctl_elem_value *value)
1599{
1600 value->value.enumerated.item[0] = kcontrol->private_value;
1601 return 0;
1602}
1603
1604static int roland_load_put(struct snd_kcontrol *kcontrol,
1605 struct snd_ctl_elem_value *value)
1606{
1607 struct snd_usb_midi* umidi = kcontrol->private_data;
1608 int changed;
1609
1610 if (value->value.enumerated.item[0] > 1)
1611 return -EINVAL;
1612 mutex_lock(&umidi->mutex);
1613 changed = value->value.enumerated.item[0] != kcontrol->private_value;
1614 if (changed)
1615 kcontrol->private_value = value->value.enumerated.item[0];
1616 mutex_unlock(&umidi->mutex);
1617 return changed;
1618}
1619
1620static struct snd_kcontrol_new roland_load_ctl = {
1621 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1622 .name = "MIDI Input Mode",
1623 .info = roland_load_info,
1624 .get = roland_load_get,
1625 .put = roland_load_put,
1626 .private_value = 1,
1627};
1628
1536/* 1629/*
1537 * On Roland devices, use the second alternate setting to be able to use 1630 * On Roland devices, use the second alternate setting to be able to use
1538 * the interrupt input endpoint. 1631 * the interrupt input endpoint.
@@ -1556,8 +1649,12 @@ static void snd_usbmidi_switch_roland_altsetting(struct snd_usb_midi* umidi)
1556 1649
1557 snd_printdd(KERN_INFO "switching to altsetting %d with int ep\n", 1650 snd_printdd(KERN_INFO "switching to altsetting %d with int ep\n",
1558 intfd->bAlternateSetting); 1651 intfd->bAlternateSetting);
1559 usb_set_interface(umidi->chip->dev, intfd->bInterfaceNumber, 1652 usb_set_interface(umidi->dev, intfd->bInterfaceNumber,
1560 intfd->bAlternateSetting); 1653 intfd->bAlternateSetting);
1654
1655 umidi->roland_load_ctl = snd_ctl_new1(&roland_load_ctl, umidi);
1656 if (snd_ctl_add(umidi->card, umidi->roland_load_ctl) < 0)
1657 umidi->roland_load_ctl = NULL;
1561} 1658}
1562 1659
1563/* 1660/*
@@ -1573,7 +1670,7 @@ static int snd_usbmidi_detect_endpoints(struct snd_usb_midi* umidi,
1573 struct usb_endpoint_descriptor* epd; 1670 struct usb_endpoint_descriptor* epd;
1574 int i, out_eps = 0, in_eps = 0; 1671 int i, out_eps = 0, in_eps = 0;
1575 1672
1576 if (USB_ID_VENDOR(umidi->chip->usb_id) == 0x0582) 1673 if (USB_ID_VENDOR(umidi->usb_id) == 0x0582)
1577 snd_usbmidi_switch_roland_altsetting(umidi); 1674 snd_usbmidi_switch_roland_altsetting(umidi);
1578 1675
1579 if (endpoint[0].out_ep || endpoint[0].in_ep) 1676 if (endpoint[0].out_ep || endpoint[0].in_ep)
@@ -1760,12 +1857,12 @@ static int snd_usbmidi_create_rawmidi(struct snd_usb_midi* umidi,
1760 struct snd_rawmidi *rmidi; 1857 struct snd_rawmidi *rmidi;
1761 int err; 1858 int err;
1762 1859
1763 err = snd_rawmidi_new(umidi->chip->card, "USB MIDI", 1860 err = snd_rawmidi_new(umidi->card, "USB MIDI",
1764 umidi->chip->next_midi_device++, 1861 umidi->next_midi_device++,
1765 out_ports, in_ports, &rmidi); 1862 out_ports, in_ports, &rmidi);
1766 if (err < 0) 1863 if (err < 0)
1767 return err; 1864 return err;
1768 strcpy(rmidi->name, umidi->chip->card->shortname); 1865 strcpy(rmidi->name, umidi->card->shortname);
1769 rmidi->info_flags = SNDRV_RAWMIDI_INFO_OUTPUT | 1866 rmidi->info_flags = SNDRV_RAWMIDI_INFO_OUTPUT |
1770 SNDRV_RAWMIDI_INFO_INPUT | 1867 SNDRV_RAWMIDI_INFO_INPUT |
1771 SNDRV_RAWMIDI_INFO_DUPLEX; 1868 SNDRV_RAWMIDI_INFO_DUPLEX;
@@ -1804,7 +1901,7 @@ static void snd_usbmidi_input_start_ep(struct snd_usb_midi_in_endpoint* ep)
1804 return; 1901 return;
1805 for (i = 0; i < INPUT_URBS; ++i) { 1902 for (i = 0; i < INPUT_URBS; ++i) {
1806 struct urb* urb = ep->urbs[i]; 1903 struct urb* urb = ep->urbs[i];
1807 urb->dev = ep->umidi->chip->dev; 1904 urb->dev = ep->umidi->dev;
1808 snd_usbmidi_submit_urb(urb, GFP_KERNEL); 1905 snd_usbmidi_submit_urb(urb, GFP_KERNEL);
1809 } 1906 }
1810} 1907}
@@ -1825,9 +1922,10 @@ void snd_usbmidi_input_start(struct list_head* p)
1825/* 1922/*
1826 * Creates and registers everything needed for a MIDI streaming interface. 1923 * Creates and registers everything needed for a MIDI streaming interface.
1827 */ 1924 */
1828int snd_usb_create_midi_interface(struct snd_usb_audio* chip, 1925int snd_usbmidi_create(struct snd_card *card,
1829 struct usb_interface* iface, 1926 struct usb_interface* iface,
1830 const struct snd_usb_audio_quirk* quirk) 1927 struct list_head *midi_list,
1928 const struct snd_usb_audio_quirk* quirk)
1831{ 1929{
1832 struct snd_usb_midi* umidi; 1930 struct snd_usb_midi* umidi;
1833 struct snd_usb_midi_endpoint_info endpoints[MIDI_MAX_ENDPOINTS]; 1931 struct snd_usb_midi_endpoint_info endpoints[MIDI_MAX_ENDPOINTS];
@@ -1837,12 +1935,16 @@ int snd_usb_create_midi_interface(struct snd_usb_audio* chip,
1837 umidi = kzalloc(sizeof(*umidi), GFP_KERNEL); 1935 umidi = kzalloc(sizeof(*umidi), GFP_KERNEL);
1838 if (!umidi) 1936 if (!umidi)
1839 return -ENOMEM; 1937 return -ENOMEM;
1840 umidi->chip = chip; 1938 umidi->dev = interface_to_usbdev(iface);
1939 umidi->card = card;
1841 umidi->iface = iface; 1940 umidi->iface = iface;
1842 umidi->quirk = quirk; 1941 umidi->quirk = quirk;
1843 umidi->usb_protocol_ops = &snd_usbmidi_standard_ops; 1942 umidi->usb_protocol_ops = &snd_usbmidi_standard_ops;
1844 init_timer(&umidi->error_timer); 1943 init_timer(&umidi->error_timer);
1845 spin_lock_init(&umidi->disc_lock); 1944 spin_lock_init(&umidi->disc_lock);
1945 mutex_init(&umidi->mutex);
1946 umidi->usb_id = USB_ID(le16_to_cpu(umidi->dev->descriptor.idVendor),
1947 le16_to_cpu(umidi->dev->descriptor.idProduct));
1846 umidi->error_timer.function = snd_usbmidi_error_timer; 1948 umidi->error_timer.function = snd_usbmidi_error_timer;
1847 umidi->error_timer.data = (unsigned long)umidi; 1949 umidi->error_timer.data = (unsigned long)umidi;
1848 1950
@@ -1851,7 +1953,7 @@ int snd_usb_create_midi_interface(struct snd_usb_audio* chip,
1851 switch (quirk ? quirk->type : QUIRK_MIDI_STANDARD_INTERFACE) { 1953 switch (quirk ? quirk->type : QUIRK_MIDI_STANDARD_INTERFACE) {
1852 case QUIRK_MIDI_STANDARD_INTERFACE: 1954 case QUIRK_MIDI_STANDARD_INTERFACE:
1853 err = snd_usbmidi_get_ms_info(umidi, endpoints); 1955 err = snd_usbmidi_get_ms_info(umidi, endpoints);
1854 if (chip->usb_id == USB_ID(0x0763, 0x0150)) /* M-Audio Uno */ 1956 if (umidi->usb_id == USB_ID(0x0763, 0x0150)) /* M-Audio Uno */
1855 umidi->usb_protocol_ops = 1957 umidi->usb_protocol_ops =
1856 &snd_usbmidi_maudio_broken_running_status_ops; 1958 &snd_usbmidi_maudio_broken_running_status_ops;
1857 break; 1959 break;
@@ -1887,7 +1989,7 @@ int snd_usb_create_midi_interface(struct snd_usb_audio* chip,
1887 * interface 0, so we have to make sure that the USB core looks 1989 * interface 0, so we have to make sure that the USB core looks
1888 * again at interface 0 by calling usb_set_interface() on it. 1990 * again at interface 0 by calling usb_set_interface() on it.
1889 */ 1991 */
1890 usb_set_interface(umidi->chip->dev, 0, 0); 1992 usb_set_interface(umidi->dev, 0, 0);
1891 err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints); 1993 err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints);
1892 break; 1994 break;
1893 case QUIRK_MIDI_EMAGIC: 1995 case QUIRK_MIDI_EMAGIC:
@@ -1914,8 +2016,8 @@ int snd_usb_create_midi_interface(struct snd_usb_audio* chip,
1914 out_ports = 0; 2016 out_ports = 0;
1915 in_ports = 0; 2017 in_ports = 0;
1916 for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) { 2018 for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) {
1917 out_ports += snd_usbmidi_count_bits(endpoints[i].out_cables); 2019 out_ports += hweight16(endpoints[i].out_cables);
1918 in_ports += snd_usbmidi_count_bits(endpoints[i].in_cables); 2020 in_ports += hweight16(endpoints[i].in_cables);
1919 } 2021 }
1920 err = snd_usbmidi_create_rawmidi(umidi, out_ports, in_ports); 2022 err = snd_usbmidi_create_rawmidi(umidi, out_ports, in_ports);
1921 if (err < 0) { 2023 if (err < 0) {
@@ -1933,14 +2035,14 @@ int snd_usb_create_midi_interface(struct snd_usb_audio* chip,
1933 return err; 2035 return err;
1934 } 2036 }
1935 2037
1936 list_add(&umidi->list, &umidi->chip->midi_list); 2038 list_add_tail(&umidi->list, midi_list);
1937 2039
1938 for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) 2040 for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i)
1939 snd_usbmidi_input_start_ep(umidi->endpoints[i].in); 2041 snd_usbmidi_input_start_ep(umidi->endpoints[i].in);
1940 return 0; 2042 return 0;
1941} 2043}
1942 2044
1943EXPORT_SYMBOL(snd_usb_create_midi_interface); 2045EXPORT_SYMBOL(snd_usbmidi_create);
1944EXPORT_SYMBOL(snd_usbmidi_input_stop); 2046EXPORT_SYMBOL(snd_usbmidi_input_stop);
1945EXPORT_SYMBOL(snd_usbmidi_input_start); 2047EXPORT_SYMBOL(snd_usbmidi_input_start);
1946EXPORT_SYMBOL(snd_usbmidi_disconnect); 2048EXPORT_SYMBOL(snd_usbmidi_disconnect);