Staging: unisys: Remove RETINT macro
[linux/fpc-iii.git] / drivers / staging / line6 / driver.c
blob77f1b421e957f158c9de7503d6c3309a74a89642
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 #define L6PROP(dev_bit, dev_id, dev_name, dev_cap)\
61 {.device_bit = LINE6_BIT_##dev_bit, .id = dev_id,\
62 .name = dev_name, .capabilities = LINE6_BIT_##dev_cap}
64 /* *INDENT-OFF* */
65 static const struct line6_properties line6_properties_table[] = {
66 L6PROP(BASSPODXT, "BassPODxt", "BassPODxt", CTRL_PCM_HW),
67 L6PROP(BASSPODXTLIVE, "BassPODxtLive", "BassPODxt Live", CTRL_PCM_HW),
68 L6PROP(BASSPODXTPRO, "BassPODxtPro", "BassPODxt Pro", CTRL_PCM_HW),
69 L6PROP(GUITARPORT, "GuitarPort", "GuitarPort", PCM),
70 L6PROP(POCKETPOD, "PocketPOD", "Pocket POD", CONTROL),
71 L6PROP(PODHD300, "PODHD300", "POD HD300", CTRL_PCM_HW),
72 L6PROP(PODHD400, "PODHD400", "POD HD400", CTRL_PCM_HW),
73 L6PROP(PODHD500, "PODHD500", "POD HD500", CTRL_PCM_HW),
74 L6PROP(PODSTUDIO_GX, "PODStudioGX", "POD Studio GX", PCM),
75 L6PROP(PODSTUDIO_UX1, "PODStudioUX1", "POD Studio UX1", PCM),
76 L6PROP(PODSTUDIO_UX2, "PODStudioUX2", "POD Studio UX2", PCM),
77 L6PROP(PODX3, "PODX3", "POD X3", PCM),
78 L6PROP(PODX3LIVE, "PODX3Live", "POD X3 Live", PCM),
79 L6PROP(PODXT, "PODxt", "PODxt", CTRL_PCM_HW),
80 L6PROP(PODXTLIVE, "PODxtLive", "PODxt Live", CTRL_PCM_HW),
81 L6PROP(PODXTPRO, "PODxtPro", "PODxt Pro", CTRL_PCM_HW),
82 L6PROP(TONEPORT_GX, "TonePortGX", "TonePort GX", PCM),
83 L6PROP(TONEPORT_UX1, "TonePortUX1", "TonePort UX1", PCM),
84 L6PROP(TONEPORT_UX2, "TonePortUX2", "TonePort UX2", PCM),
85 L6PROP(VARIAX, "Variax", "Variax Workbench", CONTROL),
87 /* *INDENT-ON* */
90 This is Line6's MIDI manufacturer ID.
92 const unsigned char line6_midi_id[] = {
93 0x00, 0x01, 0x0c
97 Code to request version of POD, Variax interface
98 (and maybe other devices).
100 static const char line6_request_version[] = {
101 0xf0, 0x7e, 0x7f, 0x06, 0x01, 0xf7
105 Class for asynchronous messages.
107 struct message {
108 struct usb_line6 *line6;
109 const char *buffer;
110 int size;
111 int done;
115 Forward declarations.
117 static void line6_data_received(struct urb *urb);
118 static int line6_send_raw_message_async_part(struct message *msg,
119 struct urb *urb);
122 Start to listen on endpoint.
124 static int line6_start_listen(struct usb_line6 *line6)
126 int err;
127 usb_fill_int_urb(line6->urb_listen, line6->usbdev,
128 usb_rcvintpipe(line6->usbdev, line6->ep_control_read),
129 line6->buffer_listen, LINE6_BUFSIZE_LISTEN,
130 line6_data_received, line6, line6->interval);
131 line6->urb_listen->actual_length = 0;
132 err = usb_submit_urb(line6->urb_listen, GFP_ATOMIC);
133 return err;
137 Stop listening on endpoint.
139 static void line6_stop_listen(struct usb_line6 *line6)
141 usb_kill_urb(line6->urb_listen);
145 Send raw message in pieces of wMaxPacketSize bytes.
147 int line6_send_raw_message(struct usb_line6 *line6, const char *buffer,
148 int size)
150 int i, done = 0;
152 for (i = 0; i < size; i += line6->max_packet_size) {
153 int partial;
154 const char *frag_buf = buffer + i;
155 int frag_size = min(line6->max_packet_size, size - i);
156 int retval;
158 retval = usb_interrupt_msg(line6->usbdev,
159 usb_sndintpipe(line6->usbdev,
160 line6->ep_control_write),
161 (char *)frag_buf, frag_size,
162 &partial, LINE6_TIMEOUT * HZ);
164 if (retval) {
165 dev_err(line6->ifcdev,
166 "usb_interrupt_msg failed (%d)\n", retval);
167 break;
170 done += frag_size;
173 return done;
177 Notification of completion of asynchronous request transmission.
179 static void line6_async_request_sent(struct urb *urb)
181 struct message *msg = (struct message *)urb->context;
183 if (msg->done >= msg->size) {
184 usb_free_urb(urb);
185 kfree(msg);
186 } else
187 line6_send_raw_message_async_part(msg, urb);
191 Asynchronously send part of a raw message.
193 static int line6_send_raw_message_async_part(struct message *msg,
194 struct urb *urb)
196 int retval;
197 struct usb_line6 *line6 = msg->line6;
198 int done = msg->done;
199 int bytes = min(msg->size - done, line6->max_packet_size);
201 usb_fill_int_urb(urb, line6->usbdev,
202 usb_sndintpipe(line6->usbdev, line6->ep_control_write),
203 (char *)msg->buffer + done, bytes,
204 line6_async_request_sent, msg, line6->interval);
206 msg->done += bytes;
207 retval = usb_submit_urb(urb, GFP_ATOMIC);
209 if (retval < 0) {
210 dev_err(line6->ifcdev, "%s: usb_submit_urb failed (%d)\n",
211 __func__, retval);
212 usb_free_urb(urb);
213 kfree(msg);
214 return retval;
217 return 0;
221 Setup and start timer.
223 void line6_start_timer(struct timer_list *timer, unsigned int msecs,
224 void (*function)(unsigned long), unsigned long data)
226 setup_timer(timer, function, data);
227 timer->expires = jiffies + msecs * HZ / 1000;
228 add_timer(timer);
232 Asynchronously send raw message.
234 int line6_send_raw_message_async(struct usb_line6 *line6, const char *buffer,
235 int size)
237 struct message *msg;
238 struct urb *urb;
240 /* create message: */
241 msg = kmalloc(sizeof(struct message), GFP_ATOMIC);
242 if (msg == NULL)
243 return -ENOMEM;
245 /* create URB: */
246 urb = usb_alloc_urb(0, GFP_ATOMIC);
248 if (urb == NULL) {
249 kfree(msg);
250 dev_err(line6->ifcdev, "Out of memory\n");
251 return -ENOMEM;
254 /* set message data: */
255 msg->line6 = line6;
256 msg->buffer = buffer;
257 msg->size = size;
258 msg->done = 0;
260 /* start sending: */
261 return line6_send_raw_message_async_part(msg, urb);
265 Send asynchronous device version request.
267 int line6_version_request_async(struct usb_line6 *line6)
269 char *buffer;
270 int retval;
272 buffer = kmemdup(line6_request_version,
273 sizeof(line6_request_version), GFP_ATOMIC);
274 if (buffer == NULL) {
275 dev_err(line6->ifcdev, "Out of memory");
276 return -ENOMEM;
279 retval = line6_send_raw_message_async(line6, buffer,
280 sizeof(line6_request_version));
281 kfree(buffer);
282 return retval;
286 Send sysex message in pieces of wMaxPacketSize bytes.
288 int line6_send_sysex_message(struct usb_line6 *line6, const char *buffer,
289 int size)
291 return line6_send_raw_message(line6, buffer,
292 size + SYSEX_EXTRA_SIZE) -
293 SYSEX_EXTRA_SIZE;
297 Allocate buffer for sysex message and prepare header.
298 @param code sysex message code
299 @param size number of bytes between code and sysex end
301 char *line6_alloc_sysex_buffer(struct usb_line6 *line6, int code1, int code2,
302 int size)
304 char *buffer = kmalloc(size + SYSEX_EXTRA_SIZE, GFP_ATOMIC);
306 if (!buffer)
307 return NULL;
309 buffer[0] = LINE6_SYSEX_BEGIN;
310 memcpy(buffer + 1, line6_midi_id, sizeof(line6_midi_id));
311 buffer[sizeof(line6_midi_id) + 1] = code1;
312 buffer[sizeof(line6_midi_id) + 2] = code2;
313 buffer[sizeof(line6_midi_id) + 3 + size] = LINE6_SYSEX_END;
314 return buffer;
318 Notification of data received from the Line6 device.
320 static void line6_data_received(struct urb *urb)
322 struct usb_line6 *line6 = (struct usb_line6 *)urb->context;
323 struct midi_buffer *mb = &line6->line6midi->midibuf_in;
324 int done;
326 if (urb->status == -ESHUTDOWN)
327 return;
329 done =
330 line6_midibuf_write(mb, urb->transfer_buffer, urb->actual_length);
332 if (done < urb->actual_length) {
333 line6_midibuf_ignore(mb, done);
334 dev_dbg(line6->ifcdev, "%d %d buffer overflow - message skipped\n",
335 done, urb->actual_length);
338 for (;;) {
339 done =
340 line6_midibuf_read(mb, line6->buffer_message,
341 LINE6_MESSAGE_MAXLEN);
343 if (done == 0)
344 break;
346 line6->message_length = done;
347 line6_midi_receive(line6, line6->buffer_message, done);
349 switch (le16_to_cpu(line6->usbdev->descriptor.idProduct)) {
350 case LINE6_DEVID_BASSPODXT:
351 case LINE6_DEVID_BASSPODXTLIVE:
352 case LINE6_DEVID_BASSPODXTPRO:
353 case LINE6_DEVID_PODXT:
354 case LINE6_DEVID_PODXTPRO:
355 case LINE6_DEVID_POCKETPOD:
356 line6_pod_process_message((struct usb_line6_pod *)
357 line6);
358 break;
360 case LINE6_DEVID_PODHD300:
361 case LINE6_DEVID_PODHD400:
362 case LINE6_DEVID_PODHD500:
363 break; /* let userspace handle MIDI */
365 case LINE6_DEVID_PODXTLIVE:
366 switch (line6->interface_number) {
367 case PODXTLIVE_INTERFACE_POD:
368 line6_pod_process_message((struct usb_line6_pod
369 *)line6);
370 break;
372 case PODXTLIVE_INTERFACE_VARIAX:
373 line6_variax_process_message((struct
374 usb_line6_variax
375 *)line6);
376 break;
378 default:
379 dev_err(line6->ifcdev,
380 "PODxt Live interface %d not supported\n",
381 line6->interface_number);
383 break;
385 case LINE6_DEVID_VARIAX:
386 line6_variax_process_message((struct usb_line6_variax *)
387 line6);
388 break;
390 default:
391 MISSING_CASE;
395 line6_start_listen(line6);
399 Send channel number (i.e., switch to a different sound).
401 int line6_send_program(struct usb_line6 *line6, u8 value)
403 int retval;
404 unsigned char *buffer;
405 int partial;
407 buffer = kmalloc(2, GFP_KERNEL);
408 if (!buffer)
409 return -ENOMEM;
411 buffer[0] = LINE6_PROGRAM_CHANGE | LINE6_CHANNEL_HOST;
412 buffer[1] = value;
414 retval = usb_interrupt_msg(line6->usbdev,
415 usb_sndintpipe(line6->usbdev,
416 line6->ep_control_write),
417 buffer, 2, &partial, LINE6_TIMEOUT * HZ);
419 if (retval)
420 dev_err(line6->ifcdev, "usb_interrupt_msg failed (%d)\n",
421 retval);
423 kfree(buffer);
424 return retval;
428 Transmit Line6 control parameter.
430 int line6_transmit_parameter(struct usb_line6 *line6, int param, u8 value)
432 int retval;
433 unsigned char *buffer;
434 int partial;
436 buffer = kmalloc(3, GFP_KERNEL);
437 if (!buffer)
438 return -ENOMEM;
440 buffer[0] = LINE6_PARAM_CHANGE | LINE6_CHANNEL_HOST;
441 buffer[1] = param;
442 buffer[2] = value;
444 retval = usb_interrupt_msg(line6->usbdev,
445 usb_sndintpipe(line6->usbdev,
446 line6->ep_control_write),
447 buffer, 3, &partial, LINE6_TIMEOUT * HZ);
449 if (retval)
450 dev_err(line6->ifcdev, "usb_interrupt_msg failed (%d)\n",
451 retval);
453 kfree(buffer);
454 return retval;
458 Read data from device.
460 int line6_read_data(struct usb_line6 *line6, int address, void *data,
461 size_t datalen)
463 struct usb_device *usbdev = line6->usbdev;
464 int ret;
465 unsigned char len;
467 /* query the serial number: */
468 ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67,
469 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
470 (datalen << 8) | 0x21, address,
471 NULL, 0, LINE6_TIMEOUT * HZ);
473 if (ret < 0) {
474 dev_err(line6->ifcdev, "read request failed (error %d)\n", ret);
475 return ret;
478 /* Wait for data length. We'll get 0xff until length arrives. */
479 do {
480 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
481 USB_TYPE_VENDOR | USB_RECIP_DEVICE |
482 USB_DIR_IN,
483 0x0012, 0x0000, &len, 1,
484 LINE6_TIMEOUT * HZ);
485 if (ret < 0) {
486 dev_err(line6->ifcdev,
487 "receive length failed (error %d)\n", ret);
488 return ret;
490 } while (len == 0xff);
492 if (len != datalen) {
493 /* should be equal or something went wrong */
494 dev_err(line6->ifcdev,
495 "length mismatch (expected %d, got %d)\n",
496 (int)datalen, (int)len);
497 return -EINVAL;
500 /* receive the result: */
501 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
502 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
503 0x0013, 0x0000, data, datalen,
504 LINE6_TIMEOUT * HZ);
506 if (ret < 0) {
507 dev_err(line6->ifcdev, "read failed (error %d)\n", ret);
508 return ret;
511 return 0;
515 Write data to device.
517 int line6_write_data(struct usb_line6 *line6, int address, void *data,
518 size_t datalen)
520 struct usb_device *usbdev = line6->usbdev;
521 int ret;
522 unsigned char status;
524 ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67,
525 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
526 0x0022, address, data, datalen,
527 LINE6_TIMEOUT * HZ);
529 if (ret < 0) {
530 dev_err(line6->ifcdev,
531 "write request failed (error %d)\n", ret);
532 return ret;
535 do {
536 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0),
537 0x67,
538 USB_TYPE_VENDOR | USB_RECIP_DEVICE |
539 USB_DIR_IN,
540 0x0012, 0x0000,
541 &status, 1, LINE6_TIMEOUT * HZ);
543 if (ret < 0) {
544 dev_err(line6->ifcdev,
545 "receiving status failed (error %d)\n", ret);
546 return ret;
548 } while (status == 0xff);
550 if (status != 0) {
551 dev_err(line6->ifcdev, "write failed (error %d)\n", ret);
552 return -EINVAL;
555 return 0;
559 Read Line6 device serial number.
560 (POD, TonePort, GuitarPort)
562 int line6_read_serial_number(struct usb_line6 *line6, int *serial_number)
564 return line6_read_data(line6, 0x80d0, serial_number,
565 sizeof(*serial_number));
569 No operation (i.e., unsupported).
571 ssize_t line6_nop_read(struct device *dev, struct device_attribute *attr,
572 char *buf)
574 return 0;
578 Generic destructor.
580 static void line6_destruct(struct usb_interface *interface)
582 struct usb_line6 *line6;
584 if (interface == NULL)
585 return;
586 line6 = usb_get_intfdata(interface);
587 if (line6 == NULL)
588 return;
590 /* free buffer memory first: */
591 kfree(line6->buffer_message);
592 kfree(line6->buffer_listen);
594 /* then free URBs: */
595 usb_free_urb(line6->urb_listen);
597 /* make sure the device isn't destructed twice: */
598 usb_set_intfdata(interface, NULL);
600 /* free interface data: */
601 kfree(line6);
605 Probe USB device.
607 static int line6_probe(struct usb_interface *interface,
608 const struct usb_device_id *id)
610 int devtype;
611 struct usb_device *usbdev;
612 struct usb_line6 *line6;
613 const struct line6_properties *properties;
614 int interface_number, alternate = 0;
615 int product;
616 int size = 0;
617 int ep_read = 0, ep_write = 0;
618 int ret;
620 if (interface == NULL)
621 return -ENODEV;
622 usbdev = interface_to_usbdev(interface);
623 if (usbdev == NULL)
624 return -ENODEV;
626 /* we don't handle multiple configurations */
627 if (usbdev->descriptor.bNumConfigurations != 1) {
628 ret = -ENODEV;
629 goto err_put;
632 /* check vendor and product id */
633 for (devtype = ARRAY_SIZE(line6_id_table) - 1; devtype--;) {
634 u16 idVendor = le16_to_cpu(usbdev->descriptor.idVendor);
635 u16 idProduct = le16_to_cpu(usbdev->descriptor.idProduct);
637 if (idVendor == line6_id_table[devtype].idVendor &&
638 idProduct == line6_id_table[devtype].idProduct)
639 break;
642 if (devtype < 0) {
643 ret = -ENODEV;
644 goto err_put;
647 /* initialize device info: */
648 properties = &line6_properties_table[devtype];
649 dev_info(&interface->dev, "Line6 %s found\n", properties->name);
650 product = le16_to_cpu(usbdev->descriptor.idProduct);
652 /* query interface number */
653 interface_number = interface->cur_altsetting->desc.bInterfaceNumber;
655 switch (product) {
656 case LINE6_DEVID_BASSPODXTLIVE:
657 case LINE6_DEVID_PODXTLIVE:
658 case LINE6_DEVID_VARIAX:
659 alternate = 1;
660 break;
662 case LINE6_DEVID_POCKETPOD:
663 switch (interface_number) {
664 case 0:
665 return 0; /* this interface has no endpoints */
666 case 1:
667 alternate = 0;
668 break;
669 default:
670 MISSING_CASE;
672 break;
674 case LINE6_DEVID_PODHD500:
675 case LINE6_DEVID_PODX3:
676 case LINE6_DEVID_PODX3LIVE:
677 switch (interface_number) {
678 case 0:
679 alternate = 1;
680 break;
681 case 1:
682 alternate = 0;
683 break;
684 default:
685 MISSING_CASE;
687 break;
689 case LINE6_DEVID_BASSPODXT:
690 case LINE6_DEVID_BASSPODXTPRO:
691 case LINE6_DEVID_PODXT:
692 case LINE6_DEVID_PODXTPRO:
693 case LINE6_DEVID_PODHD300:
694 case LINE6_DEVID_PODHD400:
695 alternate = 5;
696 break;
698 case LINE6_DEVID_GUITARPORT:
699 case LINE6_DEVID_PODSTUDIO_GX:
700 case LINE6_DEVID_PODSTUDIO_UX1:
701 case LINE6_DEVID_TONEPORT_GX:
702 case LINE6_DEVID_TONEPORT_UX1:
703 alternate = 2; /* 1..4 seem to be ok */
704 break;
706 case LINE6_DEVID_TONEPORT_UX2:
707 case LINE6_DEVID_PODSTUDIO_UX2:
708 switch (interface_number) {
709 case 0:
710 /* defaults to 44.1kHz, 16-bit */
711 alternate = 2;
712 break;
713 case 1:
714 /* don't know yet what this is ...
715 alternate = 1;
716 break;
718 return -ENODEV;
719 default:
720 MISSING_CASE;
722 break;
724 default:
725 MISSING_CASE;
726 ret = -ENODEV;
727 goto err_put;
730 ret = usb_set_interface(usbdev, interface_number, alternate);
731 if (ret < 0) {
732 dev_err(&interface->dev, "set_interface failed\n");
733 goto err_put;
736 /* initialize device data based on product id: */
737 switch (product) {
738 case LINE6_DEVID_BASSPODXT:
739 case LINE6_DEVID_BASSPODXTLIVE:
740 case LINE6_DEVID_BASSPODXTPRO:
741 case LINE6_DEVID_PODXT:
742 case LINE6_DEVID_PODXTPRO:
743 size = sizeof(struct usb_line6_pod);
744 ep_read = 0x84;
745 ep_write = 0x03;
746 break;
748 case LINE6_DEVID_PODHD300:
749 case LINE6_DEVID_PODHD400:
750 size = sizeof(struct usb_line6_podhd);
751 ep_read = 0x84;
752 ep_write = 0x03;
753 break;
755 case LINE6_DEVID_PODHD500:
756 size = sizeof(struct usb_line6_podhd);
757 ep_read = 0x81;
758 ep_write = 0x01;
759 break;
761 case LINE6_DEVID_POCKETPOD:
762 size = sizeof(struct usb_line6_pod);
763 ep_read = 0x82;
764 ep_write = 0x02;
765 break;
767 case LINE6_DEVID_PODX3:
768 case LINE6_DEVID_PODX3LIVE:
769 /* currently unused! */
770 size = sizeof(struct usb_line6_pod);
771 ep_read = 0x81;
772 ep_write = 0x01;
773 break;
775 case LINE6_DEVID_PODSTUDIO_GX:
776 case LINE6_DEVID_PODSTUDIO_UX1:
777 case LINE6_DEVID_PODSTUDIO_UX2:
778 case LINE6_DEVID_TONEPORT_GX:
779 case LINE6_DEVID_TONEPORT_UX1:
780 case LINE6_DEVID_TONEPORT_UX2:
781 case LINE6_DEVID_GUITARPORT:
782 size = sizeof(struct usb_line6_toneport);
783 /* these don't have a control channel */
784 break;
786 case LINE6_DEVID_PODXTLIVE:
787 switch (interface_number) {
788 case PODXTLIVE_INTERFACE_POD:
789 size = sizeof(struct usb_line6_pod);
790 ep_read = 0x84;
791 ep_write = 0x03;
792 break;
794 case PODXTLIVE_INTERFACE_VARIAX:
795 size = sizeof(struct usb_line6_variax);
796 ep_read = 0x86;
797 ep_write = 0x05;
798 break;
800 default:
801 ret = -ENODEV;
802 goto err_put;
804 break;
806 case LINE6_DEVID_VARIAX:
807 size = sizeof(struct usb_line6_variax);
808 ep_read = 0x82;
809 ep_write = 0x01;
810 break;
812 default:
813 MISSING_CASE;
814 ret = -ENODEV;
815 goto err_put;
818 if (size == 0) {
819 dev_err(&interface->dev,
820 "driver bug: interface data size not set\n");
821 ret = -ENODEV;
822 goto err_put;
825 line6 = kzalloc(size, GFP_KERNEL);
826 if (line6 == NULL) {
827 ret = -ENODEV;
828 goto err_put;
831 /* store basic data: */
832 line6->interface_number = interface_number;
833 line6->properties = properties;
834 line6->usbdev = usbdev;
835 line6->ifcdev = &interface->dev;
836 line6->ep_control_read = ep_read;
837 line6->ep_control_write = ep_write;
838 line6->product = product;
840 /* get data from endpoint descriptor (see usb_maxpacket): */
842 struct usb_host_endpoint *ep;
843 unsigned epnum =
844 usb_pipeendpoint(usb_rcvintpipe(usbdev, ep_read));
845 ep = usbdev->ep_in[epnum];
847 if (ep != NULL) {
848 line6->interval = ep->desc.bInterval;
849 line6->max_packet_size =
850 le16_to_cpu(ep->desc.wMaxPacketSize);
851 } else {
852 line6->interval = LINE6_FALLBACK_INTERVAL;
853 line6->max_packet_size = LINE6_FALLBACK_MAXPACKETSIZE;
854 dev_err(line6->ifcdev,
855 "endpoint not available, using fallback values");
859 usb_set_intfdata(interface, line6);
861 if (properties->capabilities & LINE6_BIT_CONTROL) {
862 /* initialize USB buffers: */
863 line6->buffer_listen =
864 kmalloc(LINE6_BUFSIZE_LISTEN, GFP_KERNEL);
865 if (line6->buffer_listen == NULL) {
866 ret = -ENOMEM;
867 goto err_destruct;
870 line6->buffer_message =
871 kmalloc(LINE6_MESSAGE_MAXLEN, GFP_KERNEL);
872 if (line6->buffer_message == NULL) {
873 ret = -ENOMEM;
874 goto err_destruct;
877 line6->urb_listen = usb_alloc_urb(0, GFP_KERNEL);
879 if (line6->urb_listen == NULL) {
880 dev_err(&interface->dev, "Out of memory\n");
881 line6_destruct(interface);
882 ret = -ENOMEM;
883 goto err_destruct;
886 ret = line6_start_listen(line6);
887 if (ret < 0) {
888 dev_err(&interface->dev, "%s: usb_submit_urb failed\n",
889 __func__);
890 goto err_destruct;
894 /* initialize device data based on product id: */
895 switch (product) {
896 case LINE6_DEVID_BASSPODXT:
897 case LINE6_DEVID_BASSPODXTLIVE:
898 case LINE6_DEVID_BASSPODXTPRO:
899 case LINE6_DEVID_POCKETPOD:
900 case LINE6_DEVID_PODX3:
901 case LINE6_DEVID_PODX3LIVE:
902 case LINE6_DEVID_PODXT:
903 case LINE6_DEVID_PODXTPRO:
904 ret = line6_pod_init(interface, (struct usb_line6_pod *)line6);
905 break;
907 case LINE6_DEVID_PODHD300:
908 case LINE6_DEVID_PODHD400:
909 case LINE6_DEVID_PODHD500:
910 ret = line6_podhd_init(interface,
911 (struct usb_line6_podhd *)line6);
912 break;
914 case LINE6_DEVID_PODXTLIVE:
915 switch (interface_number) {
916 case PODXTLIVE_INTERFACE_POD:
917 ret =
918 line6_pod_init(interface,
919 (struct usb_line6_pod *)line6);
920 break;
922 case PODXTLIVE_INTERFACE_VARIAX:
923 ret =
924 line6_variax_init(interface,
925 (struct usb_line6_variax *)line6);
926 break;
928 default:
929 dev_err(&interface->dev,
930 "PODxt Live interface %d not supported\n",
931 interface_number);
932 ret = -ENODEV;
935 break;
937 case LINE6_DEVID_VARIAX:
938 ret =
939 line6_variax_init(interface,
940 (struct usb_line6_variax *)line6);
941 break;
943 case LINE6_DEVID_PODSTUDIO_GX:
944 case LINE6_DEVID_PODSTUDIO_UX1:
945 case LINE6_DEVID_PODSTUDIO_UX2:
946 case LINE6_DEVID_TONEPORT_GX:
947 case LINE6_DEVID_TONEPORT_UX1:
948 case LINE6_DEVID_TONEPORT_UX2:
949 case LINE6_DEVID_GUITARPORT:
950 ret =
951 line6_toneport_init(interface,
952 (struct usb_line6_toneport *)line6);
953 break;
955 default:
956 MISSING_CASE;
957 ret = -ENODEV;
960 if (ret < 0)
961 goto err_destruct;
963 ret = sysfs_create_link(&interface->dev.kobj, &usbdev->dev.kobj,
964 "usb_device");
965 if (ret < 0)
966 goto err_destruct;
968 /* creation of additional special files should go here */
970 dev_info(&interface->dev, "Line6 %s now attached\n",
971 line6->properties->name);
973 switch (product) {
974 case LINE6_DEVID_PODX3:
975 case LINE6_DEVID_PODX3LIVE:
976 dev_info(&interface->dev,
977 "NOTE: the Line6 %s is detected, but not yet supported\n",
978 line6->properties->name);
981 /* increment reference counters: */
982 usb_get_intf(interface);
983 usb_get_dev(usbdev);
985 return 0;
987 err_destruct:
988 line6_destruct(interface);
989 err_put:
990 return ret;
994 Line6 device disconnected.
996 static void line6_disconnect(struct usb_interface *interface)
998 struct usb_line6 *line6;
999 struct usb_device *usbdev;
1000 int interface_number;
1002 if (interface == NULL)
1003 return;
1004 usbdev = interface_to_usbdev(interface);
1005 if (usbdev == NULL)
1006 return;
1008 /* removal of additional special files should go here */
1010 sysfs_remove_link(&interface->dev.kobj, "usb_device");
1012 interface_number = interface->cur_altsetting->desc.bInterfaceNumber;
1013 line6 = usb_get_intfdata(interface);
1015 if (line6 != NULL) {
1016 if (line6->urb_listen != NULL)
1017 line6_stop_listen(line6);
1019 if (usbdev != line6->usbdev)
1020 dev_err(line6->ifcdev,
1021 "driver bug: inconsistent usb device\n");
1023 switch (le16_to_cpu(line6->usbdev->descriptor.idProduct)) {
1024 case LINE6_DEVID_BASSPODXT:
1025 case LINE6_DEVID_BASSPODXTLIVE:
1026 case LINE6_DEVID_BASSPODXTPRO:
1027 case LINE6_DEVID_POCKETPOD:
1028 case LINE6_DEVID_PODX3:
1029 case LINE6_DEVID_PODX3LIVE:
1030 case LINE6_DEVID_PODXT:
1031 case LINE6_DEVID_PODXTPRO:
1032 line6_pod_disconnect(interface);
1033 break;
1035 case LINE6_DEVID_PODHD300:
1036 case LINE6_DEVID_PODHD400:
1037 case LINE6_DEVID_PODHD500:
1038 line6_podhd_disconnect(interface);
1039 break;
1041 case LINE6_DEVID_PODXTLIVE:
1042 switch (interface_number) {
1043 case PODXTLIVE_INTERFACE_POD:
1044 line6_pod_disconnect(interface);
1045 break;
1047 case PODXTLIVE_INTERFACE_VARIAX:
1048 line6_variax_disconnect(interface);
1049 break;
1052 break;
1054 case LINE6_DEVID_VARIAX:
1055 line6_variax_disconnect(interface);
1056 break;
1058 case LINE6_DEVID_PODSTUDIO_GX:
1059 case LINE6_DEVID_PODSTUDIO_UX1:
1060 case LINE6_DEVID_PODSTUDIO_UX2:
1061 case LINE6_DEVID_TONEPORT_GX:
1062 case LINE6_DEVID_TONEPORT_UX1:
1063 case LINE6_DEVID_TONEPORT_UX2:
1064 case LINE6_DEVID_GUITARPORT:
1065 line6_toneport_disconnect(interface);
1066 break;
1068 default:
1069 MISSING_CASE;
1072 dev_info(&interface->dev, "Line6 %s now disconnected\n",
1073 line6->properties->name);
1076 line6_destruct(interface);
1078 /* decrement reference counters: */
1079 usb_put_intf(interface);
1080 usb_put_dev(usbdev);
1083 #ifdef CONFIG_PM
1086 Suspend Line6 device.
1088 static int line6_suspend(struct usb_interface *interface, pm_message_t message)
1090 struct usb_line6 *line6 = usb_get_intfdata(interface);
1091 struct snd_line6_pcm *line6pcm = line6->line6pcm;
1093 snd_power_change_state(line6->card, SNDRV_CTL_POWER_D3hot);
1095 if (line6->properties->capabilities & LINE6_BIT_CONTROL)
1096 line6_stop_listen(line6);
1098 if (line6pcm != NULL) {
1099 snd_pcm_suspend_all(line6pcm->pcm);
1100 line6_pcm_disconnect(line6pcm);
1101 line6pcm->flags = 0;
1104 return 0;
1108 Resume Line6 device.
1110 static int line6_resume(struct usb_interface *interface)
1112 struct usb_line6 *line6 = usb_get_intfdata(interface);
1114 if (line6->properties->capabilities & LINE6_BIT_CONTROL)
1115 line6_start_listen(line6);
1117 snd_power_change_state(line6->card, SNDRV_CTL_POWER_D0);
1118 return 0;
1122 Resume Line6 device after reset.
1124 static int line6_reset_resume(struct usb_interface *interface)
1126 struct usb_line6 *line6 = usb_get_intfdata(interface);
1128 switch (le16_to_cpu(line6->usbdev->descriptor.idProduct)) {
1129 case LINE6_DEVID_PODSTUDIO_GX:
1130 case LINE6_DEVID_PODSTUDIO_UX1:
1131 case LINE6_DEVID_PODSTUDIO_UX2:
1132 case LINE6_DEVID_TONEPORT_GX:
1133 case LINE6_DEVID_TONEPORT_UX1:
1134 case LINE6_DEVID_TONEPORT_UX2:
1135 case LINE6_DEVID_GUITARPORT:
1136 line6_toneport_reset_resume((struct usb_line6_toneport *)line6);
1139 return line6_resume(interface);
1142 #endif /* CONFIG_PM */
1144 static struct usb_driver line6_driver = {
1145 .name = DRIVER_NAME,
1146 .probe = line6_probe,
1147 .disconnect = line6_disconnect,
1148 #ifdef CONFIG_PM
1149 .suspend = line6_suspend,
1150 .resume = line6_resume,
1151 .reset_resume = line6_reset_resume,
1152 #endif
1153 .id_table = line6_id_table,
1156 module_usb_driver(line6_driver);
1158 MODULE_AUTHOR(DRIVER_AUTHOR);
1159 MODULE_DESCRIPTION(DRIVER_DESC);
1160 MODULE_LICENSE("GPL");
1161 MODULE_VERSION(DRIVER_VERSION);