2 * Line6 Linux USB driver - 0.9.1beta
4 * Copyright (C) 2004-2010 Markus Grabner (grabner@icg.tugraz.at)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2.
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/slab.h>
15 #include <linux/usb.h>
29 #define DRIVER_AUTHOR "Markus Grabner <grabner@icg.tugraz.at>"
30 #define DRIVER_DESC "Line6 USB Driver"
31 #define DRIVER_VERSION "0.9.1beta" DRIVER_REVISION
33 /* table of devices that work with this driver */
34 static const struct usb_device_id line6_id_table
[] = {
35 {USB_DEVICE(LINE6_VENDOR_ID
, LINE6_DEVID_BASSPODXT
)},
36 {USB_DEVICE(LINE6_VENDOR_ID
, LINE6_DEVID_BASSPODXTLIVE
)},
37 {USB_DEVICE(LINE6_VENDOR_ID
, LINE6_DEVID_BASSPODXTPRO
)},
38 {USB_DEVICE(LINE6_VENDOR_ID
, LINE6_DEVID_GUITARPORT
)},
39 {USB_DEVICE(LINE6_VENDOR_ID
, LINE6_DEVID_POCKETPOD
)},
40 {USB_DEVICE(LINE6_VENDOR_ID
, LINE6_DEVID_PODSTUDIO_GX
)},
41 {USB_DEVICE(LINE6_VENDOR_ID
, LINE6_DEVID_PODSTUDIO_UX1
)},
42 {USB_DEVICE(LINE6_VENDOR_ID
, LINE6_DEVID_PODSTUDIO_UX2
)},
43 {USB_DEVICE(LINE6_VENDOR_ID
, LINE6_DEVID_PODX3
)},
44 {USB_DEVICE(LINE6_VENDOR_ID
, LINE6_DEVID_PODX3LIVE
)},
45 {USB_DEVICE(LINE6_VENDOR_ID
, LINE6_DEVID_PODXT
)},
46 {USB_DEVICE(LINE6_VENDOR_ID
, LINE6_DEVID_PODXTLIVE
)},
47 {USB_DEVICE(LINE6_VENDOR_ID
, LINE6_DEVID_PODXTPRO
)},
48 {USB_DEVICE(LINE6_VENDOR_ID
, LINE6_DEVID_TONEPORT_GX
)},
49 {USB_DEVICE(LINE6_VENDOR_ID
, LINE6_DEVID_TONEPORT_UX1
)},
50 {USB_DEVICE(LINE6_VENDOR_ID
, LINE6_DEVID_TONEPORT_UX2
)},
51 {USB_DEVICE(LINE6_VENDOR_ID
, LINE6_DEVID_VARIAX
)},
55 MODULE_DEVICE_TABLE(usb
, line6_id_table
);
58 static struct line6_properties line6_properties_table
[] = {
59 { "BassPODxt", "BassPODxt", LINE6_BIT_BASSPODXT
, LINE6_BIT_CONTROL_PCM_HWMON
},
60 { "BassPODxtLive", "BassPODxt Live", LINE6_BIT_BASSPODXTLIVE
, LINE6_BIT_CONTROL_PCM_HWMON
},
61 { "BassPODxtPro", "BassPODxt Pro", LINE6_BIT_BASSPODXTPRO
, LINE6_BIT_CONTROL_PCM_HWMON
},
62 { "GuitarPort", "GuitarPort", LINE6_BIT_GUITARPORT
, LINE6_BIT_PCM
},
63 { "PocketPOD", "Pocket POD", LINE6_BIT_POCKETPOD
, LINE6_BIT_CONTROL
},
64 { "PODStudioGX", "POD Studio GX", LINE6_BIT_PODSTUDIO_GX
, LINE6_BIT_PCM
},
65 { "PODStudioUX1", "POD Studio UX1", LINE6_BIT_PODSTUDIO_UX1
, LINE6_BIT_PCM
},
66 { "PODStudioUX2", "POD Studio UX2", LINE6_BIT_PODSTUDIO_UX2
, LINE6_BIT_PCM
},
67 { "PODX3", "POD X3", LINE6_BIT_PODX3
, LINE6_BIT_PCM
},
68 { "PODX3Live", "POD X3 Live", LINE6_BIT_PODX3LIVE
, LINE6_BIT_PCM
},
69 { "PODxt", "PODxt", LINE6_BIT_PODXT
, LINE6_BIT_CONTROL_PCM_HWMON
},
70 { "PODxtLive", "PODxt Live", LINE6_BIT_PODXTLIVE
, LINE6_BIT_CONTROL_PCM_HWMON
},
71 { "PODxtPro", "PODxt Pro", LINE6_BIT_PODXTPRO
, LINE6_BIT_CONTROL_PCM_HWMON
},
72 { "TonePortGX", "TonePort GX", LINE6_BIT_TONEPORT_GX
, LINE6_BIT_PCM
},
73 { "TonePortUX1", "TonePort UX1", LINE6_BIT_TONEPORT_UX1
, LINE6_BIT_PCM
},
74 { "TonePortUX2", "TonePort UX2", LINE6_BIT_TONEPORT_UX2
, LINE6_BIT_PCM
},
75 { "Variax", "Variax Workbench", LINE6_BIT_VARIAX
, LINE6_BIT_CONTROL
}
80 This is Line6's MIDI manufacturer ID.
82 const unsigned char line6_midi_id
[] = {
87 Code to request version of POD, Variax interface
88 (and maybe other devices).
90 static const char line6_request_version0
[] = {
91 0xf0, 0x7e, 0x7f, 0x06, 0x01, 0xf7
95 Copy of version request code with GFP_KERNEL flag for use in URB.
97 static const char *line6_request_version
;
99 struct usb_line6
*line6_devices
[LINE6_MAX_DEVICES
];
102 Class for asynchronous messages.
105 struct usb_line6
*line6
;
112 Forward declarations.
114 static void line6_data_received(struct urb
*urb
);
115 static int line6_send_raw_message_async_part(struct message
*msg
,
119 Start to listen on endpoint.
121 static int line6_start_listen(struct usb_line6
*line6
)
124 usb_fill_int_urb(line6
->urb_listen
, line6
->usbdev
,
125 usb_rcvintpipe(line6
->usbdev
, line6
->ep_control_read
),
126 line6
->buffer_listen
, LINE6_BUFSIZE_LISTEN
,
127 line6_data_received
, line6
, line6
->interval
);
128 line6
->urb_listen
->actual_length
= 0;
129 err
= usb_submit_urb(line6
->urb_listen
, GFP_ATOMIC
);
134 Stop listening on endpoint.
136 static void line6_stop_listen(struct usb_line6
*line6
)
138 usb_kill_urb(line6
->urb_listen
);
141 #ifdef CONFIG_LINE6_USB_DUMP_ANY
143 Write hexdump to syslog.
145 void line6_write_hexdump(struct usb_line6
*line6
, char dir
,
146 const unsigned char *buffer
, int size
)
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
)
171 break; /* buffer overflow */
174 hexdumpsize
-= bytes
;
177 dev_info(line6
->ifcdev
, "%c%04X:%s %s\n", dir
, i
, hexdump
, asc
);
182 #ifdef CONFIG_LINE6_USB_DUMP_CTRL
184 Dump URB data to syslog.
186 static void line6_dump_urb(struct urb
*urb
)
188 struct usb_line6
*line6
= (struct usb_line6
*)urb
->context
;
193 line6_write_hexdump(line6
, 'R', (unsigned char *)urb
->transfer_buffer
,
199 Send raw message in pieces of wMaxPacketSize bytes.
201 int line6_send_raw_message(struct usb_line6
*line6
, const char *buffer
,
206 #ifdef CONFIG_LINE6_USB_DUMP_CTRL
207 line6_write_hexdump(line6
, 'S', buffer
, size
);
210 for (i
= 0; i
< size
; i
+= line6
->max_packet_size
) {
212 const char *frag_buf
= buffer
+ i
;
213 int frag_size
= min(line6
->max_packet_size
, size
- i
);
216 retval
= usb_interrupt_msg(line6
->usbdev
,
217 usb_sndintpipe(line6
->usbdev
,
218 line6
->ep_control_write
),
219 (char *)frag_buf
, frag_size
,
220 &partial
, LINE6_TIMEOUT
* HZ
);
223 dev_err(line6
->ifcdev
,
224 "usb_interrupt_msg failed (%d)\n", retval
);
235 Notification of completion of asynchronous request transmission.
237 static void line6_async_request_sent(struct urb
*urb
)
239 struct message
*msg
= (struct message
*)urb
->context
;
241 if (msg
->done
>= msg
->size
) {
245 line6_send_raw_message_async_part(msg
, urb
);
249 Asynchronously send part of a raw message.
251 static int line6_send_raw_message_async_part(struct message
*msg
,
255 struct usb_line6
*line6
= msg
->line6
;
256 int done
= msg
->done
;
257 int bytes
= min(msg
->size
- done
, line6
->max_packet_size
);
259 usb_fill_int_urb(urb
, line6
->usbdev
,
260 usb_sndintpipe(line6
->usbdev
, line6
->ep_control_write
),
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
);
269 retval
= usb_submit_urb(urb
, GFP_ATOMIC
);
272 dev_err(line6
->ifcdev
, "%s: usb_submit_urb failed (%d)\n",
283 Setup and start timer.
285 void line6_start_timer(struct timer_list
*timer
, unsigned int msecs
,
286 void (*function
) (unsigned long), unsigned long data
)
288 setup_timer(timer
, function
, data
);
289 timer
->expires
= jiffies
+ msecs
* HZ
/ 1000;
294 Asynchronously send raw message.
296 int line6_send_raw_message_async(struct usb_line6
*line6
, const char *buffer
,
302 /* create message: */
303 msg
= kmalloc(sizeof(struct message
), GFP_ATOMIC
);
306 dev_err(line6
->ifcdev
, "Out of memory\n");
311 urb
= usb_alloc_urb(0, GFP_ATOMIC
);
315 dev_err(line6
->ifcdev
, "Out of memory\n");
319 /* set message data: */
321 msg
->buffer
= buffer
;
326 return line6_send_raw_message_async_part(msg
, urb
);
330 Send asynchronous device version request.
332 int line6_version_request_async(struct usb_line6
*line6
)
334 return line6_send_raw_message_async(line6
, line6_request_version
,
335 sizeof(line6_request_version0
));
339 Send sysex message in pieces of wMaxPacketSize bytes.
341 int line6_send_sysex_message(struct usb_line6
*line6
, const char *buffer
,
344 return line6_send_raw_message(line6
, buffer
,
345 size
+ SYSEX_EXTRA_SIZE
) -
350 Send sysex message in pieces of wMaxPacketSize bytes.
352 int line6_send_sysex_message_async(struct usb_line6
*line6
, const char *buffer
,
355 return line6_send_raw_message_async(line6
, buffer
,
356 size
+ SYSEX_EXTRA_SIZE
) -
361 Allocate buffer for sysex message and prepare header.
362 @param code sysex message code
363 @param size number of bytes between code and sysex end
365 char *line6_alloc_sysex_buffer(struct usb_line6
*line6
, int code1
, int code2
,
368 char *buffer
= kmalloc(size
+ SYSEX_EXTRA_SIZE
, GFP_ATOMIC
);
371 dev_err(line6
->ifcdev
, "out of memory\n");
375 buffer
[0] = LINE6_SYSEX_BEGIN
;
376 memcpy(buffer
+ 1, line6_midi_id
, sizeof(line6_midi_id
));
377 buffer
[sizeof(line6_midi_id
) + 1] = code1
;
378 buffer
[sizeof(line6_midi_id
) + 2] = code2
;
379 buffer
[sizeof(line6_midi_id
) + 3 + size
] = LINE6_SYSEX_END
;
384 Notification of data received from the Line6 device.
386 static void line6_data_received(struct urb
*urb
)
388 struct usb_line6
*line6
= (struct usb_line6
*)urb
->context
;
389 struct MidiBuffer
*mb
= &line6
->line6midi
->midibuf_in
;
392 if (urb
->status
== -ESHUTDOWN
)
395 #ifdef CONFIG_LINE6_USB_DUMP_CTRL
400 line6_midibuf_write(mb
, urb
->transfer_buffer
, urb
->actual_length
);
402 if (done
< urb
->actual_length
) {
403 line6_midibuf_ignore(mb
, done
);
404 DEBUG_MESSAGES(dev_err
406 "%d %d buffer overflow - message skipped\n",
407 done
, urb
->actual_length
));
412 line6_midibuf_read(mb
, line6
->buffer_message
,
413 LINE6_MESSAGE_MAXLEN
);
418 /* MIDI input filter */
419 if (line6_midibuf_skip_message
420 (mb
, line6
->line6midi
->midi_mask_receive
))
423 line6
->message_length
= done
;
424 #ifdef CONFIG_LINE6_USB_DUMP_MIDI
425 line6_write_hexdump(line6
, 'r', line6
->buffer_message
, done
);
427 line6_midi_receive(line6
, line6
->buffer_message
, done
);
429 switch (line6
->usbdev
->descriptor
.idProduct
) {
430 case LINE6_DEVID_BASSPODXT
:
431 case LINE6_DEVID_BASSPODXTLIVE
:
432 case LINE6_DEVID_BASSPODXTPRO
:
433 case LINE6_DEVID_PODXT
:
434 case LINE6_DEVID_PODXTPRO
:
435 case LINE6_DEVID_POCKETPOD
:
436 line6_pod_process_message((struct usb_line6_pod
*)
440 case LINE6_DEVID_PODXTLIVE
:
441 switch (line6
->interface_number
) {
442 case PODXTLIVE_INTERFACE_POD
:
443 line6_pod_process_message((struct usb_line6_pod
447 case PODXTLIVE_INTERFACE_VARIAX
:
448 line6_variax_process_message((struct
454 dev_err(line6
->ifcdev
,
455 "PODxt Live interface %d not supported\n",
456 line6
->interface_number
);
460 case LINE6_DEVID_VARIAX
:
461 line6_variax_process_message((struct usb_line6_variax
*)
470 line6_start_listen(line6
);
474 Send channel number (i.e., switch to a different sound).
476 int line6_send_program(struct usb_line6
*line6
, int value
)
479 unsigned char *buffer
;
482 buffer
= kmalloc(2, GFP_KERNEL
);
485 dev_err(line6
->ifcdev
, "out of memory\n");
489 buffer
[0] = LINE6_PROGRAM_CHANGE
| LINE6_CHANNEL_HOST
;
492 #ifdef CONFIG_LINE6_USB_DUMP_CTRL
493 line6_write_hexdump(line6
, 'S', buffer
, 2);
496 retval
= usb_interrupt_msg(line6
->usbdev
,
497 usb_sndintpipe(line6
->usbdev
,
498 line6
->ep_control_write
),
499 buffer
, 2, &partial
, LINE6_TIMEOUT
* HZ
);
502 dev_err(line6
->ifcdev
, "usb_interrupt_msg failed (%d)\n",
510 Transmit Line6 control parameter.
512 int line6_transmit_parameter(struct usb_line6
*line6
, int param
, int value
)
515 unsigned char *buffer
;
518 buffer
= kmalloc(3, GFP_KERNEL
);
521 dev_err(line6
->ifcdev
, "out of memory\n");
525 buffer
[0] = LINE6_PARAM_CHANGE
| LINE6_CHANNEL_HOST
;
529 #ifdef CONFIG_LINE6_USB_DUMP_CTRL
530 line6_write_hexdump(line6
, 'S', buffer
, 3);
533 retval
= usb_interrupt_msg(line6
->usbdev
,
534 usb_sndintpipe(line6
->usbdev
,
535 line6
->ep_control_write
),
536 buffer
, 3, &partial
, LINE6_TIMEOUT
* HZ
);
539 dev_err(line6
->ifcdev
, "usb_interrupt_msg failed (%d)\n",
547 Read data from device.
549 int line6_read_data(struct usb_line6
*line6
, int address
, void *data
,
552 struct usb_device
*usbdev
= line6
->usbdev
;
556 /* query the serial number: */
557 ret
= usb_control_msg(usbdev
, usb_sndctrlpipe(usbdev
, 0), 0x67,
558 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_OUT
,
559 (datalen
<< 8) | 0x21, address
,
560 NULL
, 0, LINE6_TIMEOUT
* HZ
);
563 dev_err(line6
->ifcdev
, "read request failed (error %d)\n", ret
);
567 /* Wait for data length. We'll get a couple of 0xff until length arrives. */
569 ret
= usb_control_msg(usbdev
, usb_rcvctrlpipe(usbdev
, 0), 0x67,
570 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
|
572 0x0012, 0x0000, &len
, 1,
575 dev_err(line6
->ifcdev
,
576 "receive length failed (error %d)\n", ret
);
579 } while (len
== 0xff);
581 if (len
!= datalen
) {
582 /* should be equal or something went wrong */
583 dev_err(line6
->ifcdev
,
584 "length mismatch (expected %d, got %d)\n",
585 (int)datalen
, (int)len
);
589 /* receive the result: */
590 ret
= usb_control_msg(usbdev
, usb_rcvctrlpipe(usbdev
, 0), 0x67,
591 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_IN
,
592 0x0013, 0x0000, data
, datalen
,
596 dev_err(line6
->ifcdev
, "read failed (error %d)\n", ret
);
604 Write data to device.
606 int line6_write_data(struct usb_line6
*line6
, int address
, void *data
,
609 struct usb_device
*usbdev
= line6
->usbdev
;
611 unsigned char status
;
613 ret
= usb_control_msg(usbdev
, usb_sndctrlpipe(usbdev
, 0), 0x67,
614 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_OUT
,
615 0x0022, address
, data
, datalen
,
619 dev_err(line6
->ifcdev
,
620 "write request failed (error %d)\n", ret
);
625 ret
= usb_control_msg(usbdev
, usb_rcvctrlpipe(usbdev
, 0),
627 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
|
630 &status
, 1, LINE6_TIMEOUT
* HZ
);
633 dev_err(line6
->ifcdev
,
634 "receiving status failed (error %d)\n", ret
);
637 } while (status
== 0xff);
640 dev_err(line6
->ifcdev
, "write failed (error %d)\n", ret
);
648 Read Line6 device serial number.
649 (POD, TonePort, GuitarPort)
651 int line6_read_serial_number(struct usb_line6
*line6
, int *serial_number
)
653 return line6_read_data(line6
, 0x80d0, serial_number
,
654 sizeof(*serial_number
));
658 No operation (i.e., unsupported).
660 ssize_t
line6_nop_read(struct device
*dev
, struct device_attribute
*attr
,
667 No operation (i.e., unsupported).
669 ssize_t
line6_nop_write(struct device
*dev
, struct device_attribute
*attr
,
670 const char *buf
, size_t count
)
676 "write" request on "raw" special file.
678 #ifdef CONFIG_LINE6_USB_RAW
679 ssize_t
line6_set_raw(struct device
*dev
, struct device_attribute
*attr
,
680 const char *buf
, size_t count
)
682 struct usb_interface
*interface
= to_usb_interface(dev
);
683 struct usb_line6
*line6
= usb_get_intfdata(interface
);
684 line6_send_raw_message(line6
, buf
, count
);
692 static void line6_destruct(struct usb_interface
*interface
)
694 struct usb_line6
*line6
;
696 if (interface
== NULL
)
698 line6
= usb_get_intfdata(interface
);
702 /* free buffer memory first: */
703 kfree(line6
->buffer_message
);
704 kfree(line6
->buffer_listen
);
706 /* then free URBs: */
707 usb_free_urb(line6
->urb_listen
);
709 /* make sure the device isn't destructed twice: */
710 usb_set_intfdata(interface
, NULL
);
712 /* free interface data: */
719 static int line6_probe(struct usb_interface
*interface
,
720 const struct usb_device_id
*id
)
723 struct usb_device
*usbdev
= NULL
;
724 struct usb_line6
*line6
= NULL
;
725 const struct line6_properties
*properties
;
727 int interface_number
, alternate
= 0;
730 int ep_read
= 0, ep_write
= 0;
733 if (interface
== NULL
)
735 usbdev
= interface_to_usbdev(interface
);
739 /* we don't handle multiple configurations */
740 if (usbdev
->descriptor
.bNumConfigurations
!= 1) {
745 /* check vendor and product id */
746 for (devtype
= ARRAY_SIZE(line6_id_table
) - 1; devtype
--;) {
747 u16 idVendor
= le16_to_cpu(usbdev
->descriptor
.idVendor
);
748 u16 idProduct
= le16_to_cpu(usbdev
->descriptor
.idProduct
);
750 if (idVendor
== line6_id_table
[devtype
].idVendor
&&
751 idProduct
== line6_id_table
[devtype
].idProduct
)
760 /* find free slot in device table: */
761 for (devnum
= 0; devnum
< LINE6_MAX_DEVICES
; ++devnum
)
762 if (line6_devices
[devnum
] == NULL
)
765 if (devnum
== LINE6_MAX_DEVICES
) {
770 /* initialize device info: */
771 properties
= &line6_properties_table
[devtype
];
772 dev_info(&interface
->dev
, "Line6 %s found\n", properties
->name
);
773 product
= le16_to_cpu(usbdev
->descriptor
.idProduct
);
775 /* query interface number */
776 interface_number
= interface
->cur_altsetting
->desc
.bInterfaceNumber
;
779 case LINE6_DEVID_BASSPODXTLIVE
:
780 case LINE6_DEVID_PODXTLIVE
:
781 case LINE6_DEVID_VARIAX
:
785 case LINE6_DEVID_POCKETPOD
:
786 switch (interface_number
) {
788 return 0; /* this interface has no endpoints */
797 case LINE6_DEVID_PODX3
:
798 case LINE6_DEVID_PODX3LIVE
:
799 switch (interface_number
) {
811 case LINE6_DEVID_BASSPODXT
:
812 case LINE6_DEVID_BASSPODXTPRO
:
813 case LINE6_DEVID_PODXT
:
814 case LINE6_DEVID_PODXTPRO
:
818 case LINE6_DEVID_GUITARPORT
:
819 case LINE6_DEVID_PODSTUDIO_GX
:
820 case LINE6_DEVID_PODSTUDIO_UX1
:
821 case LINE6_DEVID_TONEPORT_GX
:
822 case LINE6_DEVID_TONEPORT_UX1
:
823 alternate
= 2; /* 1..4 seem to be ok */
826 case LINE6_DEVID_TONEPORT_UX2
:
827 case LINE6_DEVID_PODSTUDIO_UX2
:
828 switch (interface_number
) {
830 /* defaults to 44.1kHz, 16-bit */
834 /* don't know yet what this is ...
850 ret
= usb_set_interface(usbdev
, interface_number
, alternate
);
852 dev_err(&interface
->dev
, "set_interface failed\n");
856 /* initialize device data based on product id: */
858 case LINE6_DEVID_BASSPODXT
:
859 case LINE6_DEVID_BASSPODXTLIVE
:
860 case LINE6_DEVID_BASSPODXTPRO
:
861 case LINE6_DEVID_PODXT
:
862 case LINE6_DEVID_PODXTPRO
:
863 size
= sizeof(struct usb_line6_pod
);
868 case LINE6_DEVID_POCKETPOD
:
869 size
= sizeof(struct usb_line6_pod
);
874 case LINE6_DEVID_PODX3
:
875 case LINE6_DEVID_PODX3LIVE
:
876 /* currently unused! */
877 size
= sizeof(struct usb_line6_pod
);
882 case LINE6_DEVID_PODSTUDIO_GX
:
883 case LINE6_DEVID_PODSTUDIO_UX1
:
884 case LINE6_DEVID_PODSTUDIO_UX2
:
885 case LINE6_DEVID_TONEPORT_GX
:
886 case LINE6_DEVID_TONEPORT_UX1
:
887 case LINE6_DEVID_TONEPORT_UX2
:
888 case LINE6_DEVID_GUITARPORT
:
889 size
= sizeof(struct usb_line6_toneport
);
890 /* these don't have a control channel */
893 case LINE6_DEVID_PODXTLIVE
:
894 switch (interface_number
) {
895 case PODXTLIVE_INTERFACE_POD
:
896 size
= sizeof(struct usb_line6_pod
);
901 case PODXTLIVE_INTERFACE_VARIAX
:
902 size
= sizeof(struct usb_line6_variax
);
913 case LINE6_DEVID_VARIAX
:
914 size
= sizeof(struct usb_line6_variax
);
926 dev_err(line6
->ifcdev
,
927 "driver bug: interface data size not set\n");
932 line6
= kzalloc(size
, GFP_KERNEL
);
935 dev_err(&interface
->dev
, "Out of memory\n");
940 /* store basic data: */
941 line6
->interface_number
= interface_number
;
942 line6
->properties
= properties
;
943 line6
->usbdev
= usbdev
;
944 line6
->ifcdev
= &interface
->dev
;
945 line6
->ep_control_read
= ep_read
;
946 line6
->ep_control_write
= ep_write
;
947 line6
->product
= product
;
949 /* get data from endpoint descriptor (see usb_maxpacket): */
951 struct usb_host_endpoint
*ep
;
953 usb_pipeendpoint(usb_rcvintpipe(usbdev
, ep_read
));
954 ep
= usbdev
->ep_in
[epnum
];
957 line6
->interval
= ep
->desc
.bInterval
;
958 line6
->max_packet_size
=
959 le16_to_cpu(ep
->desc
.wMaxPacketSize
);
961 line6
->interval
= LINE6_FALLBACK_INTERVAL
;
962 line6
->max_packet_size
= LINE6_FALLBACK_MAXPACKETSIZE
;
963 dev_err(line6
->ifcdev
,
964 "endpoint not available, using fallback values");
968 usb_set_intfdata(interface
, line6
);
970 if (properties
->capabilities
& LINE6_BIT_CONTROL
) {
971 /* initialize USB buffers: */
972 line6
->buffer_listen
=
973 kmalloc(LINE6_BUFSIZE_LISTEN
, GFP_KERNEL
);
975 if (line6
->buffer_listen
== NULL
) {
976 dev_err(&interface
->dev
, "Out of memory\n");
981 line6
->buffer_message
=
982 kmalloc(LINE6_MESSAGE_MAXLEN
, GFP_KERNEL
);
984 if (line6
->buffer_message
== NULL
) {
985 dev_err(&interface
->dev
, "Out of memory\n");
990 line6
->urb_listen
= usb_alloc_urb(0, GFP_KERNEL
);
992 if (line6
->urb_listen
== NULL
) {
993 dev_err(&interface
->dev
, "Out of memory\n");
994 line6_destruct(interface
);
999 ret
= line6_start_listen(line6
);
1001 dev_err(&interface
->dev
, "%s: usb_submit_urb failed\n",
1007 /* initialize device data based on product id: */
1009 case LINE6_DEVID_BASSPODXT
:
1010 case LINE6_DEVID_BASSPODXTLIVE
:
1011 case LINE6_DEVID_BASSPODXTPRO
:
1012 case LINE6_DEVID_POCKETPOD
:
1013 case LINE6_DEVID_PODX3
:
1014 case LINE6_DEVID_PODX3LIVE
:
1015 case LINE6_DEVID_PODXT
:
1016 case LINE6_DEVID_PODXTPRO
:
1017 ret
= line6_pod_init(interface
, (struct usb_line6_pod
*)line6
);
1020 case LINE6_DEVID_PODXTLIVE
:
1021 switch (interface_number
) {
1022 case PODXTLIVE_INTERFACE_POD
:
1024 line6_pod_init(interface
,
1025 (struct usb_line6_pod
*)line6
);
1028 case PODXTLIVE_INTERFACE_VARIAX
:
1030 line6_variax_init(interface
,
1031 (struct usb_line6_variax
*)line6
);
1035 dev_err(&interface
->dev
,
1036 "PODxt Live interface %d not supported\n",
1043 case LINE6_DEVID_VARIAX
:
1045 line6_variax_init(interface
,
1046 (struct usb_line6_variax
*)line6
);
1049 case LINE6_DEVID_PODSTUDIO_GX
:
1050 case LINE6_DEVID_PODSTUDIO_UX1
:
1051 case LINE6_DEVID_PODSTUDIO_UX2
:
1052 case LINE6_DEVID_TONEPORT_GX
:
1053 case LINE6_DEVID_TONEPORT_UX1
:
1054 case LINE6_DEVID_TONEPORT_UX2
:
1055 case LINE6_DEVID_GUITARPORT
:
1057 line6_toneport_init(interface
,
1058 (struct usb_line6_toneport
*)line6
);
1069 ret
= sysfs_create_link(&interface
->dev
.kobj
, &usbdev
->dev
.kobj
,
1074 /* creation of additional special files should go here */
1076 dev_info(&interface
->dev
, "Line6 %s now attached\n",
1077 line6
->properties
->name
);
1078 line6_devices
[devnum
] = line6
;
1081 case LINE6_DEVID_PODX3
:
1082 case LINE6_DEVID_PODX3LIVE
:
1083 dev_info(&interface
->dev
,
1084 "NOTE: the Line6 %s is detected, but not yet supported\n",
1085 line6
->properties
->name
);
1088 /* increment reference counters: */
1089 usb_get_intf(interface
);
1090 usb_get_dev(usbdev
);
1095 line6_destruct(interface
);
1097 usb_put_intf(interface
);
1098 usb_put_dev(usbdev
);
1103 Line6 device disconnected.
1105 static void line6_disconnect(struct usb_interface
*interface
)
1107 struct usb_line6
*line6
;
1108 struct usb_device
*usbdev
;
1109 int interface_number
, i
;
1111 if (interface
== NULL
)
1113 usbdev
= interface_to_usbdev(interface
);
1117 /* removal of additional special files should go here */
1119 sysfs_remove_link(&interface
->dev
.kobj
, "usb_device");
1121 interface_number
= interface
->cur_altsetting
->desc
.bInterfaceNumber
;
1122 line6
= usb_get_intfdata(interface
);
1124 if (line6
!= NULL
) {
1125 if (line6
->urb_listen
!= NULL
)
1126 line6_stop_listen(line6
);
1128 if (usbdev
!= line6
->usbdev
)
1129 dev_err(line6
->ifcdev
,
1130 "driver bug: inconsistent usb device\n");
1132 switch (line6
->usbdev
->descriptor
.idProduct
) {
1133 case LINE6_DEVID_BASSPODXT
:
1134 case LINE6_DEVID_BASSPODXTLIVE
:
1135 case LINE6_DEVID_BASSPODXTPRO
:
1136 case LINE6_DEVID_POCKETPOD
:
1137 case LINE6_DEVID_PODX3
:
1138 case LINE6_DEVID_PODX3LIVE
:
1139 case LINE6_DEVID_PODXT
:
1140 case LINE6_DEVID_PODXTPRO
:
1141 line6_pod_disconnect(interface
);
1144 case LINE6_DEVID_PODXTLIVE
:
1145 switch (interface_number
) {
1146 case PODXTLIVE_INTERFACE_POD
:
1147 line6_pod_disconnect(interface
);
1150 case PODXTLIVE_INTERFACE_VARIAX
:
1151 line6_variax_disconnect(interface
);
1157 case LINE6_DEVID_VARIAX
:
1158 line6_variax_disconnect(interface
);
1161 case LINE6_DEVID_PODSTUDIO_GX
:
1162 case LINE6_DEVID_PODSTUDIO_UX1
:
1163 case LINE6_DEVID_PODSTUDIO_UX2
:
1164 case LINE6_DEVID_TONEPORT_GX
:
1165 case LINE6_DEVID_TONEPORT_UX1
:
1166 case LINE6_DEVID_TONEPORT_UX2
:
1167 case LINE6_DEVID_GUITARPORT
:
1168 line6_toneport_disconnect(interface
);
1175 dev_info(&interface
->dev
, "Line6 %s now disconnected\n",
1176 line6
->properties
->name
);
1178 for (i
= LINE6_MAX_DEVICES
; i
--;)
1179 if (line6_devices
[i
] == line6
)
1180 line6_devices
[i
] = NULL
;
1183 line6_destruct(interface
);
1185 /* decrement reference counters: */
1186 usb_put_intf(interface
);
1187 usb_put_dev(usbdev
);
1193 Suspend Line6 device.
1195 static int line6_suspend(struct usb_interface
*interface
, pm_message_t message
)
1197 struct usb_line6
*line6
= usb_get_intfdata(interface
);
1198 struct snd_line6_pcm
*line6pcm
= line6
->line6pcm
;
1200 snd_power_change_state(line6
->card
, SNDRV_CTL_POWER_D3hot
);
1202 if (line6
->properties
->capabilities
& LINE6_BIT_CONTROL
)
1203 line6_stop_listen(line6
);
1205 if (line6pcm
!= NULL
) {
1206 snd_pcm_suspend_all(line6pcm
->pcm
);
1207 line6_pcm_disconnect(line6pcm
);
1208 line6pcm
->flags
= 0;
1215 Resume Line6 device.
1217 static int line6_resume(struct usb_interface
*interface
)
1219 struct usb_line6
*line6
= usb_get_intfdata(interface
);
1221 if (line6
->properties
->capabilities
& LINE6_BIT_CONTROL
)
1222 line6_start_listen(line6
);
1224 snd_power_change_state(line6
->card
, SNDRV_CTL_POWER_D0
);
1229 Resume Line6 device after reset.
1231 static int line6_reset_resume(struct usb_interface
*interface
)
1233 struct usb_line6
*line6
= usb_get_intfdata(interface
);
1235 switch (line6
->usbdev
->descriptor
.idProduct
) {
1236 case LINE6_DEVID_PODSTUDIO_GX
:
1237 case LINE6_DEVID_PODSTUDIO_UX1
:
1238 case LINE6_DEVID_PODSTUDIO_UX2
:
1239 case LINE6_DEVID_TONEPORT_GX
:
1240 case LINE6_DEVID_TONEPORT_UX1
:
1241 case LINE6_DEVID_TONEPORT_UX2
:
1242 case LINE6_DEVID_GUITARPORT
:
1243 line6_toneport_reset_resume((struct usb_line6_toneport
*)line6
);
1246 return line6_resume(interface
);
1249 #endif /* CONFIG_PM */
1251 static struct usb_driver line6_driver
= {
1252 .name
= DRIVER_NAME
,
1253 .probe
= line6_probe
,
1254 .disconnect
= line6_disconnect
,
1256 .suspend
= line6_suspend
,
1257 .resume
= line6_resume
,
1258 .reset_resume
= line6_reset_resume
,
1260 .id_table
= line6_id_table
,
1264 Module initialization.
1266 static int __init
line6_init(void)
1270 printk(KERN_INFO
"%s driver version %s\n", DRIVER_NAME
, DRIVER_VERSION
);
1272 for (i
= LINE6_MAX_DEVICES
; i
--;)
1273 line6_devices
[i
] = NULL
;
1275 retval
= usb_register(&line6_driver
);
1278 err("usb_register failed. Error number %d", retval
);
1282 line6_request_version
= kmalloc(sizeof(line6_request_version0
),
1285 if (line6_request_version
== NULL
) {
1286 err("Out of memory");
1290 memcpy((char *)line6_request_version
, line6_request_version0
,
1291 sizeof(line6_request_version0
));
1299 static void __exit
line6_exit(void)
1302 struct usb_line6
*line6
;
1303 struct snd_line6_pcm
*line6pcm
;
1305 /* stop all PCM channels */
1306 for (i
= LINE6_MAX_DEVICES
; i
--;) {
1307 line6
= line6_devices
[i
];
1312 line6pcm
= line6
->line6pcm
;
1314 if (line6pcm
== NULL
)
1317 line6_pcm_stop(line6pcm
, ~0);
1320 usb_deregister(&line6_driver
);
1321 kfree(line6_request_version
);
1324 module_init(line6_init
);
1325 module_exit(line6_exit
);
1327 MODULE_AUTHOR(DRIVER_AUTHOR
);
1328 MODULE_DESCRIPTION(DRIVER_DESC
);
1329 MODULE_LICENSE("GPL");
1330 MODULE_VERSION(DRIVER_VERSION
);