12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/slab.h>
31 #define DRIVER_DESC "Line6 USB Driver"
32 #define DRIVER_VERSION "0.9.1beta" DRIVER_REVISION
65 { LINE6_BIT_GUITARPORT,
"GuitarPort",
"GuitarPort",
LINE6_BIT_PCM },
69 { LINE6_BIT_PODSTUDIO_GX,
"PODStudioGX",
"POD Studio GX",
LINE6_BIT_PCM },
70 { LINE6_BIT_PODSTUDIO_UX1,
"PODStudioUX1",
"POD Studio UX1",
LINE6_BIT_PCM },
71 { LINE6_BIT_PODSTUDIO_UX2,
"PODStudioUX2",
"POD Studio UX2",
LINE6_BIT_PCM },
73 { LINE6_BIT_PODX3LIVE,
"PODX3Live",
"POD X3 Live",
LINE6_BIT_PCM },
77 { LINE6_BIT_TONEPORT_GX,
"TonePortGX",
"TonePort GX",
LINE6_BIT_PCM },
78 { LINE6_BIT_TONEPORT_UX1,
"TonePortUX1",
"TonePort UX1",
LINE6_BIT_PCM },
79 { LINE6_BIT_TONEPORT_UX2,
"TonePortUX2",
"TonePort UX2",
LINE6_BIT_PCM },
95 static const char line6_request_version[] = {
96 0xf0, 0x7e, 0x7f, 0x06, 0x01, 0xf7
114 static void line6_data_received(
struct urb *
urb);
115 static int line6_send_raw_message_async_part(
struct message *
msg,
121 static int line6_start_listen(
struct usb_line6 *line6)
127 line6_data_received, line6, line6->
interval);
136 static void line6_stop_listen(
struct usb_line6 *line6)
141 #ifdef CONFIG_LINE6_USB_DUMP_ANY
145 void line6_write_hexdump(
struct usb_line6 *line6,
char dir,
148 static const int BYTES_PER_LINE = 8;
150 char asc[BYTES_PER_LINE + 1];
153 for (i = 0; i <
size; i += BYTES_PER_LINE) {
154 int hexdumpsize =
sizeof(hexdump);
156 int n =
min(size - i, BYTES_PER_LINE);
159 for (j = 0; j < BYTES_PER_LINE; ++
j) {
163 unsigned char val = buffer[i +
j];
164 bytes =
snprintf(p, hexdumpsize,
" %02X", val);
165 asc[
j] = ((val >= 0x20)
166 && (val < 0x7f)) ? val :
'.';
168 bytes =
snprintf(p, hexdumpsize,
" ");
170 if (bytes > hexdumpsize)
174 hexdumpsize -=
bytes;
182 #ifdef CONFIG_LINE6_USB_DUMP_CTRL
186 static void line6_dump_urb(
struct urb *
urb)
193 line6_write_hexdump(line6,
'R', (
unsigned char *)urb->transfer_buffer,
206 #ifdef CONFIG_LINE6_USB_DUMP_CTRL
207 line6_write_hexdump(line6,
'S', buffer, size);
212 const char *frag_buf = buffer +
i;
217 usb_sndintpipe(line6->
usbdev,
219 (
char *)frag_buf, frag_size,
224 "usb_interrupt_msg failed (%d)\n", retval);
237 static void line6_async_request_sent(
struct urb *urb)
245 line6_send_raw_message_async_part(msg, urb);
251 static int line6_send_raw_message_async_part(
struct message *msg,
259 usb_fill_int_urb(urb, line6->
usbdev,
261 (
char *)msg->
buffer + done, bytes,
262 line6_async_request_sent, msg, line6->
interval);
264 #ifdef CONFIG_LINE6_USB_DUMP_CTRL
265 line6_write_hexdump(line6,
'S', (
char *)msg->
buffer + done, bytes);
286 void (*
function) (
unsigned long),
unsigned long data)
326 return line6_send_raw_message_async_part(msg, urb);
338 if (buffer ==
NULL) {
343 memcpy(buffer, line6_request_version,
sizeof(line6_request_version));
346 sizeof(line6_request_version));
358 size + SYSEX_EXTRA_SIZE) -
369 size + SYSEX_EXTRA_SIZE) -
399 static void line6_data_received(
struct urb *urb)
408 #ifdef CONFIG_LINE6_USB_DUMP_CTRL
415 if (done < urb->actual_length) {
419 "%d %d buffer overflow - message skipped\n",
420 done, urb->actual_length));
437 #ifdef CONFIG_LINE6_USB_DUMP_MIDI
442 switch (line6->
usbdev->descriptor.idProduct) {
472 "PODxt Live interface %d not supported\n",
487 line6_start_listen(line6);
509 #ifdef CONFIG_LINE6_USB_DUMP_CTRL
510 line6_write_hexdump(line6,
'S', buffer, 2);
514 usb_sndintpipe(line6->
usbdev,
546 #ifdef CONFIG_LINE6_USB_DUMP_CTRL
547 line6_write_hexdump(line6,
'S', buffer, 3);
551 usb_sndintpipe(line6->
usbdev,
569 struct usb_device *usbdev = line6->
usbdev;
576 (datalen << 8) | 0x21, address,
580 dev_err(line6->
ifcdev,
"read request failed (error %d)\n", ret);
589 0x0012, 0x0000, &len, 1,
593 "receive length failed (error %d)\n", ret);
596 }
while (len == 0xff);
598 if (len != datalen) {
601 "length mismatch (expected %d, got %d)\n",
602 (
int)datalen, (
int)len);
609 0x0013, 0x0000, data, datalen,
626 struct usb_device *usbdev = line6->
usbdev;
632 0x0022, address, data, datalen,
637 "write request failed (error %d)\n", ret);
651 "receiving status failed (error %d)\n", ret);
654 }
while (status == 0xff);
671 sizeof(*serial_number));
695 #ifdef CONFIG_LINE6_USB_RAW
713 if (interface ==
NULL)
715 line6 = usb_get_intfdata(interface);
727 usb_set_intfdata(interface,
NULL);
740 struct usb_device *usbdev;
747 int ep_read = 0, ep_write = 0;
750 if (interface ==
NULL)
752 usbdev = interface_to_usbdev(interface);
757 if (usbdev->descriptor.bNumConfigurations != 1) {
763 for (devtype =
ARRAY_SIZE(line6_id_table) - 1; devtype--;) {
767 if (idVendor == line6_id_table[devtype].idVendor &&
768 idProduct == line6_id_table[devtype].idProduct)
779 if (line6_devices[devnum] ==
NULL)
782 if (devnum == LINE6_MAX_DEVICES) {
788 properties = &line6_properties_table[devtype];
789 dev_info(&interface->dev,
"Line6 %s found\n", properties->
name);
790 product =
le16_to_cpu(usbdev->descriptor.idProduct);
793 interface_number = interface->cur_altsetting->desc.bInterfaceNumber;
803 switch (interface_number) {
817 switch (interface_number) {
847 switch (interface_number) {
871 dev_err(&interface->dev,
"set_interface failed\n");
925 switch (interface_number) {
958 "driver bug: interface data size not set\n");
966 dev_err(&interface->dev,
"Out of memory\n");
975 line6->
ifcdev = &interface->dev;
982 struct usb_host_endpoint *ep;
984 usb_pipeendpoint(usb_rcvintpipe(usbdev, ep_read));
985 ep = usbdev->ep_in[epnum];
988 line6->
interval = ep->desc.bInterval;
995 "endpoint not available, using fallback values");
999 usb_set_intfdata(interface, line6);
1007 dev_err(&interface->dev,
"Out of memory\n");
1016 dev_err(&interface->dev,
"Out of memory\n");
1024 dev_err(&interface->dev,
"Out of memory\n");
1025 line6_destruct(interface);
1030 ret = line6_start_listen(line6);
1032 dev_err(&interface->dev,
"%s: usb_submit_urb failed\n",
1058 switch (interface_number) {
1073 "PODxt Live interface %d not supported\n",
1113 dev_info(&interface->dev,
"Line6 %s now attached\n",
1115 line6_devices[
devnum] = line6;
1121 "NOTE: the Line6 %s is detected, but not yet supported\n",
1132 line6_destruct(interface);
1140 static void line6_disconnect(
struct usb_interface *interface)
1143 struct usb_device *usbdev;
1144 int interface_number,
i;
1146 if (interface ==
NULL)
1148 usbdev = interface_to_usbdev(interface);
1156 interface_number = interface->cur_altsetting->desc.bInterfaceNumber;
1157 line6 = usb_get_intfdata(interface);
1159 if (line6 !=
NULL) {
1161 line6_stop_listen(line6);
1163 if (usbdev != line6->
usbdev)
1165 "driver bug: inconsistent usb device\n");
1167 switch (line6->
usbdev->descriptor.idProduct) {
1185 switch (interface_number) {
1215 dev_info(&interface->dev,
"Line6 %s now disconnected\n",
1218 for (i = LINE6_MAX_DEVICES; i--;)
1219 if (line6_devices[i] == line6)
1220 line6_devices[
i] =
NULL;
1223 line6_destruct(interface);
1237 struct usb_line6 *line6 = usb_get_intfdata(interface);
1243 line6_stop_listen(line6);
1245 if (line6pcm !=
NULL) {
1246 snd_pcm_suspend_all(line6pcm->
pcm);
1248 line6pcm->
flags = 0;
1259 struct usb_line6 *line6 = usb_get_intfdata(interface);
1262 line6_start_listen(line6);
1271 static int line6_reset_resume(
struct usb_interface *interface)
1273 struct usb_line6 *line6 = usb_get_intfdata(interface);
1275 switch (line6->
usbdev->descriptor.idProduct) {
1286 return line6_resume(interface);
1291 static struct usb_driver line6_driver = {
1293 .probe = line6_probe,
1294 .disconnect = line6_disconnect,
1296 .suspend = line6_suspend,
1297 .resume = line6_resume,
1298 .reset_resume = line6_reset_resume,
1300 .id_table = line6_id_table,