WIP FPC-III support
[linux/fpc-iii.git] / sound / usb / line6 / driver.c
bloba030dd65eb2805993a03ef49cd78b4b438bc9fec
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Line 6 Linux USB driver
5 * Copyright (C) 2004-2010 Markus Grabner (grabner@icg.tugraz.at)
6 */
8 #include <linux/kernel.h>
9 #include <linux/module.h>
10 #include <linux/export.h>
11 #include <linux/slab.h>
12 #include <linux/usb.h>
14 #include <sound/core.h>
15 #include <sound/initval.h>
16 #include <sound/hwdep.h>
18 #include "capture.h"
19 #include "driver.h"
20 #include "midi.h"
21 #include "playback.h"
23 #define DRIVER_AUTHOR "Markus Grabner <grabner@icg.tugraz.at>"
24 #define DRIVER_DESC "Line 6 USB Driver"
27 This is Line 6's MIDI manufacturer ID.
29 const unsigned char line6_midi_id[3] = {
30 0x00, 0x01, 0x0c
32 EXPORT_SYMBOL_GPL(line6_midi_id);
35 Code to request version of POD, Variax interface
36 (and maybe other devices).
38 static const char line6_request_version[] = {
39 0xf0, 0x7e, 0x7f, 0x06, 0x01, 0xf7
43 Class for asynchronous messages.
45 struct message {
46 struct usb_line6 *line6;
47 const char *buffer;
48 int size;
49 int done;
53 Forward declarations.
55 static void line6_data_received(struct urb *urb);
56 static int line6_send_raw_message_async_part(struct message *msg,
57 struct urb *urb);
60 Start to listen on endpoint.
62 static int line6_start_listen(struct usb_line6 *line6)
64 int err;
66 if (line6->properties->capabilities & LINE6_CAP_CONTROL_MIDI) {
67 usb_fill_int_urb(line6->urb_listen, line6->usbdev,
68 usb_rcvintpipe(line6->usbdev, line6->properties->ep_ctrl_r),
69 line6->buffer_listen, LINE6_BUFSIZE_LISTEN,
70 line6_data_received, line6, line6->interval);
71 } else {
72 usb_fill_bulk_urb(line6->urb_listen, line6->usbdev,
73 usb_rcvbulkpipe(line6->usbdev, line6->properties->ep_ctrl_r),
74 line6->buffer_listen, LINE6_BUFSIZE_LISTEN,
75 line6_data_received, line6);
78 /* sanity checks of EP before actually submitting */
79 if (usb_urb_ep_type_check(line6->urb_listen)) {
80 dev_err(line6->ifcdev, "invalid control EP\n");
81 return -EINVAL;
84 line6->urb_listen->actual_length = 0;
85 err = usb_submit_urb(line6->urb_listen, GFP_ATOMIC);
86 return err;
90 Stop listening on endpoint.
92 static void line6_stop_listen(struct usb_line6 *line6)
94 usb_kill_urb(line6->urb_listen);
98 Send raw message in pieces of wMaxPacketSize bytes.
100 int line6_send_raw_message(struct usb_line6 *line6, const char *buffer,
101 int size)
103 int i, done = 0;
104 const struct line6_properties *properties = line6->properties;
106 for (i = 0; i < size; i += line6->max_packet_size) {
107 int partial;
108 const char *frag_buf = buffer + i;
109 int frag_size = min(line6->max_packet_size, size - i);
110 int retval;
112 if (properties->capabilities & LINE6_CAP_CONTROL_MIDI) {
113 retval = usb_interrupt_msg(line6->usbdev,
114 usb_sndintpipe(line6->usbdev, properties->ep_ctrl_w),
115 (char *)frag_buf, frag_size,
116 &partial, LINE6_TIMEOUT * HZ);
117 } else {
118 retval = usb_bulk_msg(line6->usbdev,
119 usb_sndbulkpipe(line6->usbdev, properties->ep_ctrl_w),
120 (char *)frag_buf, frag_size,
121 &partial, LINE6_TIMEOUT * HZ);
124 if (retval) {
125 dev_err(line6->ifcdev,
126 "usb_bulk_msg failed (%d)\n", retval);
127 break;
130 done += frag_size;
133 return done;
135 EXPORT_SYMBOL_GPL(line6_send_raw_message);
138 Notification of completion of asynchronous request transmission.
140 static void line6_async_request_sent(struct urb *urb)
142 struct message *msg = (struct message *)urb->context;
144 if (msg->done >= msg->size) {
145 usb_free_urb(urb);
146 kfree(msg);
147 } else
148 line6_send_raw_message_async_part(msg, urb);
152 Asynchronously send part of a raw message.
154 static int line6_send_raw_message_async_part(struct message *msg,
155 struct urb *urb)
157 int retval;
158 struct usb_line6 *line6 = msg->line6;
159 int done = msg->done;
160 int bytes = min(msg->size - done, line6->max_packet_size);
162 if (line6->properties->capabilities & LINE6_CAP_CONTROL_MIDI) {
163 usb_fill_int_urb(urb, line6->usbdev,
164 usb_sndintpipe(line6->usbdev, line6->properties->ep_ctrl_w),
165 (char *)msg->buffer + done, bytes,
166 line6_async_request_sent, msg, line6->interval);
167 } else {
168 usb_fill_bulk_urb(urb, line6->usbdev,
169 usb_sndbulkpipe(line6->usbdev, line6->properties->ep_ctrl_w),
170 (char *)msg->buffer + done, bytes,
171 line6_async_request_sent, msg);
174 msg->done += bytes;
176 /* sanity checks of EP before actually submitting */
177 retval = usb_urb_ep_type_check(urb);
178 if (retval < 0)
179 goto error;
181 retval = usb_submit_urb(urb, GFP_ATOMIC);
182 if (retval < 0)
183 goto error;
185 return 0;
187 error:
188 dev_err(line6->ifcdev, "%s: usb_submit_urb failed (%d)\n",
189 __func__, retval);
190 usb_free_urb(urb);
191 kfree(msg);
192 return retval;
196 Asynchronously send raw message.
198 int line6_send_raw_message_async(struct usb_line6 *line6, const char *buffer,
199 int size)
201 struct message *msg;
202 struct urb *urb;
204 /* create message: */
205 msg = kmalloc(sizeof(struct message), GFP_ATOMIC);
206 if (msg == NULL)
207 return -ENOMEM;
209 /* create URB: */
210 urb = usb_alloc_urb(0, GFP_ATOMIC);
212 if (urb == NULL) {
213 kfree(msg);
214 return -ENOMEM;
217 /* set message data: */
218 msg->line6 = line6;
219 msg->buffer = buffer;
220 msg->size = size;
221 msg->done = 0;
223 /* start sending: */
224 return line6_send_raw_message_async_part(msg, urb);
226 EXPORT_SYMBOL_GPL(line6_send_raw_message_async);
229 Send asynchronous device version request.
231 int line6_version_request_async(struct usb_line6 *line6)
233 char *buffer;
234 int retval;
236 buffer = kmemdup(line6_request_version,
237 sizeof(line6_request_version), GFP_ATOMIC);
238 if (buffer == NULL)
239 return -ENOMEM;
241 retval = line6_send_raw_message_async(line6, buffer,
242 sizeof(line6_request_version));
243 kfree(buffer);
244 return retval;
246 EXPORT_SYMBOL_GPL(line6_version_request_async);
249 Send sysex message in pieces of wMaxPacketSize bytes.
251 int line6_send_sysex_message(struct usb_line6 *line6, const char *buffer,
252 int size)
254 return line6_send_raw_message(line6, buffer,
255 size + SYSEX_EXTRA_SIZE) -
256 SYSEX_EXTRA_SIZE;
258 EXPORT_SYMBOL_GPL(line6_send_sysex_message);
261 Allocate buffer for sysex message and prepare header.
262 @param code sysex message code
263 @param size number of bytes between code and sysex end
265 char *line6_alloc_sysex_buffer(struct usb_line6 *line6, int code1, int code2,
266 int size)
268 char *buffer = kmalloc(size + SYSEX_EXTRA_SIZE, GFP_ATOMIC);
270 if (!buffer)
271 return NULL;
273 buffer[0] = LINE6_SYSEX_BEGIN;
274 memcpy(buffer + 1, line6_midi_id, sizeof(line6_midi_id));
275 buffer[sizeof(line6_midi_id) + 1] = code1;
276 buffer[sizeof(line6_midi_id) + 2] = code2;
277 buffer[sizeof(line6_midi_id) + 3 + size] = LINE6_SYSEX_END;
278 return buffer;
280 EXPORT_SYMBOL_GPL(line6_alloc_sysex_buffer);
283 Notification of data received from the Line 6 device.
285 static void line6_data_received(struct urb *urb)
287 struct usb_line6 *line6 = (struct usb_line6 *)urb->context;
288 struct midi_buffer *mb = &line6->line6midi->midibuf_in;
289 int done;
291 if (urb->status == -ESHUTDOWN)
292 return;
294 if (line6->properties->capabilities & LINE6_CAP_CONTROL_MIDI) {
295 done =
296 line6_midibuf_write(mb, urb->transfer_buffer, urb->actual_length);
298 if (done < urb->actual_length) {
299 line6_midibuf_ignore(mb, done);
300 dev_dbg(line6->ifcdev, "%d %d buffer overflow - message skipped\n",
301 done, urb->actual_length);
304 for (;;) {
305 done =
306 line6_midibuf_read(mb, line6->buffer_message,
307 LINE6_MIDI_MESSAGE_MAXLEN);
309 if (done <= 0)
310 break;
312 line6->message_length = done;
313 line6_midi_receive(line6, line6->buffer_message, done);
315 if (line6->process_message)
316 line6->process_message(line6);
318 } else {
319 line6->buffer_message = urb->transfer_buffer;
320 line6->message_length = urb->actual_length;
321 if (line6->process_message)
322 line6->process_message(line6);
323 line6->buffer_message = NULL;
326 line6_start_listen(line6);
329 #define LINE6_READ_WRITE_STATUS_DELAY 2 /* milliseconds */
330 #define LINE6_READ_WRITE_MAX_RETRIES 50
333 Read data from device.
335 int line6_read_data(struct usb_line6 *line6, unsigned address, void *data,
336 unsigned datalen)
338 struct usb_device *usbdev = line6->usbdev;
339 int ret;
340 u8 len;
341 unsigned count;
343 if (address > 0xffff || datalen > 0xff)
344 return -EINVAL;
346 /* query the serial number: */
347 ret = usb_control_msg_send(usbdev, 0, 0x67,
348 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
349 (datalen << 8) | 0x21, address, NULL, 0,
350 LINE6_TIMEOUT * HZ, GFP_KERNEL);
351 if (ret) {
352 dev_err(line6->ifcdev, "read request failed (error %d)\n", ret);
353 goto exit;
356 /* Wait for data length. We'll get 0xff until length arrives. */
357 for (count = 0; count < LINE6_READ_WRITE_MAX_RETRIES; count++) {
358 mdelay(LINE6_READ_WRITE_STATUS_DELAY);
360 ret = usb_control_msg_recv(usbdev, 0, 0x67,
361 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
362 0x0012, 0x0000, &len, 1,
363 LINE6_TIMEOUT * HZ, GFP_KERNEL);
364 if (ret) {
365 dev_err(line6->ifcdev,
366 "receive length failed (error %d)\n", ret);
367 goto exit;
370 if (len != 0xff)
371 break;
374 ret = -EIO;
375 if (len == 0xff) {
376 dev_err(line6->ifcdev, "read failed after %d retries\n",
377 count);
378 goto exit;
379 } else if (len != datalen) {
380 /* should be equal or something went wrong */
381 dev_err(line6->ifcdev,
382 "length mismatch (expected %d, got %d)\n",
383 (int)datalen, len);
384 goto exit;
387 /* receive the result: */
388 ret = usb_control_msg_recv(usbdev, 0, 0x67,
389 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
390 0x0013, 0x0000, data, datalen, LINE6_TIMEOUT * HZ,
391 GFP_KERNEL);
392 if (ret)
393 dev_err(line6->ifcdev, "read failed (error %d)\n", ret);
395 exit:
396 return ret;
398 EXPORT_SYMBOL_GPL(line6_read_data);
401 Write data to device.
403 int line6_write_data(struct usb_line6 *line6, unsigned address, void *data,
404 unsigned datalen)
406 struct usb_device *usbdev = line6->usbdev;
407 int ret;
408 unsigned char *status;
409 int count;
411 if (address > 0xffff || datalen > 0xffff)
412 return -EINVAL;
414 status = kmalloc(1, GFP_KERNEL);
415 if (!status)
416 return -ENOMEM;
418 ret = usb_control_msg_send(usbdev, 0, 0x67,
419 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
420 0x0022, address, data, datalen, LINE6_TIMEOUT * HZ,
421 GFP_KERNEL);
422 if (ret) {
423 dev_err(line6->ifcdev,
424 "write request failed (error %d)\n", ret);
425 goto exit;
428 for (count = 0; count < LINE6_READ_WRITE_MAX_RETRIES; count++) {
429 mdelay(LINE6_READ_WRITE_STATUS_DELAY);
431 ret = usb_control_msg_recv(usbdev, 0, 0x67,
432 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
433 0x0012, 0x0000, status, 1, LINE6_TIMEOUT * HZ,
434 GFP_KERNEL);
435 if (ret) {
436 dev_err(line6->ifcdev,
437 "receiving status failed (error %d)\n", ret);
438 goto exit;
441 if (*status != 0xff)
442 break;
445 if (*status == 0xff) {
446 dev_err(line6->ifcdev, "write failed after %d retries\n",
447 count);
448 ret = -EIO;
449 } else if (*status != 0) {
450 dev_err(line6->ifcdev, "write failed (error %d)\n", ret);
451 ret = -EIO;
453 exit:
454 kfree(status);
455 return ret;
457 EXPORT_SYMBOL_GPL(line6_write_data);
460 Read Line 6 device serial number.
461 (POD, TonePort, GuitarPort)
463 int line6_read_serial_number(struct usb_line6 *line6, u32 *serial_number)
465 return line6_read_data(line6, 0x80d0, serial_number,
466 sizeof(*serial_number));
468 EXPORT_SYMBOL_GPL(line6_read_serial_number);
471 Card destructor.
473 static void line6_destruct(struct snd_card *card)
475 struct usb_line6 *line6 = card->private_data;
476 struct usb_device *usbdev = line6->usbdev;
478 /* Free buffer memory first. We cannot depend on the existence of private
479 * data from the (podhd) module, it may be gone already during this call
481 kfree(line6->buffer_message);
483 kfree(line6->buffer_listen);
485 /* then free URBs: */
486 usb_free_urb(line6->urb_listen);
487 line6->urb_listen = NULL;
489 /* decrement reference counters: */
490 usb_put_dev(usbdev);
493 static void line6_get_usb_properties(struct usb_line6 *line6)
495 struct usb_device *usbdev = line6->usbdev;
496 const struct line6_properties *properties = line6->properties;
497 int pipe;
498 struct usb_host_endpoint *ep = NULL;
500 if (properties->capabilities & LINE6_CAP_CONTROL) {
501 if (properties->capabilities & LINE6_CAP_CONTROL_MIDI) {
502 pipe = usb_rcvintpipe(line6->usbdev,
503 line6->properties->ep_ctrl_r);
504 } else {
505 pipe = usb_rcvbulkpipe(line6->usbdev,
506 line6->properties->ep_ctrl_r);
508 ep = usbdev->ep_in[usb_pipeendpoint(pipe)];
511 /* Control data transfer properties */
512 if (ep) {
513 line6->interval = ep->desc.bInterval;
514 line6->max_packet_size = le16_to_cpu(ep->desc.wMaxPacketSize);
515 } else {
516 if (properties->capabilities & LINE6_CAP_CONTROL) {
517 dev_err(line6->ifcdev,
518 "endpoint not available, using fallback values");
520 line6->interval = LINE6_FALLBACK_INTERVAL;
521 line6->max_packet_size = LINE6_FALLBACK_MAXPACKETSIZE;
524 /* Isochronous transfer properties */
525 if (usbdev->speed == USB_SPEED_LOW) {
526 line6->intervals_per_second = USB_LOW_INTERVALS_PER_SECOND;
527 line6->iso_buffers = USB_LOW_ISO_BUFFERS;
528 } else {
529 line6->intervals_per_second = USB_HIGH_INTERVALS_PER_SECOND;
530 line6->iso_buffers = USB_HIGH_ISO_BUFFERS;
534 /* Enable buffering of incoming messages, flush the buffer */
535 static int line6_hwdep_open(struct snd_hwdep *hw, struct file *file)
537 struct usb_line6 *line6 = hw->private_data;
539 /* NOTE: hwdep layer provides atomicity here */
541 line6->messages.active = 1;
542 line6->messages.nonblock = file->f_flags & O_NONBLOCK ? 1 : 0;
544 return 0;
547 /* Stop buffering */
548 static int line6_hwdep_release(struct snd_hwdep *hw, struct file *file)
550 struct usb_line6 *line6 = hw->private_data;
552 line6->messages.active = 0;
554 return 0;
557 /* Read from circular buffer, return to user */
558 static long
559 line6_hwdep_read(struct snd_hwdep *hwdep, char __user *buf, long count,
560 loff_t *offset)
562 struct usb_line6 *line6 = hwdep->private_data;
563 long rv = 0;
564 unsigned int out_count;
566 if (mutex_lock_interruptible(&line6->messages.read_lock))
567 return -ERESTARTSYS;
569 while (kfifo_len(&line6->messages.fifo) == 0) {
570 mutex_unlock(&line6->messages.read_lock);
572 if (line6->messages.nonblock)
573 return -EAGAIN;
575 rv = wait_event_interruptible(
576 line6->messages.wait_queue,
577 kfifo_len(&line6->messages.fifo) != 0);
578 if (rv < 0)
579 return rv;
581 if (mutex_lock_interruptible(&line6->messages.read_lock))
582 return -ERESTARTSYS;
585 if (kfifo_peek_len(&line6->messages.fifo) > count) {
586 /* Buffer too small; allow re-read of the current item... */
587 rv = -EINVAL;
588 } else {
589 rv = kfifo_to_user(&line6->messages.fifo, buf, count, &out_count);
590 if (rv == 0)
591 rv = out_count;
594 mutex_unlock(&line6->messages.read_lock);
595 return rv;
598 /* Write directly (no buffering) to device by user*/
599 static long
600 line6_hwdep_write(struct snd_hwdep *hwdep, const char __user *data, long count,
601 loff_t *offset)
603 struct usb_line6 *line6 = hwdep->private_data;
604 int rv;
605 char *data_copy;
607 if (count > line6->max_packet_size * LINE6_RAW_MESSAGES_MAXCOUNT) {
608 /* This is an arbitrary limit - still better than nothing... */
609 return -EINVAL;
612 data_copy = memdup_user(data, count);
613 if (IS_ERR(data_copy))
614 return PTR_ERR(data_copy);
616 rv = line6_send_raw_message(line6, data_copy, count);
618 kfree(data_copy);
619 return rv;
622 static __poll_t
623 line6_hwdep_poll(struct snd_hwdep *hwdep, struct file *file, poll_table *wait)
625 __poll_t rv;
626 struct usb_line6 *line6 = hwdep->private_data;
628 poll_wait(file, &line6->messages.wait_queue, wait);
630 mutex_lock(&line6->messages.read_lock);
631 rv = kfifo_len(&line6->messages.fifo) == 0 ? 0 : EPOLLIN | EPOLLRDNORM;
632 mutex_unlock(&line6->messages.read_lock);
634 return rv;
637 static const struct snd_hwdep_ops hwdep_ops = {
638 .open = line6_hwdep_open,
639 .release = line6_hwdep_release,
640 .read = line6_hwdep_read,
641 .write = line6_hwdep_write,
642 .poll = line6_hwdep_poll,
645 /* Insert into circular buffer */
646 static void line6_hwdep_push_message(struct usb_line6 *line6)
648 if (!line6->messages.active)
649 return;
651 if (kfifo_avail(&line6->messages.fifo) >= line6->message_length) {
652 /* No race condition here, there's only one writer */
653 kfifo_in(&line6->messages.fifo,
654 line6->buffer_message, line6->message_length);
655 } /* else TODO: signal overflow */
657 wake_up_interruptible(&line6->messages.wait_queue);
660 static int line6_hwdep_init(struct usb_line6 *line6)
662 int err;
663 struct snd_hwdep *hwdep;
665 /* TODO: usb_driver_claim_interface(); */
666 line6->process_message = line6_hwdep_push_message;
667 line6->messages.active = 0;
668 init_waitqueue_head(&line6->messages.wait_queue);
669 mutex_init(&line6->messages.read_lock);
670 INIT_KFIFO(line6->messages.fifo);
672 err = snd_hwdep_new(line6->card, "config", 0, &hwdep);
673 if (err < 0)
674 goto end;
675 strcpy(hwdep->name, "config");
676 hwdep->iface = SNDRV_HWDEP_IFACE_LINE6;
677 hwdep->ops = hwdep_ops;
678 hwdep->private_data = line6;
679 hwdep->exclusive = true;
681 end:
682 return err;
685 static int line6_init_cap_control(struct usb_line6 *line6)
687 int ret;
689 /* initialize USB buffers: */
690 line6->buffer_listen = kmalloc(LINE6_BUFSIZE_LISTEN, GFP_KERNEL);
691 if (!line6->buffer_listen)
692 return -ENOMEM;
694 line6->urb_listen = usb_alloc_urb(0, GFP_KERNEL);
695 if (!line6->urb_listen)
696 return -ENOMEM;
698 if (line6->properties->capabilities & LINE6_CAP_CONTROL_MIDI) {
699 line6->buffer_message = kmalloc(LINE6_MIDI_MESSAGE_MAXLEN, GFP_KERNEL);
700 if (!line6->buffer_message)
701 return -ENOMEM;
702 } else {
703 ret = line6_hwdep_init(line6);
704 if (ret < 0)
705 return ret;
708 ret = line6_start_listen(line6);
709 if (ret < 0) {
710 dev_err(line6->ifcdev, "cannot start listening: %d\n", ret);
711 return ret;
714 return 0;
717 static void line6_startup_work(struct work_struct *work)
719 struct usb_line6 *line6 =
720 container_of(work, struct usb_line6, startup_work.work);
722 if (line6->startup)
723 line6->startup(line6);
727 Probe USB device.
729 int line6_probe(struct usb_interface *interface,
730 const struct usb_device_id *id,
731 const char *driver_name,
732 const struct line6_properties *properties,
733 int (*private_init)(struct usb_line6 *, const struct usb_device_id *id),
734 size_t data_size)
736 struct usb_device *usbdev = interface_to_usbdev(interface);
737 struct snd_card *card;
738 struct usb_line6 *line6;
739 int interface_number;
740 int ret;
742 if (WARN_ON(data_size < sizeof(*line6)))
743 return -EINVAL;
745 /* we don't handle multiple configurations */
746 if (usbdev->descriptor.bNumConfigurations != 1)
747 return -ENODEV;
749 ret = snd_card_new(&interface->dev,
750 SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
751 THIS_MODULE, data_size, &card);
752 if (ret < 0)
753 return ret;
755 /* store basic data: */
756 line6 = card->private_data;
757 line6->card = card;
758 line6->properties = properties;
759 line6->usbdev = usbdev;
760 line6->ifcdev = &interface->dev;
761 INIT_DELAYED_WORK(&line6->startup_work, line6_startup_work);
763 strcpy(card->id, properties->id);
764 strcpy(card->driver, driver_name);
765 strcpy(card->shortname, properties->name);
766 sprintf(card->longname, "Line 6 %s at USB %s", properties->name,
767 dev_name(line6->ifcdev));
768 card->private_free = line6_destruct;
770 usb_set_intfdata(interface, line6);
772 /* increment reference counters: */
773 usb_get_dev(usbdev);
775 /* initialize device info: */
776 dev_info(&interface->dev, "Line 6 %s found\n", properties->name);
778 /* query interface number */
779 interface_number = interface->cur_altsetting->desc.bInterfaceNumber;
781 /* TODO reserves the bus bandwidth even without actual transfer */
782 ret = usb_set_interface(usbdev, interface_number,
783 properties->altsetting);
784 if (ret < 0) {
785 dev_err(&interface->dev, "set_interface failed\n");
786 goto error;
789 line6_get_usb_properties(line6);
791 if (properties->capabilities & LINE6_CAP_CONTROL) {
792 ret = line6_init_cap_control(line6);
793 if (ret < 0)
794 goto error;
797 /* initialize device data based on device: */
798 ret = private_init(line6, id);
799 if (ret < 0)
800 goto error;
802 /* creation of additional special files should go here */
804 dev_info(&interface->dev, "Line 6 %s now attached\n",
805 properties->name);
807 return 0;
809 error:
810 /* we can call disconnect callback here because no close-sync is
811 * needed yet at this point
813 line6_disconnect(interface);
814 return ret;
816 EXPORT_SYMBOL_GPL(line6_probe);
819 Line 6 device disconnected.
821 void line6_disconnect(struct usb_interface *interface)
823 struct usb_line6 *line6 = usb_get_intfdata(interface);
824 struct usb_device *usbdev = interface_to_usbdev(interface);
826 if (!line6)
827 return;
829 if (WARN_ON(usbdev != line6->usbdev))
830 return;
832 cancel_delayed_work_sync(&line6->startup_work);
834 if (line6->urb_listen != NULL)
835 line6_stop_listen(line6);
837 snd_card_disconnect(line6->card);
838 if (line6->line6pcm)
839 line6_pcm_disconnect(line6->line6pcm);
840 if (line6->disconnect)
841 line6->disconnect(line6);
843 dev_info(&interface->dev, "Line 6 %s now disconnected\n",
844 line6->properties->name);
846 /* make sure the device isn't destructed twice: */
847 usb_set_intfdata(interface, NULL);
849 snd_card_free_when_closed(line6->card);
851 EXPORT_SYMBOL_GPL(line6_disconnect);
853 #ifdef CONFIG_PM
856 Suspend Line 6 device.
858 int line6_suspend(struct usb_interface *interface, pm_message_t message)
860 struct usb_line6 *line6 = usb_get_intfdata(interface);
861 struct snd_line6_pcm *line6pcm = line6->line6pcm;
863 snd_power_change_state(line6->card, SNDRV_CTL_POWER_D3hot);
865 if (line6->properties->capabilities & LINE6_CAP_CONTROL)
866 line6_stop_listen(line6);
868 if (line6pcm != NULL)
869 line6pcm->flags = 0;
871 return 0;
873 EXPORT_SYMBOL_GPL(line6_suspend);
876 Resume Line 6 device.
878 int line6_resume(struct usb_interface *interface)
880 struct usb_line6 *line6 = usb_get_intfdata(interface);
882 if (line6->properties->capabilities & LINE6_CAP_CONTROL)
883 line6_start_listen(line6);
885 snd_power_change_state(line6->card, SNDRV_CTL_POWER_D0);
886 return 0;
888 EXPORT_SYMBOL_GPL(line6_resume);
890 #endif /* CONFIG_PM */
892 MODULE_AUTHOR(DRIVER_AUTHOR);
893 MODULE_DESCRIPTION(DRIVER_DESC);
894 MODULE_LICENSE("GPL");