PM / sleep: Asynchronous threads for suspend_noirq
[linux/fpc-iii.git] / drivers / staging / line6 / driver.c
blob7a6d85ebb29b006b235261c0f180c85e61296b23
1 /*
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>
17 #include "audio.h"
18 #include "capture.h"
19 #include "driver.h"
20 #include "midi.h"
21 #include "playback.h"
22 #include "pod.h"
23 #include "podhd.h"
24 #include "revision.h"
25 #include "toneport.h"
26 #include "usbdefs.h"
27 #include "variax.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_PODHD300)},
41 {USB_DEVICE(LINE6_VENDOR_ID, LINE6_DEVID_PODHD400)},
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)},
55 {},
58 MODULE_DEVICE_TABLE(usb, line6_id_table);
60 /* *INDENT-OFF* */
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_PODHD400, "PODHD400", "POD HD400", LINE6_BIT_CONTROL_PCM_HWMON },
69 { LINE6_BIT_PODHD500, "PODHD500", "POD HD500", LINE6_BIT_CONTROL_PCM_HWMON },
70 { LINE6_BIT_PODSTUDIO_GX, "PODStudioGX", "POD Studio GX", LINE6_BIT_PCM },
71 { LINE6_BIT_PODSTUDIO_UX1, "PODStudioUX1", "POD Studio UX1", LINE6_BIT_PCM },
72 { LINE6_BIT_PODSTUDIO_UX2, "PODStudioUX2", "POD Studio UX2", LINE6_BIT_PCM },
73 { LINE6_BIT_PODX3, "PODX3", "POD X3", LINE6_BIT_PCM },
74 { LINE6_BIT_PODX3LIVE, "PODX3Live", "POD X3 Live", LINE6_BIT_PCM },
75 { LINE6_BIT_PODXT, "PODxt", "PODxt", LINE6_BIT_CONTROL_PCM_HWMON },
76 { LINE6_BIT_PODXTLIVE, "PODxtLive", "PODxt Live", LINE6_BIT_CONTROL_PCM_HWMON },
77 { LINE6_BIT_PODXTPRO, "PODxtPro", "PODxt Pro", LINE6_BIT_CONTROL_PCM_HWMON },
78 { LINE6_BIT_TONEPORT_GX, "TonePortGX", "TonePort GX", LINE6_BIT_PCM },
79 { LINE6_BIT_TONEPORT_UX1, "TonePortUX1", "TonePort UX1", LINE6_BIT_PCM },
80 { LINE6_BIT_TONEPORT_UX2, "TonePortUX2", "TonePort UX2", LINE6_BIT_PCM },
81 { LINE6_BIT_VARIAX, "Variax", "Variax Workbench", LINE6_BIT_CONTROL },
83 /* *INDENT-ON* */
86 This is Line6's MIDI manufacturer ID.
88 const unsigned char line6_midi_id[] = {
89 0x00, 0x01, 0x0c
93 Code to request version of POD, Variax interface
94 (and maybe other devices).
96 static const char line6_request_version[] = {
97 0xf0, 0x7e, 0x7f, 0x06, 0x01, 0xf7
101 Class for asynchronous messages.
103 struct message {
104 struct usb_line6 *line6;
105 const char *buffer;
106 int size;
107 int done;
111 Forward declarations.
113 static void line6_data_received(struct urb *urb);
114 static int line6_send_raw_message_async_part(struct message *msg,
115 struct urb *urb);
118 Start to listen on endpoint.
120 static int line6_start_listen(struct usb_line6 *line6)
122 int err;
123 usb_fill_int_urb(line6->urb_listen, line6->usbdev,
124 usb_rcvintpipe(line6->usbdev, line6->ep_control_read),
125 line6->buffer_listen, LINE6_BUFSIZE_LISTEN,
126 line6_data_received, line6, line6->interval);
127 line6->urb_listen->actual_length = 0;
128 err = usb_submit_urb(line6->urb_listen, GFP_ATOMIC);
129 return err;
133 Stop listening on endpoint.
135 static void line6_stop_listen(struct usb_line6 *line6)
137 usb_kill_urb(line6->urb_listen);
141 Send raw message in pieces of wMaxPacketSize bytes.
143 int line6_send_raw_message(struct usb_line6 *line6, const char *buffer,
144 int size)
146 int i, done = 0;
148 for (i = 0; i < size; i += line6->max_packet_size) {
149 int partial;
150 const char *frag_buf = buffer + i;
151 int frag_size = min(line6->max_packet_size, size - i);
152 int retval;
154 retval = usb_interrupt_msg(line6->usbdev,
155 usb_sndintpipe(line6->usbdev,
156 line6->ep_control_write),
157 (char *)frag_buf, frag_size,
158 &partial, LINE6_TIMEOUT * HZ);
160 if (retval) {
161 dev_err(line6->ifcdev,
162 "usb_interrupt_msg failed (%d)\n", retval);
163 break;
166 done += frag_size;
169 return done;
173 Notification of completion of asynchronous request transmission.
175 static void line6_async_request_sent(struct urb *urb)
177 struct message *msg = (struct message *)urb->context;
179 if (msg->done >= msg->size) {
180 usb_free_urb(urb);
181 kfree(msg);
182 } else
183 line6_send_raw_message_async_part(msg, urb);
187 Asynchronously send part of a raw message.
189 static int line6_send_raw_message_async_part(struct message *msg,
190 struct urb *urb)
192 int retval;
193 struct usb_line6 *line6 = msg->line6;
194 int done = msg->done;
195 int bytes = min(msg->size - done, line6->max_packet_size);
197 usb_fill_int_urb(urb, line6->usbdev,
198 usb_sndintpipe(line6->usbdev, line6->ep_control_write),
199 (char *)msg->buffer + done, bytes,
200 line6_async_request_sent, msg, line6->interval);
202 msg->done += bytes;
203 retval = usb_submit_urb(urb, GFP_ATOMIC);
205 if (retval < 0) {
206 dev_err(line6->ifcdev, "%s: usb_submit_urb failed (%d)\n",
207 __func__, retval);
208 usb_free_urb(urb);
209 kfree(msg);
210 return retval;
213 return 0;
217 Setup and start timer.
219 void line6_start_timer(struct timer_list *timer, unsigned int msecs,
220 void (*function) (unsigned long), unsigned long data)
222 setup_timer(timer, function, data);
223 timer->expires = jiffies + msecs * HZ / 1000;
224 add_timer(timer);
228 Asynchronously send raw message.
230 int line6_send_raw_message_async(struct usb_line6 *line6, const char *buffer,
231 int size)
233 struct message *msg;
234 struct urb *urb;
236 /* create message: */
237 msg = kmalloc(sizeof(struct message), GFP_ATOMIC);
238 if (msg == NULL)
239 return -ENOMEM;
241 /* create URB: */
242 urb = usb_alloc_urb(0, GFP_ATOMIC);
244 if (urb == NULL) {
245 kfree(msg);
246 dev_err(line6->ifcdev, "Out of memory\n");
247 return -ENOMEM;
250 /* set message data: */
251 msg->line6 = line6;
252 msg->buffer = buffer;
253 msg->size = size;
254 msg->done = 0;
256 /* start sending: */
257 return line6_send_raw_message_async_part(msg, urb);
261 Send asynchronous device version request.
263 int line6_version_request_async(struct usb_line6 *line6)
265 char *buffer;
266 int retval;
268 buffer = kmemdup(line6_request_version,
269 sizeof(line6_request_version), GFP_ATOMIC);
270 if (buffer == NULL) {
271 dev_err(line6->ifcdev, "Out of memory");
272 return -ENOMEM;
275 retval = line6_send_raw_message_async(line6, buffer,
276 sizeof(line6_request_version));
277 kfree(buffer);
278 return retval;
282 Send sysex message in pieces of wMaxPacketSize bytes.
284 int line6_send_sysex_message(struct usb_line6 *line6, const char *buffer,
285 int size)
287 return line6_send_raw_message(line6, buffer,
288 size + SYSEX_EXTRA_SIZE) -
289 SYSEX_EXTRA_SIZE;
293 Allocate buffer for sysex message and prepare header.
294 @param code sysex message code
295 @param size number of bytes between code and sysex end
297 char *line6_alloc_sysex_buffer(struct usb_line6 *line6, int code1, int code2,
298 int size)
300 char *buffer = kmalloc(size + SYSEX_EXTRA_SIZE, GFP_ATOMIC);
302 if (!buffer)
303 return NULL;
305 buffer[0] = LINE6_SYSEX_BEGIN;
306 memcpy(buffer + 1, line6_midi_id, sizeof(line6_midi_id));
307 buffer[sizeof(line6_midi_id) + 1] = code1;
308 buffer[sizeof(line6_midi_id) + 2] = code2;
309 buffer[sizeof(line6_midi_id) + 3 + size] = LINE6_SYSEX_END;
310 return buffer;
314 Notification of data received from the Line6 device.
316 static void line6_data_received(struct urb *urb)
318 struct usb_line6 *line6 = (struct usb_line6 *)urb->context;
319 struct midi_buffer *mb = &line6->line6midi->midibuf_in;
320 int done;
322 if (urb->status == -ESHUTDOWN)
323 return;
325 done =
326 line6_midibuf_write(mb, urb->transfer_buffer, urb->actual_length);
328 if (done < urb->actual_length) {
329 line6_midibuf_ignore(mb, done);
330 dev_dbg(line6->ifcdev, "%d %d buffer overflow - message skipped\n",
331 done, urb->actual_length);
334 for (;;) {
335 done =
336 line6_midibuf_read(mb, line6->buffer_message,
337 LINE6_MESSAGE_MAXLEN);
339 if (done == 0)
340 break;
342 line6->message_length = done;
343 line6_midi_receive(line6, line6->buffer_message, done);
345 switch (le16_to_cpu(line6->usbdev->descriptor.idProduct)) {
346 case LINE6_DEVID_BASSPODXT:
347 case LINE6_DEVID_BASSPODXTLIVE:
348 case LINE6_DEVID_BASSPODXTPRO:
349 case LINE6_DEVID_PODXT:
350 case LINE6_DEVID_PODXTPRO:
351 case LINE6_DEVID_POCKETPOD:
352 line6_pod_process_message((struct usb_line6_pod *)
353 line6);
354 break;
356 case LINE6_DEVID_PODHD300:
357 case LINE6_DEVID_PODHD400:
358 case LINE6_DEVID_PODHD500:
359 break; /* let userspace handle MIDI */
361 case LINE6_DEVID_PODXTLIVE:
362 switch (line6->interface_number) {
363 case PODXTLIVE_INTERFACE_POD:
364 line6_pod_process_message((struct usb_line6_pod
365 *)line6);
366 break;
368 case PODXTLIVE_INTERFACE_VARIAX:
369 line6_variax_process_message((struct
370 usb_line6_variax
371 *)line6);
372 break;
374 default:
375 dev_err(line6->ifcdev,
376 "PODxt Live interface %d not supported\n",
377 line6->interface_number);
379 break;
381 case LINE6_DEVID_VARIAX:
382 line6_variax_process_message((struct usb_line6_variax *)
383 line6);
384 break;
386 default:
387 MISSING_CASE;
391 line6_start_listen(line6);
395 Send channel number (i.e., switch to a different sound).
397 int line6_send_program(struct usb_line6 *line6, u8 value)
399 int retval;
400 unsigned char *buffer;
401 int partial;
403 buffer = kmalloc(2, GFP_KERNEL);
404 if (!buffer)
405 return -ENOMEM;
407 buffer[0] = LINE6_PROGRAM_CHANGE | LINE6_CHANNEL_HOST;
408 buffer[1] = value;
410 retval = usb_interrupt_msg(line6->usbdev,
411 usb_sndintpipe(line6->usbdev,
412 line6->ep_control_write),
413 buffer, 2, &partial, LINE6_TIMEOUT * HZ);
415 if (retval)
416 dev_err(line6->ifcdev, "usb_interrupt_msg failed (%d)\n",
417 retval);
419 kfree(buffer);
420 return retval;
424 Transmit Line6 control parameter.
426 int line6_transmit_parameter(struct usb_line6 *line6, int param, u8 value)
428 int retval;
429 unsigned char *buffer;
430 int partial;
432 buffer = kmalloc(3, GFP_KERNEL);
433 if (!buffer)
434 return -ENOMEM;
436 buffer[0] = LINE6_PARAM_CHANGE | LINE6_CHANNEL_HOST;
437 buffer[1] = param;
438 buffer[2] = value;
440 retval = usb_interrupt_msg(line6->usbdev,
441 usb_sndintpipe(line6->usbdev,
442 line6->ep_control_write),
443 buffer, 3, &partial, LINE6_TIMEOUT * HZ);
445 if (retval)
446 dev_err(line6->ifcdev, "usb_interrupt_msg failed (%d)\n",
447 retval);
449 kfree(buffer);
450 return retval;
454 Read data from device.
456 int line6_read_data(struct usb_line6 *line6, int address, void *data,
457 size_t datalen)
459 struct usb_device *usbdev = line6->usbdev;
460 int ret;
461 unsigned char len;
463 /* query the serial number: */
464 ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67,
465 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
466 (datalen << 8) | 0x21, address,
467 NULL, 0, LINE6_TIMEOUT * HZ);
469 if (ret < 0) {
470 dev_err(line6->ifcdev, "read request failed (error %d)\n", ret);
471 return ret;
474 /* Wait for data length. We'll get 0xff until length arrives. */
475 do {
476 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
477 USB_TYPE_VENDOR | USB_RECIP_DEVICE |
478 USB_DIR_IN,
479 0x0012, 0x0000, &len, 1,
480 LINE6_TIMEOUT * HZ);
481 if (ret < 0) {
482 dev_err(line6->ifcdev,
483 "receive length failed (error %d)\n", ret);
484 return ret;
486 } while (len == 0xff);
488 if (len != datalen) {
489 /* should be equal or something went wrong */
490 dev_err(line6->ifcdev,
491 "length mismatch (expected %d, got %d)\n",
492 (int)datalen, (int)len);
493 return -EINVAL;
496 /* receive the result: */
497 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
498 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
499 0x0013, 0x0000, data, datalen,
500 LINE6_TIMEOUT * HZ);
502 if (ret < 0) {
503 dev_err(line6->ifcdev, "read failed (error %d)\n", ret);
504 return ret;
507 return 0;
511 Write data to device.
513 int line6_write_data(struct usb_line6 *line6, int address, void *data,
514 size_t datalen)
516 struct usb_device *usbdev = line6->usbdev;
517 int ret;
518 unsigned char status;
520 ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67,
521 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
522 0x0022, address, data, datalen,
523 LINE6_TIMEOUT * HZ);
525 if (ret < 0) {
526 dev_err(line6->ifcdev,
527 "write request failed (error %d)\n", ret);
528 return ret;
531 do {
532 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0),
533 0x67,
534 USB_TYPE_VENDOR | USB_RECIP_DEVICE |
535 USB_DIR_IN,
536 0x0012, 0x0000,
537 &status, 1, LINE6_TIMEOUT * HZ);
539 if (ret < 0) {
540 dev_err(line6->ifcdev,
541 "receiving status failed (error %d)\n", ret);
542 return ret;
544 } while (status == 0xff);
546 if (status != 0) {
547 dev_err(line6->ifcdev, "write failed (error %d)\n", ret);
548 return -EINVAL;
551 return 0;
555 Read Line6 device serial number.
556 (POD, TonePort, GuitarPort)
558 int line6_read_serial_number(struct usb_line6 *line6, int *serial_number)
560 return line6_read_data(line6, 0x80d0, serial_number,
561 sizeof(*serial_number));
565 No operation (i.e., unsupported).
567 ssize_t line6_nop_read(struct device *dev, struct device_attribute *attr,
568 char *buf)
570 return 0;
574 Generic destructor.
576 static void line6_destruct(struct usb_interface *interface)
578 struct usb_line6 *line6;
580 if (interface == NULL)
581 return;
582 line6 = usb_get_intfdata(interface);
583 if (line6 == NULL)
584 return;
586 /* free buffer memory first: */
587 kfree(line6->buffer_message);
588 kfree(line6->buffer_listen);
590 /* then free URBs: */
591 usb_free_urb(line6->urb_listen);
593 /* make sure the device isn't destructed twice: */
594 usb_set_intfdata(interface, NULL);
596 /* free interface data: */
597 kfree(line6);
601 Probe USB device.
603 static int line6_probe(struct usb_interface *interface,
604 const struct usb_device_id *id)
606 int devtype;
607 struct usb_device *usbdev;
608 struct usb_line6 *line6;
609 const struct line6_properties *properties;
610 int interface_number, alternate = 0;
611 int product;
612 int size = 0;
613 int ep_read = 0, ep_write = 0;
614 int ret;
616 if (interface == NULL)
617 return -ENODEV;
618 usbdev = interface_to_usbdev(interface);
619 if (usbdev == NULL)
620 return -ENODEV;
622 /* we don't handle multiple configurations */
623 if (usbdev->descriptor.bNumConfigurations != 1) {
624 ret = -ENODEV;
625 goto err_put;
628 /* check vendor and product id */
629 for (devtype = ARRAY_SIZE(line6_id_table) - 1; devtype--;) {
630 u16 idVendor = le16_to_cpu(usbdev->descriptor.idVendor);
631 u16 idProduct = le16_to_cpu(usbdev->descriptor.idProduct);
633 if (idVendor == line6_id_table[devtype].idVendor &&
634 idProduct == line6_id_table[devtype].idProduct)
635 break;
638 if (devtype < 0) {
639 ret = -ENODEV;
640 goto err_put;
643 /* initialize device info: */
644 properties = &line6_properties_table[devtype];
645 dev_info(&interface->dev, "Line6 %s found\n", properties->name);
646 product = le16_to_cpu(usbdev->descriptor.idProduct);
648 /* query interface number */
649 interface_number = interface->cur_altsetting->desc.bInterfaceNumber;
651 switch (product) {
652 case LINE6_DEVID_BASSPODXTLIVE:
653 case LINE6_DEVID_PODXTLIVE:
654 case LINE6_DEVID_VARIAX:
655 alternate = 1;
656 break;
658 case LINE6_DEVID_POCKETPOD:
659 switch (interface_number) {
660 case 0:
661 return 0; /* this interface has no endpoints */
662 case 1:
663 alternate = 0;
664 break;
665 default:
666 MISSING_CASE;
668 break;
670 case LINE6_DEVID_PODHD500:
671 case LINE6_DEVID_PODX3:
672 case LINE6_DEVID_PODX3LIVE:
673 switch (interface_number) {
674 case 0:
675 alternate = 1;
676 break;
677 case 1:
678 alternate = 0;
679 break;
680 default:
681 MISSING_CASE;
683 break;
685 case LINE6_DEVID_BASSPODXT:
686 case LINE6_DEVID_BASSPODXTPRO:
687 case LINE6_DEVID_PODXT:
688 case LINE6_DEVID_PODXTPRO:
689 case LINE6_DEVID_PODHD300:
690 case LINE6_DEVID_PODHD400:
691 alternate = 5;
692 break;
694 case LINE6_DEVID_GUITARPORT:
695 case LINE6_DEVID_PODSTUDIO_GX:
696 case LINE6_DEVID_PODSTUDIO_UX1:
697 case LINE6_DEVID_TONEPORT_GX:
698 case LINE6_DEVID_TONEPORT_UX1:
699 alternate = 2; /* 1..4 seem to be ok */
700 break;
702 case LINE6_DEVID_TONEPORT_UX2:
703 case LINE6_DEVID_PODSTUDIO_UX2:
704 switch (interface_number) {
705 case 0:
706 /* defaults to 44.1kHz, 16-bit */
707 alternate = 2;
708 break;
709 case 1:
710 /* don't know yet what this is ...
711 alternate = 1;
712 break;
714 return -ENODEV;
715 default:
716 MISSING_CASE;
718 break;
720 default:
721 MISSING_CASE;
722 ret = -ENODEV;
723 goto err_put;
726 ret = usb_set_interface(usbdev, interface_number, alternate);
727 if (ret < 0) {
728 dev_err(&interface->dev, "set_interface failed\n");
729 goto err_put;
732 /* initialize device data based on product id: */
733 switch (product) {
734 case LINE6_DEVID_BASSPODXT:
735 case LINE6_DEVID_BASSPODXTLIVE:
736 case LINE6_DEVID_BASSPODXTPRO:
737 case LINE6_DEVID_PODXT:
738 case LINE6_DEVID_PODXTPRO:
739 size = sizeof(struct usb_line6_pod);
740 ep_read = 0x84;
741 ep_write = 0x03;
742 break;
744 case LINE6_DEVID_PODHD300:
745 case LINE6_DEVID_PODHD400:
746 size = sizeof(struct usb_line6_podhd);
747 ep_read = 0x84;
748 ep_write = 0x03;
749 break;
751 case LINE6_DEVID_PODHD500:
752 size = sizeof(struct usb_line6_podhd);
753 ep_read = 0x81;
754 ep_write = 0x01;
755 break;
757 case LINE6_DEVID_POCKETPOD:
758 size = sizeof(struct usb_line6_pod);
759 ep_read = 0x82;
760 ep_write = 0x02;
761 break;
763 case LINE6_DEVID_PODX3:
764 case LINE6_DEVID_PODX3LIVE:
765 /* currently unused! */
766 size = sizeof(struct usb_line6_pod);
767 ep_read = 0x81;
768 ep_write = 0x01;
769 break;
771 case LINE6_DEVID_PODSTUDIO_GX:
772 case LINE6_DEVID_PODSTUDIO_UX1:
773 case LINE6_DEVID_PODSTUDIO_UX2:
774 case LINE6_DEVID_TONEPORT_GX:
775 case LINE6_DEVID_TONEPORT_UX1:
776 case LINE6_DEVID_TONEPORT_UX2:
777 case LINE6_DEVID_GUITARPORT:
778 size = sizeof(struct usb_line6_toneport);
779 /* these don't have a control channel */
780 break;
782 case LINE6_DEVID_PODXTLIVE:
783 switch (interface_number) {
784 case PODXTLIVE_INTERFACE_POD:
785 size = sizeof(struct usb_line6_pod);
786 ep_read = 0x84;
787 ep_write = 0x03;
788 break;
790 case PODXTLIVE_INTERFACE_VARIAX:
791 size = sizeof(struct usb_line6_variax);
792 ep_read = 0x86;
793 ep_write = 0x05;
794 break;
796 default:
797 ret = -ENODEV;
798 goto err_put;
800 break;
802 case LINE6_DEVID_VARIAX:
803 size = sizeof(struct usb_line6_variax);
804 ep_read = 0x82;
805 ep_write = 0x01;
806 break;
808 default:
809 MISSING_CASE;
810 ret = -ENODEV;
811 goto err_put;
814 if (size == 0) {
815 dev_err(&interface->dev,
816 "driver bug: interface data size not set\n");
817 ret = -ENODEV;
818 goto err_put;
821 line6 = kzalloc(size, GFP_KERNEL);
822 if (line6 == NULL) {
823 ret = -ENODEV;
824 goto err_put;
827 /* store basic data: */
828 line6->interface_number = interface_number;
829 line6->properties = properties;
830 line6->usbdev = usbdev;
831 line6->ifcdev = &interface->dev;
832 line6->ep_control_read = ep_read;
833 line6->ep_control_write = ep_write;
834 line6->product = product;
836 /* get data from endpoint descriptor (see usb_maxpacket): */
838 struct usb_host_endpoint *ep;
839 unsigned epnum =
840 usb_pipeendpoint(usb_rcvintpipe(usbdev, ep_read));
841 ep = usbdev->ep_in[epnum];
843 if (ep != NULL) {
844 line6->interval = ep->desc.bInterval;
845 line6->max_packet_size =
846 le16_to_cpu(ep->desc.wMaxPacketSize);
847 } else {
848 line6->interval = LINE6_FALLBACK_INTERVAL;
849 line6->max_packet_size = LINE6_FALLBACK_MAXPACKETSIZE;
850 dev_err(line6->ifcdev,
851 "endpoint not available, using fallback values");
855 usb_set_intfdata(interface, line6);
857 if (properties->capabilities & LINE6_BIT_CONTROL) {
858 /* initialize USB buffers: */
859 line6->buffer_listen =
860 kmalloc(LINE6_BUFSIZE_LISTEN, GFP_KERNEL);
861 if (line6->buffer_listen == NULL) {
862 ret = -ENOMEM;
863 goto err_destruct;
866 line6->buffer_message =
867 kmalloc(LINE6_MESSAGE_MAXLEN, GFP_KERNEL);
868 if (line6->buffer_message == NULL) {
869 ret = -ENOMEM;
870 goto err_destruct;
873 line6->urb_listen = usb_alloc_urb(0, GFP_KERNEL);
875 if (line6->urb_listen == NULL) {
876 dev_err(&interface->dev, "Out of memory\n");
877 line6_destruct(interface);
878 ret = -ENOMEM;
879 goto err_destruct;
882 ret = line6_start_listen(line6);
883 if (ret < 0) {
884 dev_err(&interface->dev, "%s: usb_submit_urb failed\n",
885 __func__);
886 goto err_destruct;
890 /* initialize device data based on product id: */
891 switch (product) {
892 case LINE6_DEVID_BASSPODXT:
893 case LINE6_DEVID_BASSPODXTLIVE:
894 case LINE6_DEVID_BASSPODXTPRO:
895 case LINE6_DEVID_POCKETPOD:
896 case LINE6_DEVID_PODX3:
897 case LINE6_DEVID_PODX3LIVE:
898 case LINE6_DEVID_PODXT:
899 case LINE6_DEVID_PODXTPRO:
900 ret = line6_pod_init(interface, (struct usb_line6_pod *)line6);
901 break;
903 case LINE6_DEVID_PODHD300:
904 case LINE6_DEVID_PODHD400:
905 case LINE6_DEVID_PODHD500:
906 ret = line6_podhd_init(interface,
907 (struct usb_line6_podhd *)line6);
908 break;
910 case LINE6_DEVID_PODXTLIVE:
911 switch (interface_number) {
912 case PODXTLIVE_INTERFACE_POD:
913 ret =
914 line6_pod_init(interface,
915 (struct usb_line6_pod *)line6);
916 break;
918 case PODXTLIVE_INTERFACE_VARIAX:
919 ret =
920 line6_variax_init(interface,
921 (struct usb_line6_variax *)line6);
922 break;
924 default:
925 dev_err(&interface->dev,
926 "PODxt Live interface %d not supported\n",
927 interface_number);
928 ret = -ENODEV;
931 break;
933 case LINE6_DEVID_VARIAX:
934 ret =
935 line6_variax_init(interface,
936 (struct usb_line6_variax *)line6);
937 break;
939 case LINE6_DEVID_PODSTUDIO_GX:
940 case LINE6_DEVID_PODSTUDIO_UX1:
941 case LINE6_DEVID_PODSTUDIO_UX2:
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 =
947 line6_toneport_init(interface,
948 (struct usb_line6_toneport *)line6);
949 break;
951 default:
952 MISSING_CASE;
953 ret = -ENODEV;
956 if (ret < 0)
957 goto err_destruct;
959 ret = sysfs_create_link(&interface->dev.kobj, &usbdev->dev.kobj,
960 "usb_device");
961 if (ret < 0)
962 goto err_destruct;
964 /* creation of additional special files should go here */
966 dev_info(&interface->dev, "Line6 %s now attached\n",
967 line6->properties->name);
969 switch (product) {
970 case LINE6_DEVID_PODX3:
971 case LINE6_DEVID_PODX3LIVE:
972 dev_info(&interface->dev,
973 "NOTE: the Line6 %s is detected, but not yet supported\n",
974 line6->properties->name);
977 /* increment reference counters: */
978 usb_get_intf(interface);
979 usb_get_dev(usbdev);
981 return 0;
983 err_destruct:
984 line6_destruct(interface);
985 err_put:
986 return ret;
990 Line6 device disconnected.
992 static void line6_disconnect(struct usb_interface *interface)
994 struct usb_line6 *line6;
995 struct usb_device *usbdev;
996 int interface_number;
998 if (interface == NULL)
999 return;
1000 usbdev = interface_to_usbdev(interface);
1001 if (usbdev == NULL)
1002 return;
1004 /* removal of additional special files should go here */
1006 sysfs_remove_link(&interface->dev.kobj, "usb_device");
1008 interface_number = interface->cur_altsetting->desc.bInterfaceNumber;
1009 line6 = usb_get_intfdata(interface);
1011 if (line6 != NULL) {
1012 if (line6->urb_listen != NULL)
1013 line6_stop_listen(line6);
1015 if (usbdev != line6->usbdev)
1016 dev_err(line6->ifcdev,
1017 "driver bug: inconsistent usb device\n");
1019 switch (le16_to_cpu(line6->usbdev->descriptor.idProduct)) {
1020 case LINE6_DEVID_BASSPODXT:
1021 case LINE6_DEVID_BASSPODXTLIVE:
1022 case LINE6_DEVID_BASSPODXTPRO:
1023 case LINE6_DEVID_POCKETPOD:
1024 case LINE6_DEVID_PODX3:
1025 case LINE6_DEVID_PODX3LIVE:
1026 case LINE6_DEVID_PODXT:
1027 case LINE6_DEVID_PODXTPRO:
1028 line6_pod_disconnect(interface);
1029 break;
1031 case LINE6_DEVID_PODHD300:
1032 case LINE6_DEVID_PODHD400:
1033 case LINE6_DEVID_PODHD500:
1034 line6_podhd_disconnect(interface);
1035 break;
1037 case LINE6_DEVID_PODXTLIVE:
1038 switch (interface_number) {
1039 case PODXTLIVE_INTERFACE_POD:
1040 line6_pod_disconnect(interface);
1041 break;
1043 case PODXTLIVE_INTERFACE_VARIAX:
1044 line6_variax_disconnect(interface);
1045 break;
1048 break;
1050 case LINE6_DEVID_VARIAX:
1051 line6_variax_disconnect(interface);
1052 break;
1054 case LINE6_DEVID_PODSTUDIO_GX:
1055 case LINE6_DEVID_PODSTUDIO_UX1:
1056 case LINE6_DEVID_PODSTUDIO_UX2:
1057 case LINE6_DEVID_TONEPORT_GX:
1058 case LINE6_DEVID_TONEPORT_UX1:
1059 case LINE6_DEVID_TONEPORT_UX2:
1060 case LINE6_DEVID_GUITARPORT:
1061 line6_toneport_disconnect(interface);
1062 break;
1064 default:
1065 MISSING_CASE;
1068 dev_info(&interface->dev, "Line6 %s now disconnected\n",
1069 line6->properties->name);
1072 line6_destruct(interface);
1074 /* decrement reference counters: */
1075 usb_put_intf(interface);
1076 usb_put_dev(usbdev);
1079 #ifdef CONFIG_PM
1082 Suspend Line6 device.
1084 static int line6_suspend(struct usb_interface *interface, pm_message_t message)
1086 struct usb_line6 *line6 = usb_get_intfdata(interface);
1087 struct snd_line6_pcm *line6pcm = line6->line6pcm;
1089 snd_power_change_state(line6->card, SNDRV_CTL_POWER_D3hot);
1091 if (line6->properties->capabilities & LINE6_BIT_CONTROL)
1092 line6_stop_listen(line6);
1094 if (line6pcm != NULL) {
1095 snd_pcm_suspend_all(line6pcm->pcm);
1096 line6_pcm_disconnect(line6pcm);
1097 line6pcm->flags = 0;
1100 return 0;
1104 Resume Line6 device.
1106 static int line6_resume(struct usb_interface *interface)
1108 struct usb_line6 *line6 = usb_get_intfdata(interface);
1110 if (line6->properties->capabilities & LINE6_BIT_CONTROL)
1111 line6_start_listen(line6);
1113 snd_power_change_state(line6->card, SNDRV_CTL_POWER_D0);
1114 return 0;
1118 Resume Line6 device after reset.
1120 static int line6_reset_resume(struct usb_interface *interface)
1122 struct usb_line6 *line6 = usb_get_intfdata(interface);
1124 switch (le16_to_cpu(line6->usbdev->descriptor.idProduct)) {
1125 case LINE6_DEVID_PODSTUDIO_GX:
1126 case LINE6_DEVID_PODSTUDIO_UX1:
1127 case LINE6_DEVID_PODSTUDIO_UX2:
1128 case LINE6_DEVID_TONEPORT_GX:
1129 case LINE6_DEVID_TONEPORT_UX1:
1130 case LINE6_DEVID_TONEPORT_UX2:
1131 case LINE6_DEVID_GUITARPORT:
1132 line6_toneport_reset_resume((struct usb_line6_toneport *)line6);
1135 return line6_resume(interface);
1138 #endif /* CONFIG_PM */
1140 static struct usb_driver line6_driver = {
1141 .name = DRIVER_NAME,
1142 .probe = line6_probe,
1143 .disconnect = line6_disconnect,
1144 #ifdef CONFIG_PM
1145 .suspend = line6_suspend,
1146 .resume = line6_resume,
1147 .reset_resume = line6_reset_resume,
1148 #endif
1149 .id_table = line6_id_table,
1152 module_usb_driver(line6_driver);
1154 MODULE_AUTHOR(DRIVER_AUTHOR);
1155 MODULE_DESCRIPTION(DRIVER_DESC);
1156 MODULE_LICENSE("GPL");
1157 MODULE_VERSION(DRIVER_VERSION);