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>
30 #define DRIVER_AUTHOR "Markus Grabner <grabner@icg.tugraz.at>"
31 #define DRIVER_DESC "Line6 USB Driver"
32 #define DRIVER_VERSION "0.9.1beta" DRIVER_REVISION
34 /* table of devices that work with this driver */
35 static const struct usb_device_id line6_id_table
[] = {
36 {USB_DEVICE(LINE6_VENDOR_ID
, LINE6_DEVID_BASSPODXT
)},
37 {USB_DEVICE(LINE6_VENDOR_ID
, LINE6_DEVID_BASSPODXTLIVE
)},
38 {USB_DEVICE(LINE6_VENDOR_ID
, LINE6_DEVID_BASSPODXTPRO
)},
39 {USB_DEVICE(LINE6_VENDOR_ID
, LINE6_DEVID_GUITARPORT
)},
40 {USB_DEVICE(LINE6_VENDOR_ID
, LINE6_DEVID_POCKETPOD
)},
41 {USB_DEVICE(LINE6_VENDOR_ID
, LINE6_DEVID_PODHD300
)},
42 {USB_DEVICE(LINE6_VENDOR_ID
, LINE6_DEVID_PODHD500
)},
43 {USB_DEVICE(LINE6_VENDOR_ID
, LINE6_DEVID_PODSTUDIO_GX
)},
44 {USB_DEVICE(LINE6_VENDOR_ID
, LINE6_DEVID_PODSTUDIO_UX1
)},
45 {USB_DEVICE(LINE6_VENDOR_ID
, LINE6_DEVID_PODSTUDIO_UX2
)},
46 {USB_DEVICE(LINE6_VENDOR_ID
, LINE6_DEVID_PODX3
)},
47 {USB_DEVICE(LINE6_VENDOR_ID
, LINE6_DEVID_PODX3LIVE
)},
48 {USB_DEVICE(LINE6_VENDOR_ID
, LINE6_DEVID_PODXT
)},
49 {USB_DEVICE(LINE6_VENDOR_ID
, LINE6_DEVID_PODXTLIVE
)},
50 {USB_DEVICE(LINE6_VENDOR_ID
, LINE6_DEVID_PODXTPRO
)},
51 {USB_DEVICE(LINE6_VENDOR_ID
, LINE6_DEVID_TONEPORT_GX
)},
52 {USB_DEVICE(LINE6_VENDOR_ID
, LINE6_DEVID_TONEPORT_UX1
)},
53 {USB_DEVICE(LINE6_VENDOR_ID
, LINE6_DEVID_TONEPORT_UX2
)},
54 {USB_DEVICE(LINE6_VENDOR_ID
, LINE6_DEVID_VARIAX
)},
58 MODULE_DEVICE_TABLE(usb
, line6_id_table
);
61 static struct line6_properties line6_properties_table
[] = {
62 { LINE6_BIT_BASSPODXT
, "BassPODxt", "BassPODxt", LINE6_BIT_CONTROL_PCM_HWMON
},
63 { LINE6_BIT_BASSPODXTLIVE
, "BassPODxtLive", "BassPODxt Live", LINE6_BIT_CONTROL_PCM_HWMON
},
64 { LINE6_BIT_BASSPODXTPRO
, "BassPODxtPro", "BassPODxt Pro", LINE6_BIT_CONTROL_PCM_HWMON
},
65 { LINE6_BIT_GUITARPORT
, "GuitarPort", "GuitarPort", LINE6_BIT_PCM
},
66 { LINE6_BIT_POCKETPOD
, "PocketPOD", "Pocket POD", LINE6_BIT_CONTROL
},
67 { LINE6_BIT_PODHD300
, "PODHD300", "POD HD300", LINE6_BIT_CONTROL_PCM_HWMON
},
68 { LINE6_BIT_PODHD500
, "PODHD500", "POD HD500", LINE6_BIT_CONTROL_PCM_HWMON
},
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
},
72 { LINE6_BIT_PODX3
, "PODX3", "POD X3", LINE6_BIT_PCM
},
73 { LINE6_BIT_PODX3LIVE
, "PODX3Live", "POD X3 Live", LINE6_BIT_PCM
},
74 { LINE6_BIT_PODXT
, "PODxt", "PODxt", LINE6_BIT_CONTROL_PCM_HWMON
},
75 { LINE6_BIT_PODXTLIVE
, "PODxtLive", "PODxt Live", LINE6_BIT_CONTROL_PCM_HWMON
},
76 { LINE6_BIT_PODXTPRO
, "PODxtPro", "PODxt Pro", LINE6_BIT_CONTROL_PCM_HWMON
},
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
},
80 { LINE6_BIT_VARIAX
, "Variax", "Variax Workbench", LINE6_BIT_CONTROL
},
85 This is Line6's MIDI manufacturer ID.
87 const unsigned char line6_midi_id
[] = {
92 Code to request version of POD, Variax interface
93 (and maybe other devices).
95 static const char line6_request_version0
[] = {
96 0xf0, 0x7e, 0x7f, 0x06, 0x01, 0xf7
100 Copy of version request code with GFP_KERNEL flag for use in URB.
102 static const char *line6_request_version
;
104 struct usb_line6
*line6_devices
[LINE6_MAX_DEVICES
];
107 Class for asynchronous messages.
110 struct usb_line6
*line6
;
117 Forward declarations.
119 static void line6_data_received(struct urb
*urb
);
120 static int line6_send_raw_message_async_part(struct message
*msg
,
124 Start to listen on endpoint.
126 static int line6_start_listen(struct usb_line6
*line6
)
129 usb_fill_int_urb(line6
->urb_listen
, line6
->usbdev
,
130 usb_rcvintpipe(line6
->usbdev
, line6
->ep_control_read
),
131 line6
->buffer_listen
, LINE6_BUFSIZE_LISTEN
,
132 line6_data_received
, line6
, line6
->interval
);
133 line6
->urb_listen
->actual_length
= 0;
134 err
= usb_submit_urb(line6
->urb_listen
, GFP_ATOMIC
);
139 Stop listening on endpoint.
141 static void line6_stop_listen(struct usb_line6
*line6
)
143 usb_kill_urb(line6
->urb_listen
);
146 #ifdef CONFIG_LINE6_USB_DUMP_ANY
148 Write hexdump to syslog.
150 void line6_write_hexdump(struct usb_line6
*line6
, char dir
,
151 const unsigned char *buffer
, int size
)
153 static const int BYTES_PER_LINE
= 8;
155 char asc
[BYTES_PER_LINE
+ 1];
158 for (i
= 0; i
< size
; i
+= BYTES_PER_LINE
) {
159 int hexdumpsize
= sizeof(hexdump
);
161 int n
= min(size
- i
, BYTES_PER_LINE
);
164 for (j
= 0; j
< BYTES_PER_LINE
; ++j
) {
168 unsigned char val
= buffer
[i
+ j
];
169 bytes
= snprintf(p
, hexdumpsize
, " %02X", val
);
170 asc
[j
] = ((val
>= 0x20)
171 && (val
< 0x7f)) ? val
: '.';
173 bytes
= snprintf(p
, hexdumpsize
, " ");
175 if (bytes
> hexdumpsize
)
176 break; /* buffer overflow */
179 hexdumpsize
-= bytes
;
182 dev_info(line6
->ifcdev
, "%c%04X:%s %s\n", dir
, i
, hexdump
, asc
);
187 #ifdef CONFIG_LINE6_USB_DUMP_CTRL
189 Dump URB data to syslog.
191 static void line6_dump_urb(struct urb
*urb
)
193 struct usb_line6
*line6
= (struct usb_line6
*)urb
->context
;
198 line6_write_hexdump(line6
, 'R', (unsigned char *)urb
->transfer_buffer
,
204 Send raw message in pieces of wMaxPacketSize bytes.
206 int line6_send_raw_message(struct usb_line6
*line6
, const char *buffer
,
211 #ifdef CONFIG_LINE6_USB_DUMP_CTRL
212 line6_write_hexdump(line6
, 'S', buffer
, size
);
215 for (i
= 0; i
< size
; i
+= line6
->max_packet_size
) {
217 const char *frag_buf
= buffer
+ i
;
218 int frag_size
= min(line6
->max_packet_size
, size
- i
);
221 retval
= usb_interrupt_msg(line6
->usbdev
,
222 usb_sndintpipe(line6
->usbdev
,
223 line6
->ep_control_write
),
224 (char *)frag_buf
, frag_size
,
225 &partial
, LINE6_TIMEOUT
* HZ
);
228 dev_err(line6
->ifcdev
,
229 "usb_interrupt_msg failed (%d)\n", retval
);
240 Notification of completion of asynchronous request transmission.
242 static void line6_async_request_sent(struct urb
*urb
)
244 struct message
*msg
= (struct message
*)urb
->context
;
246 if (msg
->done
>= msg
->size
) {
250 line6_send_raw_message_async_part(msg
, urb
);
254 Asynchronously send part of a raw message.
256 static int line6_send_raw_message_async_part(struct message
*msg
,
260 struct usb_line6
*line6
= msg
->line6
;
261 int done
= msg
->done
;
262 int bytes
= min(msg
->size
- done
, line6
->max_packet_size
);
264 usb_fill_int_urb(urb
, line6
->usbdev
,
265 usb_sndintpipe(line6
->usbdev
, line6
->ep_control_write
),
266 (char *)msg
->buffer
+ done
, bytes
,
267 line6_async_request_sent
, msg
, line6
->interval
);
269 #ifdef CONFIG_LINE6_USB_DUMP_CTRL
270 line6_write_hexdump(line6
, 'S', (char *)msg
->buffer
+ done
, bytes
);
274 retval
= usb_submit_urb(urb
, GFP_ATOMIC
);
277 dev_err(line6
->ifcdev
, "%s: usb_submit_urb failed (%d)\n",
288 Setup and start timer.
290 void line6_start_timer(struct timer_list
*timer
, unsigned int msecs
,
291 void (*function
) (unsigned long), unsigned long data
)
293 setup_timer(timer
, function
, data
);
294 timer
->expires
= jiffies
+ msecs
* HZ
/ 1000;
299 Asynchronously send raw message.
301 int line6_send_raw_message_async(struct usb_line6
*line6
, const char *buffer
,
307 /* create message: */
308 msg
= kmalloc(sizeof(struct message
), GFP_ATOMIC
);
311 dev_err(line6
->ifcdev
, "Out of memory\n");
316 urb
= usb_alloc_urb(0, GFP_ATOMIC
);
320 dev_err(line6
->ifcdev
, "Out of memory\n");
324 /* set message data: */
326 msg
->buffer
= buffer
;
331 return line6_send_raw_message_async_part(msg
, urb
);
335 Send asynchronous device version request.
337 int line6_version_request_async(struct usb_line6
*line6
)
339 return line6_send_raw_message_async(line6
, line6_request_version
,
340 sizeof(line6_request_version0
));
344 Send sysex message in pieces of wMaxPacketSize bytes.
346 int line6_send_sysex_message(struct usb_line6
*line6
, const char *buffer
,
349 return line6_send_raw_message(line6
, buffer
,
350 size
+ SYSEX_EXTRA_SIZE
) -
355 Send sysex message in pieces of wMaxPacketSize bytes.
357 int line6_send_sysex_message_async(struct usb_line6
*line6
, const char *buffer
,
360 return line6_send_raw_message_async(line6
, buffer
,
361 size
+ SYSEX_EXTRA_SIZE
) -
366 Allocate buffer for sysex message and prepare header.
367 @param code sysex message code
368 @param size number of bytes between code and sysex end
370 char *line6_alloc_sysex_buffer(struct usb_line6
*line6
, int code1
, int code2
,
373 char *buffer
= kmalloc(size
+ SYSEX_EXTRA_SIZE
, GFP_ATOMIC
);
376 dev_err(line6
->ifcdev
, "out of memory\n");
380 buffer
[0] = LINE6_SYSEX_BEGIN
;
381 memcpy(buffer
+ 1, line6_midi_id
, sizeof(line6_midi_id
));
382 buffer
[sizeof(line6_midi_id
) + 1] = code1
;
383 buffer
[sizeof(line6_midi_id
) + 2] = code2
;
384 buffer
[sizeof(line6_midi_id
) + 3 + size
] = LINE6_SYSEX_END
;
389 Notification of data received from the Line6 device.
391 static void line6_data_received(struct urb
*urb
)
393 struct usb_line6
*line6
= (struct usb_line6
*)urb
->context
;
394 struct MidiBuffer
*mb
= &line6
->line6midi
->midibuf_in
;
397 if (urb
->status
== -ESHUTDOWN
)
400 #ifdef CONFIG_LINE6_USB_DUMP_CTRL
405 line6_midibuf_write(mb
, urb
->transfer_buffer
, urb
->actual_length
);
407 if (done
< urb
->actual_length
) {
408 line6_midibuf_ignore(mb
, done
);
409 DEBUG_MESSAGES(dev_err
411 "%d %d buffer overflow - message skipped\n",
412 done
, urb
->actual_length
));
417 line6_midibuf_read(mb
, line6
->buffer_message
,
418 LINE6_MESSAGE_MAXLEN
);
423 /* MIDI input filter */
424 if (line6_midibuf_skip_message
425 (mb
, line6
->line6midi
->midi_mask_receive
))
428 line6
->message_length
= done
;
429 #ifdef CONFIG_LINE6_USB_DUMP_MIDI
430 line6_write_hexdump(line6
, 'r', line6
->buffer_message
, done
);
432 line6_midi_receive(line6
, line6
->buffer_message
, done
);
434 switch (line6
->usbdev
->descriptor
.idProduct
) {
435 case LINE6_DEVID_BASSPODXT
:
436 case LINE6_DEVID_BASSPODXTLIVE
:
437 case LINE6_DEVID_BASSPODXTPRO
:
438 case LINE6_DEVID_PODXT
:
439 case LINE6_DEVID_PODXTPRO
:
440 case LINE6_DEVID_POCKETPOD
:
441 line6_pod_process_message((struct usb_line6_pod
*)
445 case LINE6_DEVID_PODHD300
:
446 case LINE6_DEVID_PODHD500
:
447 break; /* let userspace handle MIDI */
449 case LINE6_DEVID_PODXTLIVE
:
450 switch (line6
->interface_number
) {
451 case PODXTLIVE_INTERFACE_POD
:
452 line6_pod_process_message((struct usb_line6_pod
456 case PODXTLIVE_INTERFACE_VARIAX
:
457 line6_variax_process_message((struct
463 dev_err(line6
->ifcdev
,
464 "PODxt Live interface %d not supported\n",
465 line6
->interface_number
);
469 case LINE6_DEVID_VARIAX
:
470 line6_variax_process_message((struct usb_line6_variax
*)
479 line6_start_listen(line6
);
483 Send channel number (i.e., switch to a different sound).
485 int line6_send_program(struct usb_line6
*line6
, int value
)
488 unsigned char *buffer
;
491 buffer
= kmalloc(2, GFP_KERNEL
);
494 dev_err(line6
->ifcdev
, "out of memory\n");
498 buffer
[0] = LINE6_PROGRAM_CHANGE
| LINE6_CHANNEL_HOST
;
501 #ifdef CONFIG_LINE6_USB_DUMP_CTRL
502 line6_write_hexdump(line6
, 'S', buffer
, 2);
505 retval
= usb_interrupt_msg(line6
->usbdev
,
506 usb_sndintpipe(line6
->usbdev
,
507 line6
->ep_control_write
),
508 buffer
, 2, &partial
, LINE6_TIMEOUT
* HZ
);
511 dev_err(line6
->ifcdev
, "usb_interrupt_msg failed (%d)\n",
519 Transmit Line6 control parameter.
521 int line6_transmit_parameter(struct usb_line6
*line6
, int param
, int value
)
524 unsigned char *buffer
;
527 buffer
= kmalloc(3, GFP_KERNEL
);
530 dev_err(line6
->ifcdev
, "out of memory\n");
534 buffer
[0] = LINE6_PARAM_CHANGE
| LINE6_CHANNEL_HOST
;
538 #ifdef CONFIG_LINE6_USB_DUMP_CTRL
539 line6_write_hexdump(line6
, 'S', buffer
, 3);
542 retval
= usb_interrupt_msg(line6
->usbdev
,
543 usb_sndintpipe(line6
->usbdev
,
544 line6
->ep_control_write
),
545 buffer
, 3, &partial
, LINE6_TIMEOUT
* HZ
);
548 dev_err(line6
->ifcdev
, "usb_interrupt_msg failed (%d)\n",
556 Read data from device.
558 int line6_read_data(struct usb_line6
*line6
, int address
, void *data
,
561 struct usb_device
*usbdev
= line6
->usbdev
;
565 /* query the serial number: */
566 ret
= usb_control_msg(usbdev
, usb_sndctrlpipe(usbdev
, 0), 0x67,
567 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_OUT
,
568 (datalen
<< 8) | 0x21, address
,
569 NULL
, 0, LINE6_TIMEOUT
* HZ
);
572 dev_err(line6
->ifcdev
, "read request failed (error %d)\n", ret
);
576 /* Wait for data length. We'll get a couple of 0xff until length arrives. */
578 ret
= usb_control_msg(usbdev
, usb_rcvctrlpipe(usbdev
, 0), 0x67,
579 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
|
581 0x0012, 0x0000, &len
, 1,
584 dev_err(line6
->ifcdev
,
585 "receive length failed (error %d)\n", ret
);
588 } while (len
== 0xff);
590 if (len
!= datalen
) {
591 /* should be equal or something went wrong */
592 dev_err(line6
->ifcdev
,
593 "length mismatch (expected %d, got %d)\n",
594 (int)datalen
, (int)len
);
598 /* receive the result: */
599 ret
= usb_control_msg(usbdev
, usb_rcvctrlpipe(usbdev
, 0), 0x67,
600 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_IN
,
601 0x0013, 0x0000, data
, datalen
,
605 dev_err(line6
->ifcdev
, "read failed (error %d)\n", ret
);
613 Write data to device.
615 int line6_write_data(struct usb_line6
*line6
, int address
, void *data
,
618 struct usb_device
*usbdev
= line6
->usbdev
;
620 unsigned char status
;
622 ret
= usb_control_msg(usbdev
, usb_sndctrlpipe(usbdev
, 0), 0x67,
623 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_OUT
,
624 0x0022, address
, data
, datalen
,
628 dev_err(line6
->ifcdev
,
629 "write request failed (error %d)\n", ret
);
634 ret
= usb_control_msg(usbdev
, usb_rcvctrlpipe(usbdev
, 0),
636 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
|
639 &status
, 1, LINE6_TIMEOUT
* HZ
);
642 dev_err(line6
->ifcdev
,
643 "receiving status failed (error %d)\n", ret
);
646 } while (status
== 0xff);
649 dev_err(line6
->ifcdev
, "write failed (error %d)\n", ret
);
657 Read Line6 device serial number.
658 (POD, TonePort, GuitarPort)
660 int line6_read_serial_number(struct usb_line6
*line6
, int *serial_number
)
662 return line6_read_data(line6
, 0x80d0, serial_number
,
663 sizeof(*serial_number
));
667 No operation (i.e., unsupported).
669 ssize_t
line6_nop_read(struct device
*dev
, struct device_attribute
*attr
,
676 No operation (i.e., unsupported).
678 ssize_t
line6_nop_write(struct device
*dev
, struct device_attribute
*attr
,
679 const char *buf
, size_t count
)
685 "write" request on "raw" special file.
687 #ifdef CONFIG_LINE6_USB_RAW
688 ssize_t
line6_set_raw(struct device
*dev
, struct device_attribute
*attr
,
689 const char *buf
, size_t count
)
691 struct usb_interface
*interface
= to_usb_interface(dev
);
692 struct usb_line6
*line6
= usb_get_intfdata(interface
);
693 line6_send_raw_message(line6
, buf
, count
);
701 static void line6_destruct(struct usb_interface
*interface
)
703 struct usb_line6
*line6
;
705 if (interface
== NULL
)
707 line6
= usb_get_intfdata(interface
);
711 /* free buffer memory first: */
712 kfree(line6
->buffer_message
);
713 kfree(line6
->buffer_listen
);
715 /* then free URBs: */
716 usb_free_urb(line6
->urb_listen
);
718 /* make sure the device isn't destructed twice: */
719 usb_set_intfdata(interface
, NULL
);
721 /* free interface data: */
728 static int line6_probe(struct usb_interface
*interface
,
729 const struct usb_device_id
*id
)
732 struct usb_device
*usbdev
;
733 struct usb_line6
*line6
;
734 const struct line6_properties
*properties
;
736 int interface_number
, alternate
= 0;
739 int ep_read
= 0, ep_write
= 0;
742 if (interface
== NULL
)
744 usbdev
= interface_to_usbdev(interface
);
748 /* we don't handle multiple configurations */
749 if (usbdev
->descriptor
.bNumConfigurations
!= 1) {
754 /* check vendor and product id */
755 for (devtype
= ARRAY_SIZE(line6_id_table
) - 1; devtype
--;) {
756 u16 idVendor
= le16_to_cpu(usbdev
->descriptor
.idVendor
);
757 u16 idProduct
= le16_to_cpu(usbdev
->descriptor
.idProduct
);
759 if (idVendor
== line6_id_table
[devtype
].idVendor
&&
760 idProduct
== line6_id_table
[devtype
].idProduct
)
769 /* find free slot in device table: */
770 for (devnum
= 0; devnum
< LINE6_MAX_DEVICES
; ++devnum
)
771 if (line6_devices
[devnum
] == NULL
)
774 if (devnum
== LINE6_MAX_DEVICES
) {
779 /* initialize device info: */
780 properties
= &line6_properties_table
[devtype
];
781 dev_info(&interface
->dev
, "Line6 %s found\n", properties
->name
);
782 product
= le16_to_cpu(usbdev
->descriptor
.idProduct
);
784 /* query interface number */
785 interface_number
= interface
->cur_altsetting
->desc
.bInterfaceNumber
;
788 case LINE6_DEVID_BASSPODXTLIVE
:
789 case LINE6_DEVID_PODXTLIVE
:
790 case LINE6_DEVID_VARIAX
:
794 case LINE6_DEVID_POCKETPOD
:
795 switch (interface_number
) {
797 return 0; /* this interface has no endpoints */
806 case LINE6_DEVID_PODHD500
:
807 case LINE6_DEVID_PODX3
:
808 case LINE6_DEVID_PODX3LIVE
:
809 switch (interface_number
) {
821 case LINE6_DEVID_BASSPODXT
:
822 case LINE6_DEVID_BASSPODXTPRO
:
823 case LINE6_DEVID_PODXT
:
824 case LINE6_DEVID_PODXTPRO
:
825 case LINE6_DEVID_PODHD300
:
829 case LINE6_DEVID_GUITARPORT
:
830 case LINE6_DEVID_PODSTUDIO_GX
:
831 case LINE6_DEVID_PODSTUDIO_UX1
:
832 case LINE6_DEVID_TONEPORT_GX
:
833 case LINE6_DEVID_TONEPORT_UX1
:
834 alternate
= 2; /* 1..4 seem to be ok */
837 case LINE6_DEVID_TONEPORT_UX2
:
838 case LINE6_DEVID_PODSTUDIO_UX2
:
839 switch (interface_number
) {
841 /* defaults to 44.1kHz, 16-bit */
845 /* don't know yet what this is ...
861 ret
= usb_set_interface(usbdev
, interface_number
, alternate
);
863 dev_err(&interface
->dev
, "set_interface failed\n");
867 /* initialize device data based on product id: */
869 case LINE6_DEVID_BASSPODXT
:
870 case LINE6_DEVID_BASSPODXTLIVE
:
871 case LINE6_DEVID_BASSPODXTPRO
:
872 case LINE6_DEVID_PODXT
:
873 case LINE6_DEVID_PODXTPRO
:
874 size
= sizeof(struct usb_line6_pod
);
879 case LINE6_DEVID_PODHD300
:
880 size
= sizeof(struct usb_line6_podhd
);
885 case LINE6_DEVID_PODHD500
:
886 size
= sizeof(struct usb_line6_podhd
);
891 case LINE6_DEVID_POCKETPOD
:
892 size
= sizeof(struct usb_line6_pod
);
897 case LINE6_DEVID_PODX3
:
898 case LINE6_DEVID_PODX3LIVE
:
899 /* currently unused! */
900 size
= sizeof(struct usb_line6_pod
);
905 case LINE6_DEVID_PODSTUDIO_GX
:
906 case LINE6_DEVID_PODSTUDIO_UX1
:
907 case LINE6_DEVID_PODSTUDIO_UX2
:
908 case LINE6_DEVID_TONEPORT_GX
:
909 case LINE6_DEVID_TONEPORT_UX1
:
910 case LINE6_DEVID_TONEPORT_UX2
:
911 case LINE6_DEVID_GUITARPORT
:
912 size
= sizeof(struct usb_line6_toneport
);
913 /* these don't have a control channel */
916 case LINE6_DEVID_PODXTLIVE
:
917 switch (interface_number
) {
918 case PODXTLIVE_INTERFACE_POD
:
919 size
= sizeof(struct usb_line6_pod
);
924 case PODXTLIVE_INTERFACE_VARIAX
:
925 size
= sizeof(struct usb_line6_variax
);
936 case LINE6_DEVID_VARIAX
:
937 size
= sizeof(struct usb_line6_variax
);
949 dev_err(&interface
->dev
,
950 "driver bug: interface data size not set\n");
955 line6
= kzalloc(size
, GFP_KERNEL
);
958 dev_err(&interface
->dev
, "Out of memory\n");
963 /* store basic data: */
964 line6
->interface_number
= interface_number
;
965 line6
->properties
= properties
;
966 line6
->usbdev
= usbdev
;
967 line6
->ifcdev
= &interface
->dev
;
968 line6
->ep_control_read
= ep_read
;
969 line6
->ep_control_write
= ep_write
;
970 line6
->product
= product
;
972 /* get data from endpoint descriptor (see usb_maxpacket): */
974 struct usb_host_endpoint
*ep
;
976 usb_pipeendpoint(usb_rcvintpipe(usbdev
, ep_read
));
977 ep
= usbdev
->ep_in
[epnum
];
980 line6
->interval
= ep
->desc
.bInterval
;
981 line6
->max_packet_size
=
982 le16_to_cpu(ep
->desc
.wMaxPacketSize
);
984 line6
->interval
= LINE6_FALLBACK_INTERVAL
;
985 line6
->max_packet_size
= LINE6_FALLBACK_MAXPACKETSIZE
;
986 dev_err(line6
->ifcdev
,
987 "endpoint not available, using fallback values");
991 usb_set_intfdata(interface
, line6
);
993 if (properties
->capabilities
& LINE6_BIT_CONTROL
) {
994 /* initialize USB buffers: */
995 line6
->buffer_listen
=
996 kmalloc(LINE6_BUFSIZE_LISTEN
, GFP_KERNEL
);
998 if (line6
->buffer_listen
== NULL
) {
999 dev_err(&interface
->dev
, "Out of memory\n");
1004 line6
->buffer_message
=
1005 kmalloc(LINE6_MESSAGE_MAXLEN
, GFP_KERNEL
);
1007 if (line6
->buffer_message
== NULL
) {
1008 dev_err(&interface
->dev
, "Out of memory\n");
1013 line6
->urb_listen
= usb_alloc_urb(0, GFP_KERNEL
);
1015 if (line6
->urb_listen
== NULL
) {
1016 dev_err(&interface
->dev
, "Out of memory\n");
1017 line6_destruct(interface
);
1022 ret
= line6_start_listen(line6
);
1024 dev_err(&interface
->dev
, "%s: usb_submit_urb failed\n",
1030 /* initialize device data based on product id: */
1032 case LINE6_DEVID_BASSPODXT
:
1033 case LINE6_DEVID_BASSPODXTLIVE
:
1034 case LINE6_DEVID_BASSPODXTPRO
:
1035 case LINE6_DEVID_POCKETPOD
:
1036 case LINE6_DEVID_PODX3
:
1037 case LINE6_DEVID_PODX3LIVE
:
1038 case LINE6_DEVID_PODXT
:
1039 case LINE6_DEVID_PODXTPRO
:
1040 ret
= line6_pod_init(interface
, (struct usb_line6_pod
*)line6
);
1043 case LINE6_DEVID_PODHD300
:
1044 case LINE6_DEVID_PODHD500
:
1045 ret
= line6_podhd_init(interface
,
1046 (struct usb_line6_podhd
*)line6
);
1049 case LINE6_DEVID_PODXTLIVE
:
1050 switch (interface_number
) {
1051 case PODXTLIVE_INTERFACE_POD
:
1053 line6_pod_init(interface
,
1054 (struct usb_line6_pod
*)line6
);
1057 case PODXTLIVE_INTERFACE_VARIAX
:
1059 line6_variax_init(interface
,
1060 (struct usb_line6_variax
*)line6
);
1064 dev_err(&interface
->dev
,
1065 "PODxt Live interface %d not supported\n",
1072 case LINE6_DEVID_VARIAX
:
1074 line6_variax_init(interface
,
1075 (struct usb_line6_variax
*)line6
);
1078 case LINE6_DEVID_PODSTUDIO_GX
:
1079 case LINE6_DEVID_PODSTUDIO_UX1
:
1080 case LINE6_DEVID_PODSTUDIO_UX2
:
1081 case LINE6_DEVID_TONEPORT_GX
:
1082 case LINE6_DEVID_TONEPORT_UX1
:
1083 case LINE6_DEVID_TONEPORT_UX2
:
1084 case LINE6_DEVID_GUITARPORT
:
1086 line6_toneport_init(interface
,
1087 (struct usb_line6_toneport
*)line6
);
1098 ret
= sysfs_create_link(&interface
->dev
.kobj
, &usbdev
->dev
.kobj
,
1103 /* creation of additional special files should go here */
1105 dev_info(&interface
->dev
, "Line6 %s now attached\n",
1106 line6
->properties
->name
);
1107 line6_devices
[devnum
] = line6
;
1110 case LINE6_DEVID_PODX3
:
1111 case LINE6_DEVID_PODX3LIVE
:
1112 dev_info(&interface
->dev
,
1113 "NOTE: the Line6 %s is detected, but not yet supported\n",
1114 line6
->properties
->name
);
1117 /* increment reference counters: */
1118 usb_get_intf(interface
);
1119 usb_get_dev(usbdev
);
1124 line6_destruct(interface
);
1130 Line6 device disconnected.
1132 static void line6_disconnect(struct usb_interface
*interface
)
1134 struct usb_line6
*line6
;
1135 struct usb_device
*usbdev
;
1136 int interface_number
, i
;
1138 if (interface
== NULL
)
1140 usbdev
= interface_to_usbdev(interface
);
1144 /* removal of additional special files should go here */
1146 sysfs_remove_link(&interface
->dev
.kobj
, "usb_device");
1148 interface_number
= interface
->cur_altsetting
->desc
.bInterfaceNumber
;
1149 line6
= usb_get_intfdata(interface
);
1151 if (line6
!= NULL
) {
1152 if (line6
->urb_listen
!= NULL
)
1153 line6_stop_listen(line6
);
1155 if (usbdev
!= line6
->usbdev
)
1156 dev_err(line6
->ifcdev
,
1157 "driver bug: inconsistent usb device\n");
1159 switch (line6
->usbdev
->descriptor
.idProduct
) {
1160 case LINE6_DEVID_BASSPODXT
:
1161 case LINE6_DEVID_BASSPODXTLIVE
:
1162 case LINE6_DEVID_BASSPODXTPRO
:
1163 case LINE6_DEVID_POCKETPOD
:
1164 case LINE6_DEVID_PODX3
:
1165 case LINE6_DEVID_PODX3LIVE
:
1166 case LINE6_DEVID_PODXT
:
1167 case LINE6_DEVID_PODXTPRO
:
1168 line6_pod_disconnect(interface
);
1171 case LINE6_DEVID_PODHD300
:
1172 case LINE6_DEVID_PODHD500
:
1173 line6_podhd_disconnect(interface
);
1176 case LINE6_DEVID_PODXTLIVE
:
1177 switch (interface_number
) {
1178 case PODXTLIVE_INTERFACE_POD
:
1179 line6_pod_disconnect(interface
);
1182 case PODXTLIVE_INTERFACE_VARIAX
:
1183 line6_variax_disconnect(interface
);
1189 case LINE6_DEVID_VARIAX
:
1190 line6_variax_disconnect(interface
);
1193 case LINE6_DEVID_PODSTUDIO_GX
:
1194 case LINE6_DEVID_PODSTUDIO_UX1
:
1195 case LINE6_DEVID_PODSTUDIO_UX2
:
1196 case LINE6_DEVID_TONEPORT_GX
:
1197 case LINE6_DEVID_TONEPORT_UX1
:
1198 case LINE6_DEVID_TONEPORT_UX2
:
1199 case LINE6_DEVID_GUITARPORT
:
1200 line6_toneport_disconnect(interface
);
1207 dev_info(&interface
->dev
, "Line6 %s now disconnected\n",
1208 line6
->properties
->name
);
1210 for (i
= LINE6_MAX_DEVICES
; i
--;)
1211 if (line6_devices
[i
] == line6
)
1212 line6_devices
[i
] = NULL
;
1215 line6_destruct(interface
);
1217 /* decrement reference counters: */
1218 usb_put_intf(interface
);
1219 usb_put_dev(usbdev
);
1225 Suspend Line6 device.
1227 static int line6_suspend(struct usb_interface
*interface
, pm_message_t message
)
1229 struct usb_line6
*line6
= usb_get_intfdata(interface
);
1230 struct snd_line6_pcm
*line6pcm
= line6
->line6pcm
;
1232 snd_power_change_state(line6
->card
, SNDRV_CTL_POWER_D3hot
);
1234 if (line6
->properties
->capabilities
& LINE6_BIT_CONTROL
)
1235 line6_stop_listen(line6
);
1237 if (line6pcm
!= NULL
) {
1238 snd_pcm_suspend_all(line6pcm
->pcm
);
1239 line6_pcm_disconnect(line6pcm
);
1240 line6pcm
->flags
= 0;
1247 Resume Line6 device.
1249 static int line6_resume(struct usb_interface
*interface
)
1251 struct usb_line6
*line6
= usb_get_intfdata(interface
);
1253 if (line6
->properties
->capabilities
& LINE6_BIT_CONTROL
)
1254 line6_start_listen(line6
);
1256 snd_power_change_state(line6
->card
, SNDRV_CTL_POWER_D0
);
1261 Resume Line6 device after reset.
1263 static int line6_reset_resume(struct usb_interface
*interface
)
1265 struct usb_line6
*line6
= usb_get_intfdata(interface
);
1267 switch (line6
->usbdev
->descriptor
.idProduct
) {
1268 case LINE6_DEVID_PODSTUDIO_GX
:
1269 case LINE6_DEVID_PODSTUDIO_UX1
:
1270 case LINE6_DEVID_PODSTUDIO_UX2
:
1271 case LINE6_DEVID_TONEPORT_GX
:
1272 case LINE6_DEVID_TONEPORT_UX1
:
1273 case LINE6_DEVID_TONEPORT_UX2
:
1274 case LINE6_DEVID_GUITARPORT
:
1275 line6_toneport_reset_resume((struct usb_line6_toneport
*)line6
);
1278 return line6_resume(interface
);
1281 #endif /* CONFIG_PM */
1283 static struct usb_driver line6_driver
= {
1284 .name
= DRIVER_NAME
,
1285 .probe
= line6_probe
,
1286 .disconnect
= line6_disconnect
,
1288 .suspend
= line6_suspend
,
1289 .resume
= line6_resume
,
1290 .reset_resume
= line6_reset_resume
,
1292 .id_table
= line6_id_table
,
1296 Module initialization.
1298 static int __init
line6_init(void)
1302 printk(KERN_INFO
"%s driver version %s\n", DRIVER_NAME
, DRIVER_VERSION
);
1304 for (i
= LINE6_MAX_DEVICES
; i
--;)
1305 line6_devices
[i
] = NULL
;
1307 retval
= usb_register(&line6_driver
);
1310 err("usb_register failed. Error number %d", retval
);
1314 line6_request_version
= kmalloc(sizeof(line6_request_version0
),
1317 if (line6_request_version
== NULL
) {
1318 err("Out of memory");
1322 memcpy((char *)line6_request_version
, line6_request_version0
,
1323 sizeof(line6_request_version0
));
1331 static void __exit
line6_exit(void)
1334 struct usb_line6
*line6
;
1335 struct snd_line6_pcm
*line6pcm
;
1337 /* stop all PCM channels */
1338 for (i
= LINE6_MAX_DEVICES
; i
--;) {
1339 line6
= line6_devices
[i
];
1344 line6pcm
= line6
->line6pcm
;
1346 if (line6pcm
== NULL
)
1349 line6_pcm_stop(line6pcm
, ~0);
1352 usb_deregister(&line6_driver
);
1353 kfree(line6_request_version
);
1356 module_init(line6_init
);
1357 module_exit(line6_exit
);
1359 MODULE_AUTHOR(DRIVER_AUTHOR
);
1360 MODULE_DESCRIPTION(DRIVER_DESC
);
1361 MODULE_LICENSE("GPL");
1362 MODULE_VERSION(DRIVER_VERSION
);