1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883
|
/*
* Line6 Linux USB driver - 0.7.3
*
* Copyright (C) 2004-2008 Markus Grabner (grabner@icg.tugraz.at)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, version 2.
*
*/
#include "config.h"
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/usb.h>
#include "audio.h"
#include "capture.h"
#include "control.h"
#include "driver.h"
#include "midi.h"
#include "playback.h"
#include "pod.h"
#include "usbdefs.h"
#include "variax.h"
#define DRIVER_AUTHOR "Markus Grabner <grabner@icg.tugraz.at>"
#define DRIVER_DESC "Line6 USB Driver"
#define DRIVER_VERSION "0.7.3"
/* table of devices that work with this driver */
static struct usb_device_id line6_id_table [] = {
{ USB_DEVICE(LINE6_VENDOR_ID, LINE6_DEVID_BASSPODXT) },
{ USB_DEVICE(LINE6_VENDOR_ID, LINE6_DEVID_BASSPODXTLIVE) },
{ USB_DEVICE(LINE6_VENDOR_ID, LINE6_DEVID_BASSPODXTPRO) },
{ USB_DEVICE(LINE6_VENDOR_ID, LINE6_DEVID_PODXT) },
{ USB_DEVICE(LINE6_VENDOR_ID, LINE6_DEVID_PODXTLIVE) },
{ USB_DEVICE(LINE6_VENDOR_ID, LINE6_DEVID_PODXTPRO) },
{ USB_DEVICE(LINE6_VENDOR_ID, LINE6_DEVID_POCKETPOD) },
{ USB_DEVICE(LINE6_VENDOR_ID, LINE6_DEVID_VARIAX) },
{ USB_DEVICE(LINE6_VENDOR_ID, LINE6_DEVID_TONEPORT_UX1) },
{ USB_DEVICE(LINE6_VENDOR_ID, LINE6_DEVID_TONEPORT_UX2) },
{ },
};
MODULE_DEVICE_TABLE (usb, line6_id_table);
static const char *line6_name_table[] = {
"BassPODxt",
"BassPODxt Live",
"BassPODxt Pro",
"PODxt",
"PODxt Live",
"PODxt Pro",
"Pocket POD",
"Variax Workbench",
"TonePort UX1",
"TonePort UX2",
0
};
static const int line6_bits_table[] = {
LINE6_BIT_BASSPODXT,
LINE6_BIT_BASSPODXTLIVE,
LINE6_BIT_BASSPODXTPRO,
LINE6_BIT_PODXT,
LINE6_BIT_PODXTLIVE,
LINE6_BIT_PODXTPRO,
LINE6_BIT_POCKETPOD,
LINE6_BIT_VARIAX,
LINE6_BIT_TONEPORT_UX1,
LINE6_BIT_TONEPORT_UX2,
0
};
/*
This is Line6's MIDI manufacturer ID.
*/
const unsigned char line6_midi_id[] = { 0x00, 0x01, 0x0c };
struct usb_line6 *line6_devices[LINE6_MAX_DEVICES];
struct workqueue_struct *line6_workqueue;
/**
Class for asynchronous messages.
*/
struct message
{
struct usb_line6 *line6;
const char *buffer;
int size;
int done;
};
/*
Forward declarations.
*/
static void line6_data_received(struct urb *urb PT_REGS);
static int line6_send_raw_message_async_part(struct message *msg, struct urb *urb);
/*
Start to listen on endpoint.
*/
static int line6_start_listen(struct usb_line6 *line6)
{
usb_fill_int_urb(line6->urb_listen,
line6->usbdev,
usb_rcvintpipe(line6->usbdev, line6->ep_control_read),
line6->buffer_listen, LINE6_BUFSIZE_LISTEN,
line6_data_received,
line6,
line6->interval);
line6->urb_listen->actual_length = 0;
return usb_submit_urb(line6->urb_listen, GFP_KERNEL);
}
#if DO_DUMP_URB_SEND || DO_DUMP_URB_RECEIVE
/*
Write hexdump to syslog.
*/
void line6_write_hexdump(struct usb_line6 *line6, char dir, const unsigned char *buffer, int size)
{
static const int BYTES_PER_LINE = 8;
char hexdump[100];
char asc[BYTES_PER_LINE + 1];
int i, j;
for(i = 0; i < size; i += BYTES_PER_LINE) {
int hexdumpsize = sizeof(hexdump);
char *p = hexdump;
int n = min(size - i, BYTES_PER_LINE);
asc[n] = 0;
for(j = 0; j < BYTES_PER_LINE; ++j) {
int bytes;
if(j < n) {
unsigned char val = buffer[i + j];
bytes = snprintf(p, hexdumpsize, " %02X", val);
asc[j] = ((val >= 0x20) && (val < 0x7f)) ? val : '.';
}
else
bytes = snprintf(p, hexdumpsize, " ");
if(bytes > hexdumpsize)
break; /* buffer overflow */
p += bytes;
hexdumpsize -= bytes;
}
dev_info(line6->ifcdev, "%c%04X:%s %s\n", dir, i, hexdump, asc);
}
}
#endif
#if DO_DUMP_URB_RECEIVE
/*
Dump URB data to syslog.
*/
static void line6_dump_urb(struct urb *urb)
{
struct usb_line6 *line6 = (struct usb_line6 *)urb->context;
if(urb->status < 0)
return;
line6_write_hexdump(line6, 'R', (unsigned char *)urb->transfer_buffer, urb->actual_length);
}
#endif
/*
Send raw message in pieces of wMaxPacketSize bytes.
*/
int line6_send_raw_message(struct usb_line6 *line6, const char *buffer, int size)
{
int i, done = 0;
#if DO_DUMP_URB_SEND
line6_write_hexdump(line6, 'S', buffer, size);
#endif
for(i = 0; i < size; i += line6->max_packet_size) {
int partial;
const char *frag_buf = buffer + i;
int frag_size = min(line6->max_packet_size, size - i);
int retval = usb_interrupt_msg(line6->usbdev,
usb_sndintpipe(line6->usbdev, line6->ep_control_write),
(char *)frag_buf, frag_size, &partial, LINE6_TIMEOUT * HZ);
if(retval) {
dev_err(line6->ifcdev, "usb_interrupt_msg failed (%d)\n", retval);
break;
}
done += frag_size;
}
return done;
}
/*
Notification of completion of asynchronous request transmission.
*/
static void line6_async_request_sent(struct urb *urb PT_REGS)
{
struct message *msg = (struct message *)urb->context;
if(msg->done >= msg->size) {
usb_free_urb(urb);
kfree(msg);
}
else
line6_send_raw_message_async_part(msg, urb);
}
/*
Asynchronously send part of a raw message.
*/
static int line6_send_raw_message_async_part(struct message *msg, struct urb *urb)
{
int retval;
struct usb_line6 *line6 = msg->line6;
int done = msg->done;
int bytes = min(msg->size - done, line6->max_packet_size);
usb_fill_int_urb(urb,
line6->usbdev,
usb_sndintpipe(line6->usbdev, line6->ep_control_write),
(char *)msg->buffer + done, bytes,
line6_async_request_sent, msg, line6->interval);
#if DO_DUMP_URB_SEND
line6_write_hexdump(line6, 'S', (char *)msg->buffer + done, bytes);
#endif
msg->done += bytes;
retval = usb_submit_urb(urb, GFP_ATOMIC);
if(retval < 0) {
dev_err(line6->ifcdev, "line6_send_raw_message_async: usb_submit_urb failed (%d)\n", retval);
usb_free_urb(urb);
kfree(msg);
return -EINVAL;
}
return 0;
}
/*
Asynchronously send raw message.
*/
int line6_send_raw_message_async(struct usb_line6 *line6, const char *buffer, int size)
{
struct message *msg;
struct urb *urb;
/* create message: */
msg = kmalloc(sizeof(struct message), GFP_ATOMIC);
if(msg == NULL) {
dev_err(line6->ifcdev, "Out of memory\n");
return -ENOMEM;
}
/* create URB: */
urb = usb_alloc_urb(0, GFP_ATOMIC);
if(urb == NULL) {
kfree(msg);
dev_err(line6->ifcdev, "Out of memory\n");
return -ENOMEM;
}
/* set message data: */
msg->line6 = line6;
msg->buffer = buffer;
msg->size = size;
msg->done = 0;
/* start sending: */
return line6_send_raw_message_async_part(msg, urb);
}
/*
Send sysex message in pieces of wMaxPacketSize bytes.
*/
int line6_send_sysex_message(struct usb_line6 *line6, const char *buffer, int size)
{
return line6_send_raw_message(line6, buffer, size + SYSEX_EXTRA_SIZE) - SYSEX_EXTRA_SIZE;
}
/*
Allocate buffer for sysex message and prepare header.
@param code sysex message code
@param size number of bytes between code and sysex end
*/
char *line6_alloc_sysex_buffer(struct usb_line6 *line6, int code1, int code2, int size)
{
char *buffer = kmalloc(size + SYSEX_EXTRA_SIZE, GFP_KERNEL);
if(!buffer) {
dev_err(line6->ifcdev, "out of memory\n");
return 0;
}
buffer[0] = LINE6_SYSEX_BEGIN;
memcpy(buffer + 1, line6_midi_id, sizeof(line6_midi_id));
buffer[sizeof(line6_midi_id) + 1] = code1;
buffer[sizeof(line6_midi_id) + 2] = code2;
buffer[sizeof(line6_midi_id) + 3 + size] = LINE6_SYSEX_END;
return buffer;
}
/*
Notification of data received from the Line6 device.
*/
static void line6_data_received(struct urb *urb PT_REGS)
{
struct usb_line6 *line6 = (struct usb_line6 *)urb->context;
struct MidiBuffer *mb = &line6->midi->midibuf_in;
int done;
if(urb->status == -ESHUTDOWN)
return;
#if DO_DUMP_URB_RECEIVE
line6_dump_urb(urb);
#endif
done = midibuf_write(mb, urb->transfer_buffer, urb->actual_length);
if(done < urb->actual_length) {
midibuf_ignore(mb, done);
DEBUG_MESSAGES(dev_err(line6->ifcdev, "%d %d buffer overflow - message skipped\n", done, urb->actual_length));
}
for(;;) {
done = midibuf_read(mb, line6->buffer_message, LINE6_MESSAGE_MAXLEN);
if(done == 0)
break;
/* MIDI input filter */
if(midibuf_skip_message(mb, line6->midi->midi_mask_receive))
continue;
line6->message_length = done;
#if DO_DUMP_MIDI_RECEIVE
line6_write_hexdump(line6, 'r', line6->buffer_message, done);
#endif
line6_midi_receive(line6, line6->buffer_message, done);
switch(line6->usbdev->descriptor.idProduct) {
case LINE6_DEVID_BASSPODXT:
case LINE6_DEVID_BASSPODXTLIVE:
case LINE6_DEVID_BASSPODXTPRO:
case LINE6_DEVID_PODXT:
case LINE6_DEVID_PODXTPRO:
case LINE6_DEVID_POCKETPOD:
pod_process_message((struct usb_line6_pod *)line6);
break;
case LINE6_DEVID_PODXTLIVE:
switch(line6->interface_number) {
case PODXTLIVE_INTERFACE_POD:
pod_process_message((struct usb_line6_pod *)line6);
break;
case PODXTLIVE_INTERFACE_VARIAX:
variax_process_message((struct usb_line6_variax *)line6);
break;
default:
dev_err(line6->ifcdev, "PODxt Live interface %d not supported\n", line6->interface_number);
}
break;
case LINE6_DEVID_VARIAX:
variax_process_message((struct usb_line6_variax *)line6);
break;
}
}
line6_start_listen(line6);
}
/*
Send channel number (i.e., switch to a different sound).
*/
int line6_send_program(struct usb_line6 *line6, int value)
{
int retval;
unsigned char *buffer;
unsigned int partial;
buffer = kmalloc(2, GFP_KERNEL);
if(!buffer) {
dev_err(line6->ifcdev, "out of memory\n");
return -ENOMEM;
}
buffer[0] = LINE6_PROGRAM_CHANGE | LINE6_CHANNEL_HOST;
buffer[1] = value;
#if DO_DUMP_URB_SEND
line6_write_hexdump(line6, 'S', buffer, 2);
#endif
retval = usb_interrupt_msg(line6->usbdev,
usb_sndintpipe(line6->usbdev, line6->ep_control_write),
buffer, 2, &partial, LINE6_TIMEOUT * HZ);
if(retval)
dev_err(line6->ifcdev, "usb_interrupt_msg failed (%d)\n", retval);
kfree(buffer);
return retval;
}
/*
Transmit Line6 control parameter.
*/
int line6_transmit_parameter(struct usb_line6 *line6, int param, int value)
{
int retval;
unsigned char *buffer;
unsigned int partial;
buffer = kmalloc(3, GFP_KERNEL);
if(!buffer) {
dev_err(line6->ifcdev, "out of memory\n");
return -ENOMEM;
}
buffer[0] = LINE6_PARAM_CHANGE | LINE6_CHANNEL_HOST;
buffer[1] = param;
buffer[2] = value;
#if DO_DUMP_URB_SEND
line6_write_hexdump(line6, 'S', buffer, 3);
#endif
retval = usb_interrupt_msg(line6->usbdev,
usb_sndintpipe(line6->usbdev, line6->ep_control_write),
buffer, 3, &partial, LINE6_TIMEOUT * HZ);
if(retval)
dev_err(line6->ifcdev, "usb_interrupt_msg failed (%d)\n", retval);
kfree(buffer);
return retval;
}
/*
No operation (i.e., unsupported).
*/
ssize_t line6_nop_read(struct device *dev, DEVICE_ATTRIBUTE char *buf)
{
return 0;
}
/*
No operation (i.e., unsupported).
*/
ssize_t line6_nop_write(struct device *dev, DEVICE_ATTRIBUTE const char *buf, size_t count)
{
return count;
}
/*
"write" request on "raw" special file.
*/
#if CREATE_RAW_FILE
ssize_t line6_set_raw(struct device *dev, DEVICE_ATTRIBUTE const char *buf, size_t count)
{
struct usb_interface *interface = to_usb_interface(dev);
struct usb_line6 *line6 = usb_get_intfdata(interface);
line6_send_raw_message(line6, buf, count);
return count;
}
#endif
/*
Generic destructor.
*/
static void line6_destruct(struct usb_interface *interface)
{
struct usb_line6 *line6;
if(interface == NULL) return;
line6 = usb_get_intfdata(interface);
if(line6 == NULL) return;
/* free buffer memory first: */
if(line6->buffer_message != NULL) kfree(line6->buffer_message);
if(line6->buffer_listen != NULL) kfree(line6->buffer_listen);
/* then free URBs: */
if(line6->urb_listen != NULL) usb_free_urb(line6->urb_listen);
/* make sure the device isn't destructed twice: */
usb_set_intfdata(interface, NULL);
/* free interface data: */
kfree(line6);
}
static void line6_list_devices(void)
{
int i;
for(i = 0; i < LINE6_MAX_DEVICES; ++i) {
struct usb_line6 *dev = line6_devices[i];
printk(KERN_INFO "Line6 device %d: ", i);
if(dev == NULL)
printk("(not used)\n");
else
printk("%s:%d\n", dev->devname, dev->interface_number);
}
}
/*
Probe USB device.
*/
static int line6_probe(struct usb_interface *interface, const struct usb_device_id *id)
{
int devtype;
const char *devname;
struct usb_device *usbdev = 0;
struct usb_line6 *line6 = 0;
int devnum;
int interface_number, alternate;
int product;
int size = 0;
int ep_read = 0, ep_write = 0;
int ret;
if(interface == NULL) return -ENODEV;
usbdev = interface_to_usbdev(interface);
if(usbdev == NULL) return -ENODEV;
/* increment reference counters: */
usb_get_intf(interface);
usb_get_dev(usbdev);
/* we don't handle multiple configurations */
if(usbdev->descriptor.bNumConfigurations != 1)
return -ENODEV;
/* check vendor and product id */
for(devtype = sizeof(line6_id_table) / sizeof(line6_id_table[0]) - 1; devtype--;)
if((le16_to_cpu(usbdev->descriptor.idVendor) == line6_id_table[devtype].idVendor) &&
(le16_to_cpu(usbdev->descriptor.idProduct) == line6_id_table[devtype].idProduct))
break;
if(devtype < 0)
return -ENODEV;
/* query interface number */
interface_number = interface->cur_altsetting->desc.bInterfaceNumber;
/* find free slot in device table: */
for(devnum = 0; devnum < LINE6_MAX_DEVICES; ++devnum)
if(line6_devices[devnum] == NULL)
break;
if(devnum == LINE6_MAX_DEVICES)
return -ENODEV;
/* initialize device info: */
devname = line6_name_table[devtype];
dev_info(&interface->dev, "Line6 %s found\n", devname);
product = le16_to_cpu(usbdev->descriptor.idProduct);
switch(product) {
case LINE6_DEVID_PODXTLIVE:
case LINE6_DEVID_BASSPODXTLIVE:
case LINE6_DEVID_VARIAX:
alternate = 1;
break;
default:
alternate = 5;
}
if((ret = usb_set_interface(usbdev, interface_number, alternate)) < 0) {
dev_err(&interface->dev, "set_interface failed\n");
return ret;
}
/* initialize device data: */
switch(product) {
case LINE6_DEVID_BASSPODXT:
case LINE6_DEVID_BASSPODXTLIVE:
case LINE6_DEVID_BASSPODXTPRO:
case LINE6_DEVID_PODXT:
case LINE6_DEVID_PODXTPRO:
case LINE6_DEVID_POCKETPOD:
size = sizeof(struct usb_line6_pod);
ep_read = POD_EP_READ_MIDI;
ep_write = POD_EP_WRITE_MIDI;
break;
case LINE6_DEVID_PODXTLIVE:
switch(interface_number) {
case PODXTLIVE_INTERFACE_POD:
size = sizeof(struct usb_line6_pod);
ep_read = POD_EP_READ_MIDI;
ep_write = POD_EP_WRITE_MIDI;
break;
case PODXTLIVE_INTERFACE_VARIAX:
size = sizeof(struct usb_line6_variax);
ep_read = PODXTLIVE_VARIAX_EP_READ_MIDI;
ep_write = PODXTLIVE_VARIAX_EP_WRITE_MIDI;
break;
default:
return -ENODEV;
}
break;
case LINE6_DEVID_VARIAX:
size = sizeof(struct usb_line6_variax);
ep_read = VARIAX_EP_READ_MIDI;
ep_write = VARIAX_EP_WRITE_MIDI;
break;
default:
return -ENODEV;
}
if(size == 0) {
dev_err(line6->ifcdev, "driver bug: interface data size not set\n");
return -ENODEV;
}
line6 = kzalloc(size, GFP_KERNEL);
if(line6 == NULL) {
dev_err(&interface->dev, "Out of memory\n");
return -ENOMEM;
}
/* store basic data: */
line6->interface_number = interface_number;
line6->devname = devname;
line6->devbit = line6_bits_table[devtype];
line6->usbdev = usbdev;
line6->ifcdev = &interface->dev;
line6->ep_control_read = ep_read;
line6->ep_control_write = ep_write;
/* get data from endpoint descriptor (see usb_maxpacket): */
{
struct usb_host_endpoint *ep;
unsigned epnum = usb_pipeendpoint(usb_rcvintpipe(usbdev, ep_read));
ep = usbdev->ep_in[epnum];
if(ep != NULL) {
line6->interval = ep->desc.bInterval;
line6->max_packet_size = le16_to_cpu(ep->desc.wMaxPacketSize);
}
else {
line6->interval = LINE6_FALLBACK_INTERVAL;
line6->max_packet_size = LINE6_FALLBACK_MAXPACKETSIZE;
dev_err(line6->ifcdev, "endpoint not available, using fallback values");
}
}
usb_set_intfdata(interface, line6);
/* initialize USB buffers: */
line6->buffer_listen = kmalloc(LINE6_BUFSIZE_LISTEN, GFP_KERNEL);
if(line6->buffer_listen == NULL) {
dev_err(&interface->dev, "Out of memory\n");
line6_destruct(interface);
return -ENOMEM;
}
line6->buffer_message = kmalloc(LINE6_MESSAGE_MAXLEN, GFP_KERNEL);
if(line6->buffer_message == NULL) {
dev_err(&interface->dev, "Out of memory\n");
line6_destruct(interface);
return -ENOMEM;
}
line6->urb_listen = usb_alloc_urb(0, GFP_KERNEL);
if(line6->urb_listen == NULL) {
dev_err(&interface->dev, "Out of memory\n");
line6_destruct(interface);
return -ENOMEM;
}
if((ret = line6_start_listen(line6)) < 0) {
dev_err(&interface->dev, " line6_probe: usb_submit_urb failed\n");
line6_destruct(interface);
return ret;
}
switch(product) {
case LINE6_DEVID_BASSPODXT:
case LINE6_DEVID_BASSPODXTLIVE:
case LINE6_DEVID_BASSPODXTPRO:
case LINE6_DEVID_PODXT:
case LINE6_DEVID_PODXTPRO:
case LINE6_DEVID_POCKETPOD:
ret = pod_init(interface, (struct usb_line6_pod *)line6);
break;
case LINE6_DEVID_PODXTLIVE:
switch(interface_number) {
case PODXTLIVE_INTERFACE_POD:
ret = pod_init(interface, (struct usb_line6_pod *)line6);
break;
case PODXTLIVE_INTERFACE_VARIAX:
ret = variax_init(interface, (struct usb_line6_variax *)line6);
break;
default:
dev_err(&interface->dev, "PODxt Live interface %d not supported\n", interface_number);
ret = -ENODEV;
}
break;
case LINE6_DEVID_VARIAX:
ret = variax_init(interface, (struct usb_line6_variax *)line6);
break;
default:
dev_err(&interface->dev, "Line6 product %04x not supported\n", product);
ret = -ENODEV;
}
if(ret < 0) {
line6_destruct(interface);
return ret;
}
if((ret = sysfs_create_link(&interface->dev.kobj, &usbdev->dev.kobj, "usb_device")) < 0) {
line6_destruct(interface);
return ret;
}
dev_info(&interface->dev, "Line6 %s now attached\n", line6->devname);
line6_devices[devnum] = line6;
line6_list_devices();
return ret;
}
/*
Line6 device disconnected.
*/
static void line6_disconnect(struct usb_interface *interface)
{
struct usb_line6 *line6;
struct usb_device *usbdev;
int interface_number, i;
if(interface == NULL) return;
usbdev = interface_to_usbdev(interface);
if(usbdev == NULL) return;
sysfs_remove_link(&interface->dev.kobj, "usb_device");
interface_number = interface->cur_altsetting->desc.bInterfaceNumber;
line6 = usb_get_intfdata(interface);
if(line6 != NULL) {
if(line6->urb_listen != NULL) usb_kill_urb(line6->urb_listen);
if(usbdev != line6->usbdev)
dev_err(line6->ifcdev, "driver bug: inconsistent usb device\n");
switch(line6->usbdev->descriptor.idProduct) {
case LINE6_DEVID_BASSPODXT:
case LINE6_DEVID_BASSPODXTLIVE:
case LINE6_DEVID_BASSPODXTPRO:
case LINE6_DEVID_PODXT:
case LINE6_DEVID_PODXTPRO:
case LINE6_DEVID_POCKETPOD:
pod_disconnect(interface);
break;
case LINE6_DEVID_PODXTLIVE:
switch(interface_number) {
case PODXTLIVE_INTERFACE_POD:
pod_disconnect(interface);
break;
case PODXTLIVE_INTERFACE_VARIAX:
variax_disconnect(interface);
break;
}
break;
case LINE6_DEVID_VARIAX:
variax_disconnect(interface);
break;
}
dev_info(&interface->dev, "Line6 %s now disconnected\n", line6->devname);
for(i = LINE6_MAX_DEVICES; i--;)
if(line6_devices[i] == line6)
line6_devices[i] = 0;
}
line6_destruct(interface);
/* decrement reference counters: */
usb_put_intf(interface);
usb_put_dev(usbdev);
line6_list_devices();
}
static struct usb_driver line6_driver = {
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 16)
.owner = THIS_MODULE,
#endif
.name = DRIVER_NAME,
.probe = line6_probe,
.disconnect = line6_disconnect,
.id_table = line6_id_table,
};
/*
Module initialization.
*/
static int __init line6_init(void)
{
int i, retval;
line6_workqueue = create_workqueue(DRIVER_NAME);
if(line6_workqueue == 0) {
err("couldn't create workqueue");
return -EINVAL;
}
for(i = LINE6_MAX_DEVICES; i--;)
line6_devices[i] = 0;
retval = usb_register(&line6_driver);
if(retval)
err("usb_register failed. Error number %d", retval);
return retval;
}
/*
Module cleanup.
*/
static void __exit line6_exit(void)
{
destroy_workqueue(line6_workqueue);
usb_deregister(&line6_driver);
}
module_init(line6_init);
module_exit(line6_exit);
MODULE_AUTHOR(DRIVER_AUTHOR);
MODULE_DESCRIPTION(DRIVER_DESC);
MODULE_LICENSE("GPL");
MODULE_VERSION(DRIVER_VERSION);
|