blob: e4078a92d399c13bae12a65a0809dc5f411b556d [file] [log] [blame]
Markus Grabner705ecec2009-02-27 19:43:04 -08001/*
2 * Line6 Linux USB driver - 0.8.0
3 *
4 * Copyright (C) 2004-2009 Markus Grabner (grabner@icg.tugraz.at)
5 *
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.
9 *
10 */
11
12#include "driver.h"
13
14#include <linux/kernel.h>
15#include <linux/module.h>
16#include <linux/usb.h>
17
18#include "audio.h"
19#include "capture.h"
20#include "control.h"
21#include "midi.h"
22#include "playback.h"
23#include "pod.h"
24#include "revision.h"
25#include "toneport.h"
26#include "usbdefs.h"
27#include "variax.h"
28
29
30#define DRIVER_AUTHOR "Markus Grabner <grabner@icg.tugraz.at>"
31#define DRIVER_DESC "Line6 USB Driver"
32#define DRIVER_VERSION "0.8.0"
33
34
35/* table of devices that work with this driver */
36static struct usb_device_id line6_id_table[] = {
37 { USB_DEVICE(LINE6_VENDOR_ID, LINE6_DEVID_BASSPODXT) },
38 { USB_DEVICE(LINE6_VENDOR_ID, LINE6_DEVID_BASSPODXTLIVE) },
39 { USB_DEVICE(LINE6_VENDOR_ID, LINE6_DEVID_BASSPODXTPRO) },
40 { USB_DEVICE(LINE6_VENDOR_ID, LINE6_DEVID_GUITARPORT) },
41 { USB_DEVICE(LINE6_VENDOR_ID, LINE6_DEVID_POCKETPOD) },
42 { USB_DEVICE(LINE6_VENDOR_ID, LINE6_DEVID_PODX3) },
43 { USB_DEVICE(LINE6_VENDOR_ID, LINE6_DEVID_PODX3LIVE) },
44 { USB_DEVICE(LINE6_VENDOR_ID, LINE6_DEVID_PODXT) },
45 { USB_DEVICE(LINE6_VENDOR_ID, LINE6_DEVID_PODXTLIVE) },
46 { USB_DEVICE(LINE6_VENDOR_ID, LINE6_DEVID_PODXTPRO) },
47 { USB_DEVICE(LINE6_VENDOR_ID, LINE6_DEVID_TONEPORT_GX) },
48 { USB_DEVICE(LINE6_VENDOR_ID, LINE6_DEVID_TONEPORT_UX1) },
49 { USB_DEVICE(LINE6_VENDOR_ID, LINE6_DEVID_TONEPORT_UX2) },
50 { USB_DEVICE(LINE6_VENDOR_ID, LINE6_DEVID_VARIAX) },
51 { },
52};
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -080053MODULE_DEVICE_TABLE(usb, line6_id_table);
Markus Grabner705ecec2009-02-27 19:43:04 -080054
55static struct line6_properties line6_properties_table[] = {
56 { "BassPODxt", LINE6_BIT_BASSPODXT, LINE6_BIT_CONTROL_PCM },
57 { "BassPODxt Live", LINE6_BIT_BASSPODXTLIVE, LINE6_BIT_CONTROL_PCM },
58 { "BassPODxt Pro", LINE6_BIT_BASSPODXTPRO, LINE6_BIT_CONTROL_PCM },
59 { "GuitarPort", LINE6_BIT_GUITARPORT, LINE6_BIT_PCM },
60 { "Pocket POD", LINE6_BIT_POCKETPOD, LINE6_BIT_CONTROL_PCM },
61 { "POD X3", LINE6_BIT_PODX3, LINE6_BIT_PCM },
62 { "POD X3 Live", LINE6_BIT_PODX3LIVE, LINE6_BIT_PCM },
63 { "PODxt", LINE6_BIT_PODXT, LINE6_BIT_CONTROL_PCM },
64 { "PODxt Live", LINE6_BIT_PODXTLIVE, LINE6_BIT_CONTROL_PCM },
65 { "PODxt Pro", LINE6_BIT_PODXTPRO, LINE6_BIT_CONTROL_PCM },
66 { "TonePort GX", LINE6_BIT_TONEPORT_GX, LINE6_BIT_PCM },
67 { "TonePort UX1", LINE6_BIT_TONEPORT_UX1, LINE6_BIT_PCM },
68 { "TonePort UX2", LINE6_BIT_TONEPORT_UX2, LINE6_BIT_PCM },
69 { "Variax Workbench", LINE6_BIT_VARIAX, LINE6_BIT_CONTROL }
70};
71
72
73/*
74 This is Line6's MIDI manufacturer ID.
75*/
76const unsigned char line6_midi_id[] = { 0x00, 0x01, 0x0c };
77
78struct usb_line6 *line6_devices[LINE6_MAX_DEVICES];
79struct workqueue_struct *line6_workqueue;
80
81
82/**
83 Class for asynchronous messages.
84*/
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -080085struct message {
Markus Grabner705ecec2009-02-27 19:43:04 -080086 struct usb_line6 *line6;
87 const char *buffer;
88 int size;
89 int done;
90};
91
92
93/*
94 Forward declarations.
95*/
Greg Kroah-Hartman0c7ab152009-02-27 20:28:04 -080096static void line6_data_received(struct urb *urb);
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -080097static int line6_send_raw_message_async_part(struct message *msg,
98 struct urb *urb);
Markus Grabner705ecec2009-02-27 19:43:04 -080099
100
101/*
102 Start to listen on endpoint.
103*/
104static int line6_start_listen(struct usb_line6 *line6)
105{
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800106 usb_fill_int_urb(line6->urb_listen, line6->usbdev,
107 usb_rcvintpipe(line6->usbdev, line6->ep_control_read),
108 line6->buffer_listen, LINE6_BUFSIZE_LISTEN,
109 line6_data_received, line6, line6->interval);
Markus Grabner705ecec2009-02-27 19:43:04 -0800110 line6->urb_listen->actual_length = 0;
111 return usb_submit_urb(line6->urb_listen, GFP_KERNEL);
112}
113
114#if DO_DUMP_ANY
115/*
116 Write hexdump to syslog.
117*/
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800118void line6_write_hexdump(struct usb_line6 *line6, char dir,
119 const unsigned char *buffer, int size)
Markus Grabner705ecec2009-02-27 19:43:04 -0800120{
121 static const int BYTES_PER_LINE = 8;
122 char hexdump[100];
123 char asc[BYTES_PER_LINE + 1];
124 int i, j;
125
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800126 for (i = 0; i < size; i += BYTES_PER_LINE) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800127 int hexdumpsize = sizeof(hexdump);
128 char *p = hexdump;
129 int n = min(size - i, BYTES_PER_LINE);
130 asc[n] = 0;
131
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800132 for (j = 0; j < BYTES_PER_LINE; ++j) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800133 int bytes;
134
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800135 if (j < n) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800136 unsigned char val = buffer[i + j];
137 bytes = snprintf(p, hexdumpsize, " %02X", val);
138 asc[j] = ((val >= 0x20) && (val < 0x7f)) ? val : '.';
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800139 } else
Markus Grabner705ecec2009-02-27 19:43:04 -0800140 bytes = snprintf(p, hexdumpsize, " ");
141
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800142 if (bytes > hexdumpsize)
Markus Grabner705ecec2009-02-27 19:43:04 -0800143 break; /* buffer overflow */
144
145 p += bytes;
146 hexdumpsize -= bytes;
147 }
148
149 dev_info(line6->ifcdev, "%c%04X:%s %s\n", dir, i, hexdump, asc);
150 }
151}
152#endif
153
154#if DO_DUMP_URB_RECEIVE
155/*
156 Dump URB data to syslog.
157*/
158static void line6_dump_urb(struct urb *urb)
159{
160 struct usb_line6 *line6 = (struct usb_line6 *)urb->context;
161
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800162 if (urb->status < 0)
Markus Grabner705ecec2009-02-27 19:43:04 -0800163 return;
164
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800165 line6_write_hexdump(line6, 'R', (unsigned char *)urb->transfer_buffer,
166 urb->actual_length);
Markus Grabner705ecec2009-02-27 19:43:04 -0800167}
168#endif
169
170/*
Frederik Deweerdtd722a512009-09-15 09:29:43 +0000171 Send raw message in pieces of max_packet_size bytes.
Markus Grabner705ecec2009-02-27 19:43:04 -0800172*/
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800173int line6_send_raw_message(struct usb_line6 *line6, const char *buffer,
174 int size)
Markus Grabner705ecec2009-02-27 19:43:04 -0800175{
176 int i, done = 0;
Frederik Deweerdtd722a512009-09-15 09:29:43 +0000177 int actual_size;
Markus Grabner705ecec2009-02-27 19:43:04 -0800178
179#if DO_DUMP_URB_SEND
180 line6_write_hexdump(line6, 'S', buffer, size);
181#endif
182
Frederik Deweerdtd722a512009-09-15 09:29:43 +0000183 for (i = 0; i < size; i += actual_size) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800184 const char *frag_buf = buffer + i;
185 int frag_size = min(line6->max_packet_size, size - i);
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800186 int retval;
Markus Grabner705ecec2009-02-27 19:43:04 -0800187
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800188 retval = usb_interrupt_msg(line6->usbdev,
189 usb_sndintpipe(line6->usbdev,
190 line6->ep_control_write),
191 (char *)frag_buf, frag_size,
Frederik Deweerdtd722a512009-09-15 09:29:43 +0000192 &actual_size, LINE6_TIMEOUT * HZ);
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800193
194 if (retval) {
195 dev_err(line6->ifcdev,
196 "usb_interrupt_msg failed (%d)\n", retval);
Markus Grabner705ecec2009-02-27 19:43:04 -0800197 break;
198 }
199
Frederik Deweerdtd722a512009-09-15 09:29:43 +0000200 done += actual_size;
Markus Grabner705ecec2009-02-27 19:43:04 -0800201 }
202
203 return done;
204}
205
206/*
207 Notification of completion of asynchronous request transmission.
208*/
Greg Kroah-Hartman0c7ab152009-02-27 20:28:04 -0800209static void line6_async_request_sent(struct urb *urb)
Markus Grabner705ecec2009-02-27 19:43:04 -0800210{
211 struct message *msg = (struct message *)urb->context;
212
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800213 if (msg->done >= msg->size) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800214 usb_free_urb(urb);
215 kfree(msg);
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800216 } else
Markus Grabner705ecec2009-02-27 19:43:04 -0800217 line6_send_raw_message_async_part(msg, urb);
218}
219
220/*
221 Asynchronously send part of a raw message.
222*/
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800223static int line6_send_raw_message_async_part(struct message *msg,
224 struct urb *urb)
Markus Grabner705ecec2009-02-27 19:43:04 -0800225{
226 int retval;
227 struct usb_line6 *line6 = msg->line6;
228 int done = msg->done;
229 int bytes = min(msg->size - done, line6->max_packet_size);
230
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800231 usb_fill_int_urb(urb, line6->usbdev,
232 usb_sndintpipe(line6->usbdev, line6->ep_control_write),
233 (char *)msg->buffer + done, bytes,
234 line6_async_request_sent, msg, line6->interval);
Markus Grabner705ecec2009-02-27 19:43:04 -0800235
236#if DO_DUMP_URB_SEND
237 line6_write_hexdump(line6, 'S', (char *)msg->buffer + done, bytes);
238#endif
239
240 msg->done += bytes;
241 retval = usb_submit_urb(urb, GFP_ATOMIC);
242
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800243 if (retval < 0) {
244 dev_err(line6->ifcdev, "%s: usb_submit_urb failed (%d)\n",
245 __func__, retval);
Markus Grabner705ecec2009-02-27 19:43:04 -0800246 usb_free_urb(urb);
247 kfree(msg);
248 return -EINVAL;
249 }
250
251 return 0;
252}
253
254/*
255 Asynchronously send raw message.
256*/
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800257int line6_send_raw_message_async(struct usb_line6 *line6, const char *buffer,
258 int size)
Markus Grabner705ecec2009-02-27 19:43:04 -0800259{
260 struct message *msg;
261 struct urb *urb;
262
263 /* create message: */
264 msg = kmalloc(sizeof(struct message), GFP_ATOMIC);
265
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800266 if (msg == NULL) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800267 dev_err(line6->ifcdev, "Out of memory\n");
268 return -ENOMEM;
269 }
270
271 /* create URB: */
272 urb = usb_alloc_urb(0, GFP_ATOMIC);
273
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800274 if (urb == NULL) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800275 kfree(msg);
276 dev_err(line6->ifcdev, "Out of memory\n");
277 return -ENOMEM;
278 }
279
280 /* set message data: */
281 msg->line6 = line6;
282 msg->buffer = buffer;
283 msg->size = size;
284 msg->done = 0;
285
286 /* start sending: */
287 return line6_send_raw_message_async_part(msg, urb);
288}
289
290/*
291 Send sysex message in pieces of wMaxPacketSize bytes.
292*/
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800293int line6_send_sysex_message(struct usb_line6 *line6, const char *buffer,
294 int size)
Markus Grabner705ecec2009-02-27 19:43:04 -0800295{
296 return line6_send_raw_message(line6, buffer, size + SYSEX_EXTRA_SIZE) - SYSEX_EXTRA_SIZE;
297}
298
299/*
300 Allocate buffer for sysex message and prepare header.
301 @param code sysex message code
302 @param size number of bytes between code and sysex end
303*/
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800304char *line6_alloc_sysex_buffer(struct usb_line6 *line6, int code1, int code2,
305 int size)
Markus Grabner705ecec2009-02-27 19:43:04 -0800306{
307 char *buffer = kmalloc(size + SYSEX_EXTRA_SIZE, GFP_KERNEL);
308
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800309 if (!buffer) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800310 dev_err(line6->ifcdev, "out of memory\n");
Greg Kroah-Hartman536165d2009-02-27 20:49:46 -0800311 return NULL;
Markus Grabner705ecec2009-02-27 19:43:04 -0800312 }
313
314 buffer[0] = LINE6_SYSEX_BEGIN;
315 memcpy(buffer + 1, line6_midi_id, sizeof(line6_midi_id));
316 buffer[sizeof(line6_midi_id) + 1] = code1;
317 buffer[sizeof(line6_midi_id) + 2] = code2;
318 buffer[sizeof(line6_midi_id) + 3 + size] = LINE6_SYSEX_END;
319 return buffer;
320}
321
322/*
323 Notification of data received from the Line6 device.
324*/
Greg Kroah-Hartman0c7ab152009-02-27 20:28:04 -0800325static void line6_data_received(struct urb *urb)
Markus Grabner705ecec2009-02-27 19:43:04 -0800326{
327 struct usb_line6 *line6 = (struct usb_line6 *)urb->context;
328 struct MidiBuffer *mb = &line6->line6midi->midibuf_in;
329 int done;
330
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800331 if (urb->status == -ESHUTDOWN)
Markus Grabner705ecec2009-02-27 19:43:04 -0800332 return;
333
334#if DO_DUMP_URB_RECEIVE
335 line6_dump_urb(urb);
336#endif
337
338 done = midibuf_write(mb, urb->transfer_buffer, urb->actual_length);
339
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800340 if (done < urb->actual_length) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800341 midibuf_ignore(mb, done);
342 DEBUG_MESSAGES(dev_err(line6->ifcdev, "%d %d buffer overflow - message skipped\n", done, urb->actual_length));
343 }
344
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800345 for (;;) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800346 done = midibuf_read(mb, line6->buffer_message, LINE6_MESSAGE_MAXLEN);
347
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800348 if (done == 0)
Markus Grabner705ecec2009-02-27 19:43:04 -0800349 break;
350
351 /* MIDI input filter */
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800352 if (midibuf_skip_message(mb, line6->line6midi->midi_mask_receive))
Markus Grabner705ecec2009-02-27 19:43:04 -0800353 continue;
354
355 line6->message_length = done;
356#if DO_DUMP_MIDI_RECEIVE
357 line6_write_hexdump(line6, 'r', line6->buffer_message, done);
358#endif
359 line6_midi_receive(line6, line6->buffer_message, done);
360
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800361 switch (line6->usbdev->descriptor.idProduct) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800362 case LINE6_DEVID_BASSPODXT:
363 case LINE6_DEVID_BASSPODXTLIVE:
364 case LINE6_DEVID_BASSPODXTPRO:
365 case LINE6_DEVID_PODXT:
366 case LINE6_DEVID_PODXTPRO:
367 case LINE6_DEVID_POCKETPOD:
368 pod_process_message((struct usb_line6_pod *)line6);
369 break;
370
371 case LINE6_DEVID_PODXTLIVE:
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800372 switch (line6->interface_number) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800373 case PODXTLIVE_INTERFACE_POD:
374 pod_process_message((struct usb_line6_pod *)line6);
375 break;
376
377 case PODXTLIVE_INTERFACE_VARIAX:
378 variax_process_message((struct usb_line6_variax *)line6);
379 break;
380
381 default:
382 dev_err(line6->ifcdev, "PODxt Live interface %d not supported\n", line6->interface_number);
383 }
384 break;
385
386 case LINE6_DEVID_VARIAX:
387 variax_process_message((struct usb_line6_variax *)line6);
388 break;
389
390 default:
391 MISSING_CASE;
392 }
393 }
394
395 line6_start_listen(line6);
396}
397
Frederik Deweerdtd722a512009-09-15 09:29:43 +0000398static int line6_send(struct usb_line6 *line6, unsigned char *buf, size_t len)
399{
400 int retval;
401 unsigned int partial;
402
403#if DO_DUMP_URB_SEND
404 line6_write_hexdump(line6, 'S', buf, len);
405#endif
406
407 retval = usb_interrupt_msg(line6->usbdev,
408 usb_sndintpipe(line6->usbdev,
409 line6->ep_control_write),
410 buf, len, &partial,
411 LINE6_TIMEOUT * HZ);
412
413 if (retval) {
414 dev_err(line6->ifcdev,
415 "usb_interrupt_msg failed (%d)\n", retval);
416 }
417
418 if (partial != len) {
419 dev_err(line6->ifcdev,
420 "usb_interrupt_msg sent partial message (%d)\n",
421 retval);
422 }
423
424 return retval;
425}
426
Markus Grabner705ecec2009-02-27 19:43:04 -0800427/*
428 Send channel number (i.e., switch to a different sound).
429*/
430int line6_send_program(struct usb_line6 *line6, int value)
431{
Markus Grabner705ecec2009-02-27 19:43:04 -0800432 unsigned char *buffer;
Frederik Deweerdtd722a512009-09-15 09:29:43 +0000433 size_t len = 2;
Markus Grabner705ecec2009-02-27 19:43:04 -0800434
Frederik Deweerdtd722a512009-09-15 09:29:43 +0000435 buffer = kmalloc(len, GFP_KERNEL);
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800436 if (!buffer) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800437 dev_err(line6->ifcdev, "out of memory\n");
438 return -ENOMEM;
439 }
440
441 buffer[0] = LINE6_PROGRAM_CHANGE | LINE6_CHANNEL_HOST;
442 buffer[1] = value;
443
Frederik Deweerdtd722a512009-09-15 09:29:43 +0000444 return line6_send(line6, buffer, len);
Markus Grabner705ecec2009-02-27 19:43:04 -0800445}
446
447/*
448 Transmit Line6 control parameter.
449*/
450int line6_transmit_parameter(struct usb_line6 *line6, int param, int value)
451{
Markus Grabner705ecec2009-02-27 19:43:04 -0800452 unsigned char *buffer;
Frederik Deweerdtd722a512009-09-15 09:29:43 +0000453 size_t len = 3;
Markus Grabner705ecec2009-02-27 19:43:04 -0800454
Frederik Deweerdtd722a512009-09-15 09:29:43 +0000455 buffer = kmalloc(len, GFP_KERNEL);
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800456 if (!buffer) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800457 dev_err(line6->ifcdev, "out of memory\n");
458 return -ENOMEM;
459 }
460
461 buffer[0] = LINE6_PARAM_CHANGE | LINE6_CHANNEL_HOST;
462 buffer[1] = param;
463 buffer[2] = value;
464
Frederik Deweerdtd722a512009-09-15 09:29:43 +0000465 return line6_send(line6, buffer, len);
Markus Grabner705ecec2009-02-27 19:43:04 -0800466}
467
468/*
469 Read data from device.
470*/
471int line6_read_data(struct usb_line6 *line6, int address, void *data, size_t datalen)
472{
473 struct usb_device *usbdev = line6->usbdev;
474 int ret;
475 unsigned char len;
476
477 /* query the serial number: */
478 ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67,
Frederik Deweerdtd722a512009-09-15 09:29:43 +0000479 USB_TYPE_VENDOR | USB_RECIP_DEVICE
480 | USB_DIR_OUT,
481 (datalen << 8) | 0x21, address,
482 NULL, 0, LINE6_TIMEOUT * HZ);
Markus Grabner705ecec2009-02-27 19:43:04 -0800483
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800484 if (ret < 0) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800485 dev_err(line6->ifcdev, "read request failed (error %d)\n", ret);
486 return ret;
487 }
488
489 /* Wait for data length. We'll get a couple of 0xff until length arrives. */
490 do {
491 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800492 USB_TYPE_VENDOR | USB_RECIP_DEVICE |
493 USB_DIR_IN,
494 0x0012, 0x0000, &len, 1,
495 LINE6_TIMEOUT * HZ);
496 if (ret < 0) {
497 dev_err(line6->ifcdev,
498 "receive length failed (error %d)\n", ret);
Markus Grabner705ecec2009-02-27 19:43:04 -0800499 return ret;
500 }
Frederik Deweerdtd722a512009-09-15 09:29:43 +0000501 } while (len == 0xff);
Markus Grabner705ecec2009-02-27 19:43:04 -0800502
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800503 if (len != datalen) {
504 /* should be equal or something went wrong */
505 dev_err(line6->ifcdev,
506 "length mismatch (expected %d, got %d)\n",
507 (int)datalen, (int)len);
Markus Grabner705ecec2009-02-27 19:43:04 -0800508 return -EINVAL;
509 }
510
511 /* receive the result: */
512 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800513 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
514 0x0013, 0x0000, data, datalen,
515 LINE6_TIMEOUT * HZ);
Markus Grabner705ecec2009-02-27 19:43:04 -0800516
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800517 if (ret < 0) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800518 dev_err(line6->ifcdev, "read failed (error %d)\n", ret);
519 return ret;
520 }
521
522 return 0;
523}
524
525/*
526 Write data to device.
527*/
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800528int line6_write_data(struct usb_line6 *line6, int address, void *data,
529 size_t datalen)
Markus Grabner705ecec2009-02-27 19:43:04 -0800530{
531 struct usb_device *usbdev = line6->usbdev;
532 int ret;
533 unsigned char status;
534
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800535 ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67,
536 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
537 0x0022, address, data, datalen,
538 LINE6_TIMEOUT * HZ);
Markus Grabner705ecec2009-02-27 19:43:04 -0800539
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800540 if (ret < 0) {
541 dev_err(line6->ifcdev,
542 "write request failed (error %d)\n", ret);
Markus Grabner705ecec2009-02-27 19:43:04 -0800543 return ret;
544 }
545
546 do {
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800547 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0),
548 0x67,
549 USB_TYPE_VENDOR | USB_RECIP_DEVICE |
550 USB_DIR_IN,
551 0x0012, 0x0000,
552 &status, 1, LINE6_TIMEOUT * HZ);
Markus Grabner705ecec2009-02-27 19:43:04 -0800553
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800554 if (ret < 0) {
555 dev_err(line6->ifcdev,
556 "receiving status failed (error %d)\n", ret);
Markus Grabner705ecec2009-02-27 19:43:04 -0800557 return ret;
558 }
559 }
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800560 while (status == 0xff)
561 ;
Markus Grabner705ecec2009-02-27 19:43:04 -0800562
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800563 if (status != 0) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800564 dev_err(line6->ifcdev, "write failed (error %d)\n", ret);
565 return -EINVAL;
566 }
567
568 return 0;
569}
570
571/*
572 Read Line6 device serial number.
573 (POD, TonePort, GuitarPort)
574*/
575int line6_read_serial_number(struct usb_line6 *line6, int *serial_number)
576{
577 return line6_read_data(line6, 0x80d0, serial_number, sizeof(*serial_number));
578}
579
580/*
581 No operation (i.e., unsupported).
582*/
Greg Kroah-Hartman77491e52009-02-27 20:25:43 -0800583ssize_t line6_nop_read(struct device *dev, struct device_attribute *attr,
584 char *buf)
Markus Grabner705ecec2009-02-27 19:43:04 -0800585{
586 return 0;
587}
588
589/*
590 No operation (i.e., unsupported).
591*/
Greg Kroah-Hartman77491e52009-02-27 20:25:43 -0800592ssize_t line6_nop_write(struct device *dev, struct device_attribute *attr,
593 const char *buf, size_t count)
Markus Grabner705ecec2009-02-27 19:43:04 -0800594{
595 return count;
596}
597
598/*
599 "write" request on "raw" special file.
600*/
601#if CREATE_RAW_FILE
Greg Kroah-Hartman77491e52009-02-27 20:25:43 -0800602ssize_t line6_set_raw(struct device *dev, struct device_attribute *attr,
603 const char *buf, size_t count)
Markus Grabner705ecec2009-02-27 19:43:04 -0800604{
605 struct usb_interface *interface = to_usb_interface(dev);
606 struct usb_line6 *line6 = usb_get_intfdata(interface);
607 line6_send_raw_message(line6, buf, count);
608 return count;
609}
610#endif
611
612/*
613 Generic destructor.
614*/
615static void line6_destruct(struct usb_interface *interface)
616{
617 struct usb_line6 *line6;
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800618
619 if (interface == NULL)
620 return;
Markus Grabner705ecec2009-02-27 19:43:04 -0800621 line6 = usb_get_intfdata(interface);
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800622 if (line6 == NULL)
623 return;
Markus Grabner705ecec2009-02-27 19:43:04 -0800624
625 /* free buffer memory first: */
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800626 kfree(line6->buffer_message);
627 kfree(line6->buffer_listen);
Markus Grabner705ecec2009-02-27 19:43:04 -0800628
629 /* then free URBs: */
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800630 usb_free_urb(line6->urb_listen);
Markus Grabner705ecec2009-02-27 19:43:04 -0800631
632 /* make sure the device isn't destructed twice: */
633 usb_set_intfdata(interface, NULL);
634
635 /* free interface data: */
636 kfree(line6);
637}
638
639static void line6_list_devices(void)
640{
641 int i;
642
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800643 for (i = 0; i < LINE6_MAX_DEVICES; ++i) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800644 struct usb_line6 *dev = line6_devices[i];
645 printk(KERN_INFO "Line6 device %d: ", i);
646
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800647 if (dev == NULL)
Markus Grabner705ecec2009-02-27 19:43:04 -0800648 printk("(not used)\n");
649 else
650 printk("%s:%d\n", dev->properties->name, dev->interface_number);
651 }
652}
653
654/*
655 Probe USB device.
656*/
657static int line6_probe(struct usb_interface *interface, const struct usb_device_id *id)
658{
659 int devtype;
Greg Kroah-Hartman536165d2009-02-27 20:49:46 -0800660 struct usb_device *usbdev = NULL;
661 struct usb_line6 *line6 = NULL;
Markus Grabner705ecec2009-02-27 19:43:04 -0800662 const struct line6_properties *properties;
663 int devnum;
664 int interface_number, alternate = 0;
665 int product;
666 int size = 0;
667 int ep_read = 0, ep_write = 0;
668 int ret;
669
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800670 if (interface == NULL)
671 return -ENODEV;
Markus Grabner705ecec2009-02-27 19:43:04 -0800672 usbdev = interface_to_usbdev(interface);
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800673 if (usbdev == NULL)
674 return -ENODEV;
Markus Grabner705ecec2009-02-27 19:43:04 -0800675
676 /* increment reference counters: */
677 usb_get_intf(interface);
678 usb_get_dev(usbdev);
679
680 /* we don't handle multiple configurations */
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800681 if (usbdev->descriptor.bNumConfigurations != 1)
Markus Grabner705ecec2009-02-27 19:43:04 -0800682 return -ENODEV;
683
684 /* check vendor and product id */
Frederik Deweerdtd722a512009-09-15 09:29:43 +0000685 for (devtype = ARRAY_SIZE(line6_id_table) - 1; devtype--;) {
686 u16 vendor = le16_to_cpu(usbdev->descriptor.idVendor);
687 u16 product = le16_to_cpu(usbdev->descriptor.idProduct);
688
689 if (vendor == line6_id_table[devtype].idVendor
690 && product == line6_id_table[devtype].idProduct)
Markus Grabner705ecec2009-02-27 19:43:04 -0800691 break;
Frederik Deweerdtd722a512009-09-15 09:29:43 +0000692 }
Markus Grabner705ecec2009-02-27 19:43:04 -0800693
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800694 if (devtype < 0)
Markus Grabner705ecec2009-02-27 19:43:04 -0800695 return -ENODEV;
696
697 /* find free slot in device table: */
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800698 for (devnum = 0; devnum < LINE6_MAX_DEVICES; ++devnum)
699 if (line6_devices[devnum] == NULL)
Markus Grabner705ecec2009-02-27 19:43:04 -0800700 break;
701
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800702 if (devnum == LINE6_MAX_DEVICES)
Markus Grabner705ecec2009-02-27 19:43:04 -0800703 return -ENODEV;
704
705 /* initialize device info: */
706 properties = &line6_properties_table[devtype];
707 dev_info(&interface->dev, "Line6 %s found\n", properties->name);
708 product = le16_to_cpu(usbdev->descriptor.idProduct);
709
710 /* query interface number */
711 interface_number = interface->cur_altsetting->desc.bInterfaceNumber;
712
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800713 switch (product) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800714 case LINE6_DEVID_BASSPODXTLIVE:
715 case LINE6_DEVID_POCKETPOD:
716 case LINE6_DEVID_PODXTLIVE:
717 case LINE6_DEVID_VARIAX:
718 alternate = 1;
719 break;
720
721 case LINE6_DEVID_PODX3:
722 case LINE6_DEVID_PODX3LIVE:
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800723 switch (interface_number) {
724 case 0:
725 alternate = 1;
726 break;
727 case 1:
728 alternate = 0;
729 break;
730 default:
731 MISSING_CASE;
Markus Grabner705ecec2009-02-27 19:43:04 -0800732 }
733 break;
734
735 case LINE6_DEVID_BASSPODXT:
736 case LINE6_DEVID_BASSPODXTPRO:
737 case LINE6_DEVID_PODXT:
738 case LINE6_DEVID_PODXTPRO:
739 alternate = 5;
740 break;
741
742 case LINE6_DEVID_TONEPORT_GX:
743 case LINE6_DEVID_GUITARPORT:
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800744 alternate = 2; /* 1..4 seem to be ok */
Markus Grabner705ecec2009-02-27 19:43:04 -0800745 break;
746
747 case LINE6_DEVID_TONEPORT_UX1:
748 case LINE6_DEVID_TONEPORT_UX2:
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800749 switch (interface_number) {
750 case 0:
751 /* defaults to 44.1kHz, 16-bit */
752 alternate = 2;
753 break;
754 case 1:
755 alternate = 0;
756 break;
757 default:
758 MISSING_CASE;
Markus Grabner705ecec2009-02-27 19:43:04 -0800759 }
760 break;
761
762 default:
763 MISSING_CASE;
764 return -ENODEV;
765 }
766
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800767 ret = usb_set_interface(usbdev, interface_number, alternate);
768 if (ret < 0) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800769 dev_err(&interface->dev, "set_interface failed\n");
770 return ret;
771 }
772
773 /* initialize device data based on product id: */
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800774 switch (product) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800775 case LINE6_DEVID_BASSPODXT:
776 case LINE6_DEVID_BASSPODXTLIVE:
777 case LINE6_DEVID_BASSPODXTPRO:
778 case LINE6_DEVID_POCKETPOD:
779 case LINE6_DEVID_PODXT:
780 case LINE6_DEVID_PODXTPRO:
781 size = sizeof(struct usb_line6_pod);
782 ep_read = 0x84;
783 ep_write = 0x03;
784 break;
785
786 case LINE6_DEVID_PODX3:
787 case LINE6_DEVID_PODX3LIVE:
788 /* currently unused! */
789 size = sizeof(struct usb_line6_pod);
790 ep_read = 0x81;
791 ep_write = 0x01;
792 break;
793
794 case LINE6_DEVID_TONEPORT_GX:
795 case LINE6_DEVID_TONEPORT_UX1:
796 case LINE6_DEVID_TONEPORT_UX2:
797 case LINE6_DEVID_GUITARPORT:
798 size = sizeof(struct usb_line6_toneport);
799 /* these don't have a control channel */
800 break;
801
802 case LINE6_DEVID_PODXTLIVE:
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800803 switch (interface_number) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800804 case PODXTLIVE_INTERFACE_POD:
805 size = sizeof(struct usb_line6_pod);
806 ep_read = 0x84;
807 ep_write = 0x03;
808 break;
809
810 case PODXTLIVE_INTERFACE_VARIAX:
811 size = sizeof(struct usb_line6_variax);
812 ep_read = 0x86;
813 ep_write = 0x05;
814 break;
815
816 default:
817 return -ENODEV;
818 }
819 break;
820
821 case LINE6_DEVID_VARIAX:
822 size = sizeof(struct usb_line6_variax);
823 ep_read = 0x82;
824 ep_write = 0x01;
825 break;
826
827 default:
828 MISSING_CASE;
829 return -ENODEV;
830 }
831
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800832 if (size == 0) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800833 dev_err(line6->ifcdev, "driver bug: interface data size not set\n");
834 return -ENODEV;
835 }
836
837 line6 = kzalloc(size, GFP_KERNEL);
838
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800839 if (line6 == NULL) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800840 dev_err(&interface->dev, "Out of memory\n");
841 return -ENOMEM;
842 }
843
844 /* store basic data: */
845 line6->interface_number = interface_number;
846 line6->properties = properties;
847 line6->usbdev = usbdev;
848 line6->ifcdev = &interface->dev;
849 line6->ep_control_read = ep_read;
850 line6->ep_control_write = ep_write;
851 line6->product = product;
852
853 /* get data from endpoint descriptor (see usb_maxpacket): */
854 {
855 struct usb_host_endpoint *ep;
856 unsigned epnum = usb_pipeendpoint(usb_rcvintpipe(usbdev, ep_read));
857 ep = usbdev->ep_in[epnum];
858
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800859 if (ep != NULL) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800860 line6->interval = ep->desc.bInterval;
861 line6->max_packet_size = le16_to_cpu(ep->desc.wMaxPacketSize);
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800862 } else {
Markus Grabner705ecec2009-02-27 19:43:04 -0800863 line6->interval = LINE6_FALLBACK_INTERVAL;
864 line6->max_packet_size = LINE6_FALLBACK_MAXPACKETSIZE;
865 dev_err(line6->ifcdev, "endpoint not available, using fallback values");
866 }
867 }
868
869 usb_set_intfdata(interface, line6);
870
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800871 if (properties->capabilities & LINE6_BIT_CONTROL) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800872 /* initialize USB buffers: */
873 line6->buffer_listen = kmalloc(LINE6_BUFSIZE_LISTEN, GFP_KERNEL);
874
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800875 if (line6->buffer_listen == NULL) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800876 dev_err(&interface->dev, "Out of memory\n");
877 line6_destruct(interface);
878 return -ENOMEM;
879 }
880
881 line6->buffer_message = kmalloc(LINE6_MESSAGE_MAXLEN, GFP_KERNEL);
882
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800883 if (line6->buffer_message == NULL) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800884 dev_err(&interface->dev, "Out of memory\n");
885 line6_destruct(interface);
886 return -ENOMEM;
887 }
888
889 line6->urb_listen = usb_alloc_urb(0, GFP_KERNEL);
890
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800891 if (line6->urb_listen == NULL) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800892 dev_err(&interface->dev, "Out of memory\n");
893 line6_destruct(interface);
894 return -ENOMEM;
895 }
896
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800897 ret = line6_start_listen(line6);
898 if (ret < 0) {
899 dev_err(&interface->dev, "%s: usb_submit_urb failed\n",
900 __func__);
Markus Grabner705ecec2009-02-27 19:43:04 -0800901 line6_destruct(interface);
902 return ret;
903 }
904 }
905
906 /* initialize device data based on product id: */
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800907 switch (product) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800908 case LINE6_DEVID_BASSPODXT:
909 case LINE6_DEVID_BASSPODXTLIVE:
910 case LINE6_DEVID_BASSPODXTPRO:
911 case LINE6_DEVID_POCKETPOD:
912 case LINE6_DEVID_PODX3:
913 case LINE6_DEVID_PODX3LIVE:
914 case LINE6_DEVID_PODXT:
915 case LINE6_DEVID_PODXTPRO:
916 ret = pod_init(interface, (struct usb_line6_pod *)line6);
917 break;
918
919 case LINE6_DEVID_PODXTLIVE:
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800920 switch (interface_number) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800921 case PODXTLIVE_INTERFACE_POD:
922 ret = pod_init(interface, (struct usb_line6_pod *)line6);
923 break;
924
925 case PODXTLIVE_INTERFACE_VARIAX:
926 ret = variax_init(interface, (struct usb_line6_variax *)line6);
927 break;
928
929 default:
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800930 dev_err(&interface->dev,
931 "PODxt Live interface %d not supported\n",
932 interface_number);
Markus Grabner705ecec2009-02-27 19:43:04 -0800933 ret = -ENODEV;
934 }
935
936 break;
937
938 case LINE6_DEVID_VARIAX:
939 ret = variax_init(interface, (struct usb_line6_variax *)line6);
940 break;
941
942 case LINE6_DEVID_TONEPORT_GX:
943 case LINE6_DEVID_TONEPORT_UX1:
944 case LINE6_DEVID_TONEPORT_UX2:
945 case LINE6_DEVID_GUITARPORT:
946 ret = toneport_init(interface, (struct usb_line6_toneport *)line6);
947 break;
948
949 default:
950 MISSING_CASE;
951 ret = -ENODEV;
952 }
953
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800954 if (ret < 0) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800955 line6_destruct(interface);
956 return ret;
957 }
958
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800959 ret = sysfs_create_link(&interface->dev.kobj, &usbdev->dev.kobj,
960 "usb_device");
961 if (ret < 0) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800962 line6_destruct(interface);
963 return ret;
964 }
965
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800966 dev_info(&interface->dev, "Line6 %s now attached\n",
967 line6->properties->name);
Markus Grabner705ecec2009-02-27 19:43:04 -0800968 line6_devices[devnum] = line6;
969 line6_list_devices();
970 return ret;
971}
972
973/*
974 Line6 device disconnected.
975*/
976static void line6_disconnect(struct usb_interface *interface)
977{
978 struct usb_line6 *line6;
979 struct usb_device *usbdev;
980 int interface_number, i;
981
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800982 if (interface == NULL)
983 return;
Markus Grabner705ecec2009-02-27 19:43:04 -0800984 usbdev = interface_to_usbdev(interface);
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800985 if (usbdev == NULL)
986 return;
Markus Grabner705ecec2009-02-27 19:43:04 -0800987
988 sysfs_remove_link(&interface->dev.kobj, "usb_device");
989
990 interface_number = interface->cur_altsetting->desc.bInterfaceNumber;
991 line6 = usb_get_intfdata(interface);
992
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800993 if (line6 != NULL) {
994 if (line6->urb_listen != NULL)
995 usb_kill_urb(line6->urb_listen);
Markus Grabner705ecec2009-02-27 19:43:04 -0800996
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800997 if (usbdev != line6->usbdev)
998 dev_err(line6->ifcdev,
999 "driver bug: inconsistent usb device\n");
Markus Grabner705ecec2009-02-27 19:43:04 -08001000
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -08001001 switch (line6->usbdev->descriptor.idProduct) {
Markus Grabner705ecec2009-02-27 19:43:04 -08001002 case LINE6_DEVID_BASSPODXT:
1003 case LINE6_DEVID_BASSPODXTLIVE:
1004 case LINE6_DEVID_BASSPODXTPRO:
1005 case LINE6_DEVID_POCKETPOD:
1006 case LINE6_DEVID_PODX3:
1007 case LINE6_DEVID_PODX3LIVE:
1008 case LINE6_DEVID_PODXT:
1009 case LINE6_DEVID_PODXTPRO:
1010 pod_disconnect(interface);
1011 break;
1012
1013 case LINE6_DEVID_PODXTLIVE:
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -08001014 switch (interface_number) {
Markus Grabner705ecec2009-02-27 19:43:04 -08001015 case PODXTLIVE_INTERFACE_POD:
1016 pod_disconnect(interface);
1017 break;
1018
1019 case PODXTLIVE_INTERFACE_VARIAX:
1020 variax_disconnect(interface);
1021 break;
1022 }
1023
1024 break;
1025
1026 case LINE6_DEVID_VARIAX:
1027 variax_disconnect(interface);
1028 break;
1029
1030 case LINE6_DEVID_TONEPORT_GX:
1031 case LINE6_DEVID_TONEPORT_UX1:
1032 case LINE6_DEVID_TONEPORT_UX2:
1033 case LINE6_DEVID_GUITARPORT:
1034 toneport_disconnect(interface);
1035 break;
1036
1037 default:
1038 MISSING_CASE;
1039 }
1040
1041 dev_info(&interface->dev, "Line6 %s now disconnected\n", line6->properties->name);
1042
Frederik Deweerdtd722a512009-09-15 09:29:43 +00001043 for (i = LINE6_MAX_DEVICES; i--;) {
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -08001044 if (line6_devices[i] == line6)
Greg Kroah-Hartman536165d2009-02-27 20:49:46 -08001045 line6_devices[i] = NULL;
Frederik Deweerdtd722a512009-09-15 09:29:43 +00001046 }
Markus Grabner705ecec2009-02-27 19:43:04 -08001047 }
1048
1049 line6_destruct(interface);
1050
1051 /* decrement reference counters: */
1052 usb_put_intf(interface);
1053 usb_put_dev(usbdev);
1054
1055 line6_list_devices();
1056}
1057
1058static struct usb_driver line6_driver = {
Markus Grabner705ecec2009-02-27 19:43:04 -08001059 .name = DRIVER_NAME,
1060 .probe = line6_probe,
1061 .disconnect = line6_disconnect,
1062 .id_table = line6_id_table,
1063};
1064
1065/*
1066 Module initialization.
1067*/
1068static int __init line6_init(void)
1069{
1070 int i, retval;
1071
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -08001072 printk(KERN_INFO "%s driver version %s%s\n",
1073 DRIVER_NAME, DRIVER_VERSION, DRIVER_REVISION);
Markus Grabner705ecec2009-02-27 19:43:04 -08001074 line6_workqueue = create_workqueue(DRIVER_NAME);
1075
Greg Kroah-Hartman536165d2009-02-27 20:49:46 -08001076 if (line6_workqueue == NULL) {
Markus Grabner705ecec2009-02-27 19:43:04 -08001077 err("couldn't create workqueue");
1078 return -EINVAL;
1079 }
1080
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -08001081 for (i = LINE6_MAX_DEVICES; i--;)
Greg Kroah-Hartman536165d2009-02-27 20:49:46 -08001082 line6_devices[i] = NULL;
Markus Grabner705ecec2009-02-27 19:43:04 -08001083
1084 retval = usb_register(&line6_driver);
1085
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -08001086 if (retval)
Markus Grabner705ecec2009-02-27 19:43:04 -08001087 err("usb_register failed. Error number %d", retval);
1088
1089 return retval;
1090}
1091
1092/*
1093 Module cleanup.
1094*/
1095static void __exit line6_exit(void)
1096{
1097 destroy_workqueue(line6_workqueue);
1098 usb_deregister(&line6_driver);
1099}
1100
1101module_init(line6_init);
1102module_exit(line6_exit);
1103
1104MODULE_AUTHOR(DRIVER_AUTHOR);
1105MODULE_DESCRIPTION(DRIVER_DESC);
1106MODULE_LICENSE("GPL");
1107MODULE_VERSION(DRIVER_VERSION);