ARCv2: SLC: Make sure busy bit is set properly for region ops
[linux/fpc-iii.git] / sound / usb / line6 / driver.c
blob0ff5a7d2e19fe1cc584a6420461841be26781b9b
1 /*
2 * Line 6 Linux USB driver
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/export.h>
15 #include <linux/slab.h>
16 #include <linux/usb.h>
18 #include <sound/core.h>
19 #include <sound/initval.h>
20 #include <sound/hwdep.h>
22 #include "capture.h"
23 #include "driver.h"
24 #include "midi.h"
25 #include "playback.h"
27 #define DRIVER_AUTHOR "Markus Grabner <grabner@icg.tugraz.at>"
28 #define DRIVER_DESC "Line 6 USB Driver"
31 This is Line 6's MIDI manufacturer ID.
33 const unsigned char line6_midi_id[3] = {
34 0x00, 0x01, 0x0c
36 EXPORT_SYMBOL_GPL(line6_midi_id);
39 Code to request version of POD, Variax interface
40 (and maybe other devices).
42 static const char line6_request_version[] = {
43 0xf0, 0x7e, 0x7f, 0x06, 0x01, 0xf7
47 Class for asynchronous messages.
49 struct message {
50 struct usb_line6 *line6;
51 const char *buffer;
52 int size;
53 int done;
57 Forward declarations.
59 static void line6_data_received(struct urb *urb);
60 static int line6_send_raw_message_async_part(struct message *msg,
61 struct urb *urb);
64 Start to listen on endpoint.
66 static int line6_start_listen(struct usb_line6 *line6)
68 int err;
70 if (line6->properties->capabilities & LINE6_CAP_CONTROL_MIDI) {
71 usb_fill_int_urb(line6->urb_listen, line6->usbdev,
72 usb_rcvintpipe(line6->usbdev, line6->properties->ep_ctrl_r),
73 line6->buffer_listen, LINE6_BUFSIZE_LISTEN,
74 line6_data_received, line6, line6->interval);
75 } else {
76 usb_fill_bulk_urb(line6->urb_listen, line6->usbdev,
77 usb_rcvbulkpipe(line6->usbdev, line6->properties->ep_ctrl_r),
78 line6->buffer_listen, LINE6_BUFSIZE_LISTEN,
79 line6_data_received, line6);
81 line6->urb_listen->actual_length = 0;
82 err = usb_submit_urb(line6->urb_listen, GFP_ATOMIC);
83 return err;
87 Stop listening on endpoint.
89 static void line6_stop_listen(struct usb_line6 *line6)
91 usb_kill_urb(line6->urb_listen);
95 Send raw message in pieces of wMaxPacketSize bytes.
97 static int line6_send_raw_message(struct usb_line6 *line6, const char *buffer,
98 int size)
100 int i, done = 0;
101 const struct line6_properties *properties = line6->properties;
103 for (i = 0; i < size; i += line6->max_packet_size) {
104 int partial;
105 const char *frag_buf = buffer + i;
106 int frag_size = min(line6->max_packet_size, size - i);
107 int retval;
109 if (properties->capabilities & LINE6_CAP_CONTROL_MIDI) {
110 retval = usb_interrupt_msg(line6->usbdev,
111 usb_sndintpipe(line6->usbdev, properties->ep_ctrl_w),
112 (char *)frag_buf, frag_size,
113 &partial, LINE6_TIMEOUT * HZ);
114 } else {
115 retval = usb_bulk_msg(line6->usbdev,
116 usb_sndbulkpipe(line6->usbdev, properties->ep_ctrl_w),
117 (char *)frag_buf, frag_size,
118 &partial, LINE6_TIMEOUT * HZ);
121 if (retval) {
122 dev_err(line6->ifcdev,
123 "usb_bulk_msg failed (%d)\n", retval);
124 break;
127 done += frag_size;
130 return done;
134 Notification of completion of asynchronous request transmission.
136 static void line6_async_request_sent(struct urb *urb)
138 struct message *msg = (struct message *)urb->context;
140 if (msg->done >= msg->size) {
141 usb_free_urb(urb);
142 kfree(msg);
143 } else
144 line6_send_raw_message_async_part(msg, urb);
148 Asynchronously send part of a raw message.
150 static int line6_send_raw_message_async_part(struct message *msg,
151 struct urb *urb)
153 int retval;
154 struct usb_line6 *line6 = msg->line6;
155 int done = msg->done;
156 int bytes = min(msg->size - done, line6->max_packet_size);
158 if (line6->properties->capabilities & LINE6_CAP_CONTROL_MIDI) {
159 usb_fill_int_urb(urb, line6->usbdev,
160 usb_sndintpipe(line6->usbdev, line6->properties->ep_ctrl_w),
161 (char *)msg->buffer + done, bytes,
162 line6_async_request_sent, msg, line6->interval);
163 } else {
164 usb_fill_bulk_urb(urb, line6->usbdev,
165 usb_sndbulkpipe(line6->usbdev, line6->properties->ep_ctrl_w),
166 (char *)msg->buffer + done, bytes,
167 line6_async_request_sent, msg);
170 msg->done += bytes;
171 retval = usb_submit_urb(urb, GFP_ATOMIC);
173 if (retval < 0) {
174 dev_err(line6->ifcdev, "%s: usb_submit_urb failed (%d)\n",
175 __func__, retval);
176 usb_free_urb(urb);
177 kfree(msg);
178 return retval;
181 return 0;
185 Setup and start timer.
187 void line6_start_timer(struct timer_list *timer, unsigned long msecs,
188 void (*function)(unsigned long), unsigned long data)
190 setup_timer(timer, function, data);
191 mod_timer(timer, jiffies + msecs_to_jiffies(msecs));
193 EXPORT_SYMBOL_GPL(line6_start_timer);
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 unsigned char len;
341 unsigned count;
343 if (address > 0xffff || datalen > 0xff)
344 return -EINVAL;
346 /* query the serial number: */
347 ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67,
348 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
349 (datalen << 8) | 0x21, address,
350 NULL, 0, LINE6_TIMEOUT * HZ);
352 if (ret < 0) {
353 dev_err(line6->ifcdev, "read request failed (error %d)\n", ret);
354 return ret;
357 /* Wait for data length. We'll get 0xff until length arrives. */
358 for (count = 0; count < LINE6_READ_WRITE_MAX_RETRIES; count++) {
359 mdelay(LINE6_READ_WRITE_STATUS_DELAY);
361 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
362 USB_TYPE_VENDOR | USB_RECIP_DEVICE |
363 USB_DIR_IN,
364 0x0012, 0x0000, &len, 1,
365 LINE6_TIMEOUT * HZ);
366 if (ret < 0) {
367 dev_err(line6->ifcdev,
368 "receive length failed (error %d)\n", ret);
369 return ret;
372 if (len != 0xff)
373 break;
376 if (len == 0xff) {
377 dev_err(line6->ifcdev, "read failed after %d retries\n",
378 count);
379 return -EIO;
380 } else if (len != datalen) {
381 /* should be equal or something went wrong */
382 dev_err(line6->ifcdev,
383 "length mismatch (expected %d, got %d)\n",
384 (int)datalen, (int)len);
385 return -EIO;
388 /* receive the result: */
389 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
390 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
391 0x0013, 0x0000, data, datalen,
392 LINE6_TIMEOUT * HZ);
394 if (ret < 0) {
395 dev_err(line6->ifcdev, "read failed (error %d)\n", ret);
396 return ret;
399 return 0;
401 EXPORT_SYMBOL_GPL(line6_read_data);
404 Write data to device.
406 int line6_write_data(struct usb_line6 *line6, unsigned address, void *data,
407 unsigned datalen)
409 struct usb_device *usbdev = line6->usbdev;
410 int ret;
411 unsigned char status;
412 int count;
414 if (address > 0xffff || datalen > 0xffff)
415 return -EINVAL;
417 ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67,
418 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
419 0x0022, address, data, datalen,
420 LINE6_TIMEOUT * HZ);
422 if (ret < 0) {
423 dev_err(line6->ifcdev,
424 "write request failed (error %d)\n", ret);
425 return ret;
428 for (count = 0; count < LINE6_READ_WRITE_MAX_RETRIES; count++) {
429 mdelay(LINE6_READ_WRITE_STATUS_DELAY);
431 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0),
432 0x67,
433 USB_TYPE_VENDOR | USB_RECIP_DEVICE |
434 USB_DIR_IN,
435 0x0012, 0x0000,
436 &status, 1, LINE6_TIMEOUT * HZ);
438 if (ret < 0) {
439 dev_err(line6->ifcdev,
440 "receiving status failed (error %d)\n", ret);
441 return ret;
444 if (status != 0xff)
445 break;
448 if (status == 0xff) {
449 dev_err(line6->ifcdev, "write failed after %d retries\n",
450 count);
451 return -EIO;
452 } else if (status != 0) {
453 dev_err(line6->ifcdev, "write failed (error %d)\n", ret);
454 return -EIO;
457 return 0;
459 EXPORT_SYMBOL_GPL(line6_write_data);
462 Read Line 6 device serial number.
463 (POD, TonePort, GuitarPort)
465 int line6_read_serial_number(struct usb_line6 *line6, u32 *serial_number)
467 return line6_read_data(line6, 0x80d0, serial_number,
468 sizeof(*serial_number));
470 EXPORT_SYMBOL_GPL(line6_read_serial_number);
473 Card destructor.
475 static void line6_destruct(struct snd_card *card)
477 struct usb_line6 *line6 = card->private_data;
478 struct usb_device *usbdev = line6->usbdev;
480 /* Free buffer memory first. We cannot depend on the existence of private
481 * data from the (podhd) module, it may be gone already during this call
483 kfree(line6->buffer_message);
485 kfree(line6->buffer_listen);
487 /* then free URBs: */
488 usb_free_urb(line6->urb_listen);
489 line6->urb_listen = NULL;
491 /* decrement reference counters: */
492 usb_put_dev(usbdev);
495 static void line6_get_usb_properties(struct usb_line6 *line6)
497 struct usb_device *usbdev = line6->usbdev;
498 const struct line6_properties *properties = line6->properties;
499 int pipe;
500 struct usb_host_endpoint *ep = NULL;
502 if (properties->capabilities & LINE6_CAP_CONTROL) {
503 if (properties->capabilities & LINE6_CAP_CONTROL_MIDI) {
504 pipe = usb_rcvintpipe(line6->usbdev,
505 line6->properties->ep_ctrl_r);
506 } else {
507 pipe = usb_rcvbulkpipe(line6->usbdev,
508 line6->properties->ep_ctrl_r);
510 ep = usbdev->ep_in[usb_pipeendpoint(pipe)];
513 /* Control data transfer properties */
514 if (ep) {
515 line6->interval = ep->desc.bInterval;
516 line6->max_packet_size = le16_to_cpu(ep->desc.wMaxPacketSize);
517 } else {
518 if (properties->capabilities & LINE6_CAP_CONTROL) {
519 dev_err(line6->ifcdev,
520 "endpoint not available, using fallback values");
522 line6->interval = LINE6_FALLBACK_INTERVAL;
523 line6->max_packet_size = LINE6_FALLBACK_MAXPACKETSIZE;
526 /* Isochronous transfer properties */
527 if (usbdev->speed == USB_SPEED_LOW) {
528 line6->intervals_per_second = USB_LOW_INTERVALS_PER_SECOND;
529 line6->iso_buffers = USB_LOW_ISO_BUFFERS;
530 } else {
531 line6->intervals_per_second = USB_HIGH_INTERVALS_PER_SECOND;
532 line6->iso_buffers = USB_HIGH_ISO_BUFFERS;
536 /* Enable buffering of incoming messages, flush the buffer */
537 static int line6_hwdep_open(struct snd_hwdep *hw, struct file *file)
539 struct usb_line6 *line6 = hw->private_data;
541 /* NOTE: hwdep layer provides atomicity here */
543 line6->messages.active = 1;
545 return 0;
548 /* Stop buffering */
549 static int line6_hwdep_release(struct snd_hwdep *hw, struct file *file)
551 struct usb_line6 *line6 = hw->private_data;
553 line6->messages.active = 0;
555 return 0;
558 /* Read from circular buffer, return to user */
559 static long
560 line6_hwdep_read(struct snd_hwdep *hwdep, char __user *buf, long count,
561 loff_t *offset)
563 struct usb_line6 *line6 = hwdep->private_data;
564 long rv = 0;
565 unsigned int out_count;
567 if (mutex_lock_interruptible(&line6->messages.read_lock))
568 return -ERESTARTSYS;
570 while (kfifo_len(&line6->messages.fifo) == 0) {
571 mutex_unlock(&line6->messages.read_lock);
573 rv = wait_event_interruptible(
574 line6->messages.wait_queue,
575 kfifo_len(&line6->messages.fifo) != 0);
576 if (rv < 0)
577 return rv;
579 if (mutex_lock_interruptible(&line6->messages.read_lock))
580 return -ERESTARTSYS;
583 if (kfifo_peek_len(&line6->messages.fifo) > count) {
584 /* Buffer too small; allow re-read of the current item... */
585 rv = -EINVAL;
586 } else {
587 rv = kfifo_to_user(&line6->messages.fifo, buf, count, &out_count);
588 if (rv == 0)
589 rv = out_count;
592 mutex_unlock(&line6->messages.read_lock);
593 return rv;
596 /* Write directly (no buffering) to device by user*/
597 static long
598 line6_hwdep_write(struct snd_hwdep *hwdep, const char __user *data, long count,
599 loff_t *offset)
601 struct usb_line6 *line6 = hwdep->private_data;
602 int rv;
603 char *data_copy;
605 if (count > line6->max_packet_size * LINE6_RAW_MESSAGES_MAXCOUNT) {
606 /* This is an arbitrary limit - still better than nothing... */
607 return -EINVAL;
610 data_copy = memdup_user(data, count);
611 if (IS_ERR(data_copy))
612 return PTR_ERR(data_copy);
614 rv = line6_send_raw_message(line6, data_copy, count);
616 kfree(data_copy);
617 return rv;
620 static const struct snd_hwdep_ops hwdep_ops = {
621 .open = line6_hwdep_open,
622 .release = line6_hwdep_release,
623 .read = line6_hwdep_read,
624 .write = line6_hwdep_write,
627 /* Insert into circular buffer */
628 static void line6_hwdep_push_message(struct usb_line6 *line6)
630 if (!line6->messages.active)
631 return;
633 if (kfifo_avail(&line6->messages.fifo) >= line6->message_length) {
634 /* No race condition here, there's only one writer */
635 kfifo_in(&line6->messages.fifo,
636 line6->buffer_message, line6->message_length);
637 } /* else TODO: signal overflow */
639 wake_up_interruptible(&line6->messages.wait_queue);
642 static int line6_hwdep_init(struct usb_line6 *line6)
644 int err;
645 struct snd_hwdep *hwdep;
647 /* TODO: usb_driver_claim_interface(); */
648 line6->process_message = line6_hwdep_push_message;
649 line6->messages.active = 0;
650 init_waitqueue_head(&line6->messages.wait_queue);
651 mutex_init(&line6->messages.read_lock);
652 INIT_KFIFO(line6->messages.fifo);
654 err = snd_hwdep_new(line6->card, "config", 0, &hwdep);
655 if (err < 0)
656 goto end;
657 strcpy(hwdep->name, "config");
658 hwdep->iface = SNDRV_HWDEP_IFACE_LINE6;
659 hwdep->ops = hwdep_ops;
660 hwdep->private_data = line6;
661 hwdep->exclusive = true;
663 end:
664 return err;
667 static int line6_init_cap_control(struct usb_line6 *line6)
669 int ret;
671 /* initialize USB buffers: */
672 line6->buffer_listen = kmalloc(LINE6_BUFSIZE_LISTEN, GFP_KERNEL);
673 if (!line6->buffer_listen)
674 return -ENOMEM;
676 line6->urb_listen = usb_alloc_urb(0, GFP_KERNEL);
677 if (!line6->urb_listen)
678 return -ENOMEM;
680 if (line6->properties->capabilities & LINE6_CAP_CONTROL_MIDI) {
681 line6->buffer_message = kmalloc(LINE6_MIDI_MESSAGE_MAXLEN, GFP_KERNEL);
682 if (!line6->buffer_message)
683 return -ENOMEM;
684 } else {
685 ret = line6_hwdep_init(line6);
686 if (ret < 0)
687 return ret;
690 ret = line6_start_listen(line6);
691 if (ret < 0) {
692 dev_err(line6->ifcdev, "cannot start listening: %d\n", ret);
693 return ret;
696 return 0;
700 Probe USB device.
702 int line6_probe(struct usb_interface *interface,
703 const struct usb_device_id *id,
704 const char *driver_name,
705 const struct line6_properties *properties,
706 int (*private_init)(struct usb_line6 *, const struct usb_device_id *id),
707 size_t data_size)
709 struct usb_device *usbdev = interface_to_usbdev(interface);
710 struct snd_card *card;
711 struct usb_line6 *line6;
712 int interface_number;
713 int ret;
715 if (WARN_ON(data_size < sizeof(*line6)))
716 return -EINVAL;
718 /* we don't handle multiple configurations */
719 if (usbdev->descriptor.bNumConfigurations != 1)
720 return -ENODEV;
722 ret = snd_card_new(&interface->dev,
723 SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
724 THIS_MODULE, data_size, &card);
725 if (ret < 0)
726 return ret;
728 /* store basic data: */
729 line6 = card->private_data;
730 line6->card = card;
731 line6->properties = properties;
732 line6->usbdev = usbdev;
733 line6->ifcdev = &interface->dev;
735 strcpy(card->id, properties->id);
736 strcpy(card->driver, driver_name);
737 strcpy(card->shortname, properties->name);
738 sprintf(card->longname, "Line 6 %s at USB %s", properties->name,
739 dev_name(line6->ifcdev));
740 card->private_free = line6_destruct;
742 usb_set_intfdata(interface, line6);
744 /* increment reference counters: */
745 usb_get_dev(usbdev);
747 /* initialize device info: */
748 dev_info(&interface->dev, "Line 6 %s found\n", properties->name);
750 /* query interface number */
751 interface_number = interface->cur_altsetting->desc.bInterfaceNumber;
753 /* TODO reserves the bus bandwidth even without actual transfer */
754 ret = usb_set_interface(usbdev, interface_number,
755 properties->altsetting);
756 if (ret < 0) {
757 dev_err(&interface->dev, "set_interface failed\n");
758 goto error;
761 line6_get_usb_properties(line6);
763 if (properties->capabilities & LINE6_CAP_CONTROL) {
764 ret = line6_init_cap_control(line6);
765 if (ret < 0)
766 goto error;
769 /* initialize device data based on device: */
770 ret = private_init(line6, id);
771 if (ret < 0)
772 goto error;
774 /* creation of additional special files should go here */
776 dev_info(&interface->dev, "Line 6 %s now attached\n",
777 properties->name);
779 return 0;
781 error:
782 if (line6->disconnect)
783 line6->disconnect(line6);
784 snd_card_free(card);
785 return ret;
787 EXPORT_SYMBOL_GPL(line6_probe);
790 Line 6 device disconnected.
792 void line6_disconnect(struct usb_interface *interface)
794 struct usb_line6 *line6 = usb_get_intfdata(interface);
795 struct usb_device *usbdev = interface_to_usbdev(interface);
797 if (!line6)
798 return;
800 if (WARN_ON(usbdev != line6->usbdev))
801 return;
803 if (line6->urb_listen != NULL)
804 line6_stop_listen(line6);
806 snd_card_disconnect(line6->card);
807 if (line6->line6pcm)
808 line6_pcm_disconnect(line6->line6pcm);
809 if (line6->disconnect)
810 line6->disconnect(line6);
812 dev_info(&interface->dev, "Line 6 %s now disconnected\n",
813 line6->properties->name);
815 /* make sure the device isn't destructed twice: */
816 usb_set_intfdata(interface, NULL);
818 snd_card_free_when_closed(line6->card);
820 EXPORT_SYMBOL_GPL(line6_disconnect);
822 #ifdef CONFIG_PM
825 Suspend Line 6 device.
827 int line6_suspend(struct usb_interface *interface, pm_message_t message)
829 struct usb_line6 *line6 = usb_get_intfdata(interface);
830 struct snd_line6_pcm *line6pcm = line6->line6pcm;
832 snd_power_change_state(line6->card, SNDRV_CTL_POWER_D3hot);
834 if (line6->properties->capabilities & LINE6_CAP_CONTROL)
835 line6_stop_listen(line6);
837 if (line6pcm != NULL) {
838 snd_pcm_suspend_all(line6pcm->pcm);
839 line6pcm->flags = 0;
842 return 0;
844 EXPORT_SYMBOL_GPL(line6_suspend);
847 Resume Line 6 device.
849 int line6_resume(struct usb_interface *interface)
851 struct usb_line6 *line6 = usb_get_intfdata(interface);
853 if (line6->properties->capabilities & LINE6_CAP_CONTROL)
854 line6_start_listen(line6);
856 snd_power_change_state(line6->card, SNDRV_CTL_POWER_D0);
857 return 0;
859 EXPORT_SYMBOL_GPL(line6_resume);
861 #endif /* CONFIG_PM */
863 MODULE_AUTHOR(DRIVER_AUTHOR);
864 MODULE_DESCRIPTION(DRIVER_DESC);
865 MODULE_LICENSE("GPL");