Merge tag 'sound-3.20-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai...
[deliverable/linux.git] / sound / usb / line6 / driver.c
CommitLineData
705ececd 1/*
c078a4aa 2 * Line 6 Linux USB driver
705ececd 3 *
1027f476 4 * Copyright (C) 2004-2010 Markus Grabner (grabner@icg.tugraz.at)
705ececd
MG
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2.
9 *
10 */
11
705ececd
MG
12#include <linux/kernel.h>
13#include <linux/module.h>
ccddbe4a 14#include <linux/export.h>
5a0e3ad6 15#include <linux/slab.h>
705ececd
MG
16#include <linux/usb.h>
17
85a9339b
TI
18#include <sound/core.h>
19#include <sound/initval.h>
20
705ececd 21#include "capture.h"
1027f476 22#include "driver.h"
705ececd
MG
23#include "midi.h"
24#include "playback.h"
705ececd 25
705ececd 26#define DRIVER_AUTHOR "Markus Grabner <grabner@icg.tugraz.at>"
c6fffce9 27#define DRIVER_DESC "Line 6 USB Driver"
705ececd 28
705ececd 29/*
c6fffce9 30 This is Line 6's MIDI manufacturer ID.
705ececd 31*/
1027f476
MG
32const unsigned char line6_midi_id[] = {
33 0x00, 0x01, 0x0c
34};
ccddbe4a 35EXPORT_SYMBOL_GPL(line6_midi_id);
1027f476
MG
36
37/*
38 Code to request version of POD, Variax interface
39 (and maybe other devices).
40*/
c46b8a65 41static const char line6_request_version[] = {
1027f476
MG
42 0xf0, 0x7e, 0x7f, 0x06, 0x01, 0xf7
43};
44
cddbd4f1 45/*
705ececd
MG
46 Class for asynchronous messages.
47*/
36445bc1 48struct message {
705ececd
MG
49 struct usb_line6 *line6;
50 const char *buffer;
51 int size;
52 int done;
53};
54
705ececd
MG
55/*
56 Forward declarations.
57*/
0c7ab158 58static void line6_data_received(struct urb *urb);
36445bc1
GKH
59static int line6_send_raw_message_async_part(struct message *msg,
60 struct urb *urb);
705ececd 61
705ececd
MG
62/*
63 Start to listen on endpoint.
64*/
65static int line6_start_listen(struct usb_line6 *line6)
66{
1027f476 67 int err;
a6b4699d 68
36445bc1 69 usb_fill_int_urb(line6->urb_listen, line6->usbdev,
9e165be7
CR
70 usb_rcvintpipe(line6->usbdev, line6->properties->ep_ctrl_r),
71 line6->buffer_listen, LINE6_BUFSIZE_LISTEN,
72 line6_data_received, line6, line6->interval);
705ececd 73 line6->urb_listen->actual_length = 0;
e1a164d7 74 err = usb_submit_urb(line6->urb_listen, GFP_ATOMIC);
1027f476
MG
75 return err;
76}
77
78/*
79 Stop listening on endpoint.
80*/
81static void line6_stop_listen(struct usb_line6 *line6)
82{
83 usb_kill_urb(line6->urb_listen);
705ececd
MG
84}
85
705ececd 86/*
1027f476 87 Send raw message in pieces of wMaxPacketSize bytes.
705ececd 88*/
73723190
TI
89static int line6_send_raw_message(struct usb_line6 *line6, const char *buffer,
90 int size)
705ececd
MG
91{
92 int i, done = 0;
93
1027f476
MG
94 for (i = 0; i < size; i += line6->max_packet_size) {
95 int partial;
705ececd
MG
96 const char *frag_buf = buffer + i;
97 int frag_size = min(line6->max_packet_size, size - i);
36445bc1
GKH
98 int retval;
99
100 retval = usb_interrupt_msg(line6->usbdev,
ba79e52b 101 usb_sndintpipe(line6->usbdev,
9e165be7 102 line6->properties->ep_ctrl_w),
ba79e52b
DB
103 (char *)frag_buf, frag_size,
104 &partial, LINE6_TIMEOUT * HZ);
705ececd 105
36445bc1
GKH
106 if (retval) {
107 dev_err(line6->ifcdev,
108 "usb_interrupt_msg failed (%d)\n", retval);
705ececd
MG
109 break;
110 }
111
1027f476 112 done += frag_size;
705ececd
MG
113 }
114
115 return done;
116}
117
118/*
119 Notification of completion of asynchronous request transmission.
120*/
0c7ab158 121static void line6_async_request_sent(struct urb *urb)
705ececd
MG
122{
123 struct message *msg = (struct message *)urb->context;
124
36445bc1 125 if (msg->done >= msg->size) {
705ececd
MG
126 usb_free_urb(urb);
127 kfree(msg);
36445bc1 128 } else
705ececd
MG
129 line6_send_raw_message_async_part(msg, urb);
130}
131
132/*
133 Asynchronously send part of a raw message.
134*/
36445bc1
GKH
135static int line6_send_raw_message_async_part(struct message *msg,
136 struct urb *urb)
705ececd
MG
137{
138 int retval;
139 struct usb_line6 *line6 = msg->line6;
140 int done = msg->done;
141 int bytes = min(msg->size - done, line6->max_packet_size);
142
36445bc1 143 usb_fill_int_urb(urb, line6->usbdev,
9e165be7
CR
144 usb_sndintpipe(line6->usbdev, line6->properties->ep_ctrl_w),
145 (char *)msg->buffer + done, bytes,
146 line6_async_request_sent, msg, line6->interval);
705ececd 147
705ececd
MG
148 msg->done += bytes;
149 retval = usb_submit_urb(urb, GFP_ATOMIC);
150
36445bc1
GKH
151 if (retval < 0) {
152 dev_err(line6->ifcdev, "%s: usb_submit_urb failed (%d)\n",
153 __func__, retval);
705ececd
MG
154 usb_free_urb(urb);
155 kfree(msg);
056e0af2 156 return retval;
705ececd
MG
157 }
158
159 return 0;
160}
161
1027f476
MG
162/*
163 Setup and start timer.
164*/
6ccd93bd 165void line6_start_timer(struct timer_list *timer, unsigned long msecs,
1cad608e 166 void (*function)(unsigned long), unsigned long data)
1027f476
MG
167{
168 setup_timer(timer, function, data);
695758c6 169 mod_timer(timer, jiffies + msecs_to_jiffies(msecs));
1027f476 170}
ccddbe4a 171EXPORT_SYMBOL_GPL(line6_start_timer);
1027f476 172
705ececd
MG
173/*
174 Asynchronously send raw message.
175*/
36445bc1
GKH
176int line6_send_raw_message_async(struct usb_line6 *line6, const char *buffer,
177 int size)
705ececd
MG
178{
179 struct message *msg;
180 struct urb *urb;
181
182 /* create message: */
183 msg = kmalloc(sizeof(struct message), GFP_ATOMIC);
78110bb8 184 if (msg == NULL)
705ececd 185 return -ENOMEM;
705ececd
MG
186
187 /* create URB: */
188 urb = usb_alloc_urb(0, GFP_ATOMIC);
189
36445bc1 190 if (urb == NULL) {
705ececd 191 kfree(msg);
705ececd
MG
192 return -ENOMEM;
193 }
194
195 /* set message data: */
196 msg->line6 = line6;
197 msg->buffer = buffer;
198 msg->size = size;
199 msg->done = 0;
200
201 /* start sending: */
202 return line6_send_raw_message_async_part(msg, urb);
203}
ccddbe4a 204EXPORT_SYMBOL_GPL(line6_send_raw_message_async);
705ececd 205
1027f476
MG
206/*
207 Send asynchronous device version request.
208*/
209int line6_version_request_async(struct usb_line6 *line6)
210{
c46b8a65
GKH
211 char *buffer;
212 int retval;
213
77ecb6fe
LN
214 buffer = kmemdup(line6_request_version,
215 sizeof(line6_request_version), GFP_ATOMIC);
a019f5e8 216 if (buffer == NULL)
c46b8a65 217 return -ENOMEM;
c46b8a65 218
c46b8a65
GKH
219 retval = line6_send_raw_message_async(line6, buffer,
220 sizeof(line6_request_version));
221 kfree(buffer);
222 return retval;
1027f476 223}
ccddbe4a 224EXPORT_SYMBOL_GPL(line6_version_request_async);
1027f476 225
705ececd
MG
226/*
227 Send sysex message in pieces of wMaxPacketSize bytes.
228*/
36445bc1
GKH
229int line6_send_sysex_message(struct usb_line6 *line6, const char *buffer,
230 int size)
705ececd 231{
e1a164d7
MG
232 return line6_send_raw_message(line6, buffer,
233 size + SYSEX_EXTRA_SIZE) -
234 SYSEX_EXTRA_SIZE;
705ececd 235}
ccddbe4a 236EXPORT_SYMBOL_GPL(line6_send_sysex_message);
705ececd
MG
237
238/*
239 Allocate buffer for sysex message and prepare header.
240 @param code sysex message code
241 @param size number of bytes between code and sysex end
242*/
36445bc1
GKH
243char *line6_alloc_sysex_buffer(struct usb_line6 *line6, int code1, int code2,
244 int size)
705ececd 245{
1027f476 246 char *buffer = kmalloc(size + SYSEX_EXTRA_SIZE, GFP_ATOMIC);
705ececd 247
78110bb8 248 if (!buffer)
536165d8 249 return NULL;
705ececd
MG
250
251 buffer[0] = LINE6_SYSEX_BEGIN;
252 memcpy(buffer + 1, line6_midi_id, sizeof(line6_midi_id));
253 buffer[sizeof(line6_midi_id) + 1] = code1;
254 buffer[sizeof(line6_midi_id) + 2] = code2;
255 buffer[sizeof(line6_midi_id) + 3 + size] = LINE6_SYSEX_END;
256 return buffer;
257}
ccddbe4a 258EXPORT_SYMBOL_GPL(line6_alloc_sysex_buffer);
705ececd
MG
259
260/*
c6fffce9 261 Notification of data received from the Line 6 device.
705ececd 262*/
0c7ab158 263static void line6_data_received(struct urb *urb)
705ececd
MG
264{
265 struct usb_line6 *line6 = (struct usb_line6 *)urb->context;
269edc8e 266 struct midi_buffer *mb = &line6->line6midi->midibuf_in;
705ececd
MG
267 int done;
268
36445bc1 269 if (urb->status == -ESHUTDOWN)
705ececd
MG
270 return;
271
e1a164d7
MG
272 done =
273 line6_midibuf_write(mb, urb->transfer_buffer, urb->actual_length);
705ececd 274
36445bc1 275 if (done < urb->actual_length) {
1027f476 276 line6_midibuf_ignore(mb, done);
e00d33cb
SH
277 dev_dbg(line6->ifcdev, "%d %d buffer overflow - message skipped\n",
278 done, urb->actual_length);
705ececd
MG
279 }
280
36445bc1 281 for (;;) {
e1a164d7
MG
282 done =
283 line6_midibuf_read(mb, line6->buffer_message,
284 LINE6_MESSAGE_MAXLEN);
705ececd 285
36445bc1 286 if (done == 0)
705ececd
MG
287 break;
288
705ececd 289 line6->message_length = done;
705ececd
MG
290 line6_midi_receive(line6, line6->buffer_message, done);
291
01f6b2bc
CR
292 if (line6->process_message)
293 line6->process_message(line6);
705ececd
MG
294 }
295
296 line6_start_listen(line6);
297}
298
e64e94df 299#define LINE6_READ_WRITE_STATUS_DELAY 2 /* milliseconds */
f3dfd1be 300#define LINE6_READ_WRITE_MAX_RETRIES 50
e64e94df 301
705ececd
MG
302/*
303 Read data from device.
304*/
e1a164d7
MG
305int line6_read_data(struct usb_line6 *line6, int address, void *data,
306 size_t datalen)
705ececd
MG
307{
308 struct usb_device *usbdev = line6->usbdev;
309 int ret;
310 unsigned char len;
f3dfd1be 311 unsigned count;
705ececd
MG
312
313 /* query the serial number: */
314 ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67,
1027f476
MG
315 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
316 (datalen << 8) | 0x21, address,
317 NULL, 0, LINE6_TIMEOUT * HZ);
705ececd 318
36445bc1 319 if (ret < 0) {
705ececd
MG
320 dev_err(line6->ifcdev, "read request failed (error %d)\n", ret);
321 return ret;
322 }
323
bc776f27 324 /* Wait for data length. We'll get 0xff until length arrives. */
f3dfd1be 325 for (count = 0; count < LINE6_READ_WRITE_MAX_RETRIES; count++) {
e64e94df
CR
326 mdelay(LINE6_READ_WRITE_STATUS_DELAY);
327
705ececd 328 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
36445bc1
GKH
329 USB_TYPE_VENDOR | USB_RECIP_DEVICE |
330 USB_DIR_IN,
331 0x0012, 0x0000, &len, 1,
332 LINE6_TIMEOUT * HZ);
333 if (ret < 0) {
334 dev_err(line6->ifcdev,
335 "receive length failed (error %d)\n", ret);
705ececd
MG
336 return ret;
337 }
36445bc1 338
f3dfd1be
CR
339 if (len != 0xff)
340 break;
341 }
342
343 if (len == 0xff) {
344 dev_err(line6->ifcdev, "read failed after %d retries\n",
345 count);
346 return -EIO;
347 } else if (len != datalen) {
36445bc1
GKH
348 /* should be equal or something went wrong */
349 dev_err(line6->ifcdev,
350 "length mismatch (expected %d, got %d)\n",
351 (int)datalen, (int)len);
e474e7fd 352 return -EIO;
705ececd
MG
353 }
354
355 /* receive the result: */
356 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
36445bc1
GKH
357 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
358 0x0013, 0x0000, data, datalen,
359 LINE6_TIMEOUT * HZ);
705ececd 360
36445bc1 361 if (ret < 0) {
705ececd
MG
362 dev_err(line6->ifcdev, "read failed (error %d)\n", ret);
363 return ret;
364 }
365
366 return 0;
367}
ccddbe4a 368EXPORT_SYMBOL_GPL(line6_read_data);
705ececd
MG
369
370/*
371 Write data to device.
372*/
36445bc1
GKH
373int line6_write_data(struct usb_line6 *line6, int address, void *data,
374 size_t datalen)
705ececd
MG
375{
376 struct usb_device *usbdev = line6->usbdev;
377 int ret;
378 unsigned char status;
f3dfd1be 379 int count;
705ececd 380
36445bc1
GKH
381 ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67,
382 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
383 0x0022, address, data, datalen,
384 LINE6_TIMEOUT * HZ);
705ececd 385
36445bc1
GKH
386 if (ret < 0) {
387 dev_err(line6->ifcdev,
388 "write request failed (error %d)\n", ret);
705ececd
MG
389 return ret;
390 }
391
f3dfd1be 392 for (count = 0; count < LINE6_READ_WRITE_MAX_RETRIES; count++) {
e64e94df
CR
393 mdelay(LINE6_READ_WRITE_STATUS_DELAY);
394
36445bc1
GKH
395 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0),
396 0x67,
397 USB_TYPE_VENDOR | USB_RECIP_DEVICE |
398 USB_DIR_IN,
399 0x0012, 0x0000,
400 &status, 1, LINE6_TIMEOUT * HZ);
401
402 if (ret < 0) {
403 dev_err(line6->ifcdev,
404 "receiving status failed (error %d)\n", ret);
705ececd
MG
405 return ret;
406 }
705ececd 407
f3dfd1be
CR
408 if (status != 0xff)
409 break;
410 }
411
412 if (status == 0xff) {
413 dev_err(line6->ifcdev, "write failed after %d retries\n",
414 count);
415 return -EIO;
416 } else if (status != 0) {
705ececd 417 dev_err(line6->ifcdev, "write failed (error %d)\n", ret);
e474e7fd 418 return -EIO;
705ececd
MG
419 }
420
421 return 0;
422}
ccddbe4a 423EXPORT_SYMBOL_GPL(line6_write_data);
705ececd
MG
424
425/*
c6fffce9 426 Read Line 6 device serial number.
705ececd
MG
427 (POD, TonePort, GuitarPort)
428*/
12b00157 429int line6_read_serial_number(struct usb_line6 *line6, u32 *serial_number)
705ececd 430{
e1a164d7
MG
431 return line6_read_data(line6, 0x80d0, serial_number,
432 sizeof(*serial_number));
705ececd 433}
ccddbe4a 434EXPORT_SYMBOL_GPL(line6_read_serial_number);
705ececd 435
705ececd 436/*
85a9339b 437 Card destructor.
705ececd 438*/
85a9339b 439static void line6_destruct(struct snd_card *card)
705ececd 440{
85a9339b 441 struct usb_line6 *line6 = card->private_data;
aca514b8 442 struct usb_device *usbdev = line6->usbdev;
705ececd
MG
443
444 /* free buffer memory first: */
36445bc1
GKH
445 kfree(line6->buffer_message);
446 kfree(line6->buffer_listen);
705ececd
MG
447
448 /* then free URBs: */
36445bc1 449 usb_free_urb(line6->urb_listen);
705ececd 450
85a9339b
TI
451 /* decrement reference counters: */
452 usb_put_dev(usbdev);
705ececd
MG
453}
454
644d9085
TI
455/* get data from endpoint descriptor (see usb_maxpacket): */
456static void line6_get_interval(struct usb_line6 *line6)
457{
458 struct usb_device *usbdev = line6->usbdev;
459 struct usb_host_endpoint *ep;
460 unsigned pipe = usb_rcvintpipe(usbdev, line6->properties->ep_ctrl_r);
461 unsigned epnum = usb_pipeendpoint(pipe);
462
463 ep = usbdev->ep_in[epnum];
464 if (ep) {
465 line6->interval = ep->desc.bInterval;
466 line6->max_packet_size = le16_to_cpu(ep->desc.wMaxPacketSize);
467 } else {
468 dev_err(line6->ifcdev,
469 "endpoint not available, using fallback values");
470 line6->interval = LINE6_FALLBACK_INTERVAL;
471 line6->max_packet_size = LINE6_FALLBACK_MAXPACKETSIZE;
472 }
473}
474
475static int line6_init_cap_control(struct usb_line6 *line6)
476{
477 int ret;
478
479 /* initialize USB buffers: */
480 line6->buffer_listen = kmalloc(LINE6_BUFSIZE_LISTEN, GFP_KERNEL);
481 if (!line6->buffer_listen)
482 return -ENOMEM;
483
484 line6->buffer_message = kmalloc(LINE6_MESSAGE_MAXLEN, GFP_KERNEL);
485 if (!line6->buffer_message)
486 return -ENOMEM;
487
488 line6->urb_listen = usb_alloc_urb(0, GFP_KERNEL);
489 if (!line6->urb_listen)
490 return -ENOMEM;
491
492 ret = line6_start_listen(line6);
493 if (ret < 0) {
494 dev_err(line6->ifcdev, "cannot start listening: %d\n", ret);
495 return ret;
496 }
497
498 return 0;
499}
500
705ececd
MG
501/*
502 Probe USB device.
503*/
ccddbe4a 504int line6_probe(struct usb_interface *interface,
f66fd990 505 const struct usb_device_id *id,
12865cac 506 const char *driver_name,
ccddbe4a 507 const struct line6_properties *properties,
aca514b8
TI
508 int (*private_init)(struct usb_line6 *, const struct usb_device_id *id),
509 size_t data_size)
705ececd 510{
35ae48a3 511 struct usb_device *usbdev = interface_to_usbdev(interface);
85a9339b 512 struct snd_card *card;
aca514b8 513 struct usb_line6 *line6;
7b9584fa 514 int interface_number;
705ececd
MG
515 int ret;
516
aca514b8
TI
517 if (WARN_ON(data_size < sizeof(*line6)))
518 return -EINVAL;
519
d6ca69d8
TI
520 /* we don't handle multiple configurations */
521 if (usbdev->descriptor.bNumConfigurations != 1)
522 return -ENODEV;
523
6b562f63
TI
524 ret = snd_card_new(&interface->dev,
525 SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
aca514b8
TI
526 THIS_MODULE, data_size, &card);
527 if (ret < 0)
6b562f63 528 return ret;
705ececd 529
705ececd 530 /* store basic data: */
aca514b8 531 line6 = card->private_data;
6b562f63 532 line6->card = card;
705ececd
MG
533 line6->properties = properties;
534 line6->usbdev = usbdev;
535 line6->ifcdev = &interface->dev;
705ececd 536
d6ca69d8 537 strcpy(card->id, properties->id);
12865cac 538 strcpy(card->driver, driver_name);
d6ca69d8
TI
539 strcpy(card->shortname, properties->name);
540 sprintf(card->longname, "Line 6 %s at USB %s", properties->name,
85a9339b 541 dev_name(line6->ifcdev));
85a9339b
TI
542 card->private_free = line6_destruct;
543
705ececd
MG
544 usb_set_intfdata(interface, line6);
545
85a9339b
TI
546 /* increment reference counters: */
547 usb_get_dev(usbdev);
548
6b562f63
TI
549 /* initialize device info: */
550 dev_info(&interface->dev, "Line 6 %s found\n", properties->name);
551
552 /* query interface number */
553 interface_number = interface->cur_altsetting->desc.bInterfaceNumber;
554
555 ret = usb_set_interface(usbdev, interface_number,
d6ca69d8 556 properties->altsetting);
6b562f63
TI
557 if (ret < 0) {
558 dev_err(&interface->dev, "set_interface failed\n");
559 goto error;
560 }
561
562 line6_get_interval(line6);
563
4cb1a4ae 564 if (properties->capabilities & LINE6_CAP_CONTROL) {
644d9085
TI
565 ret = line6_init_cap_control(line6);
566 if (ret < 0)
6b562f63 567 goto error;
705ececd
MG
568 }
569
a23a8bff 570 /* initialize device data based on device: */
f66fd990 571 ret = private_init(line6, id);
ab366c1a 572 if (ret < 0)
6b562f63 573 goto error;
705ececd 574
1027f476
MG
575 /* creation of additional special files should go here */
576
c6fffce9 577 dev_info(&interface->dev, "Line 6 %s now attached\n",
d6ca69d8 578 properties->name);
1027f476 579
ab366c1a
KV
580 return 0;
581
6b562f63 582 error:
eedd0e95 583 if (line6->disconnect)
f66fd990 584 line6->disconnect(line6);
85a9339b 585 snd_card_free(card);
705ececd
MG
586 return ret;
587}
ccddbe4a 588EXPORT_SYMBOL_GPL(line6_probe);
705ececd
MG
589
590/*
c6fffce9 591 Line 6 device disconnected.
705ececd 592*/
ccddbe4a 593void line6_disconnect(struct usb_interface *interface)
705ececd 594{
270fd9c7
TI
595 struct usb_line6 *line6 = usb_get_intfdata(interface);
596 struct usb_device *usbdev = interface_to_usbdev(interface);
705ececd 597
85a9339b
TI
598 if (!line6)
599 return;
705ececd 600
2a324fcd
TI
601 if (WARN_ON(usbdev != line6->usbdev))
602 return;
603
85a9339b
TI
604 if (line6->urb_listen != NULL)
605 line6_stop_listen(line6);
705ececd 606
85a9339b 607 snd_card_disconnect(line6->card);
5a475311
TI
608 if (line6->line6pcm)
609 line6_pcm_disconnect(line6->line6pcm);
85a9339b 610 if (line6->disconnect)
f66fd990 611 line6->disconnect(line6);
705ececd 612
c6fffce9 613 dev_info(&interface->dev, "Line 6 %s now disconnected\n",
85a9339b 614 line6->properties->name);
705ececd 615
85a9339b
TI
616 /* make sure the device isn't destructed twice: */
617 usb_set_intfdata(interface, NULL);
ccddbe4a 618
85a9339b 619 snd_card_free_when_closed(line6->card);
1027f476 620}
ccddbe4a 621EXPORT_SYMBOL_GPL(line6_disconnect);
1027f476
MG
622
623#ifdef CONFIG_PM
624
625/*
c6fffce9 626 Suspend Line 6 device.
1027f476 627*/
ccddbe4a 628int line6_suspend(struct usb_interface *interface, pm_message_t message)
1027f476
MG
629{
630 struct usb_line6 *line6 = usb_get_intfdata(interface);
631 struct snd_line6_pcm *line6pcm = line6->line6pcm;
632
633 snd_power_change_state(line6->card, SNDRV_CTL_POWER_D3hot);
634
4cb1a4ae 635 if (line6->properties->capabilities & LINE6_CAP_CONTROL)
1027f476
MG
636 line6_stop_listen(line6);
637
638 if (line6pcm != NULL) {
639 snd_pcm_suspend_all(line6pcm->pcm);
1027f476
MG
640 line6pcm->flags = 0;
641 }
642
643 return 0;
644}
ccddbe4a 645EXPORT_SYMBOL_GPL(line6_suspend);
1027f476
MG
646
647/*
c6fffce9 648 Resume Line 6 device.
1027f476 649*/
ccddbe4a 650int line6_resume(struct usb_interface *interface)
1027f476
MG
651{
652 struct usb_line6 *line6 = usb_get_intfdata(interface);
653
4cb1a4ae 654 if (line6->properties->capabilities & LINE6_CAP_CONTROL)
1027f476
MG
655 line6_start_listen(line6);
656
657 snd_power_change_state(line6->card, SNDRV_CTL_POWER_D0);
658 return 0;
659}
ccddbe4a 660EXPORT_SYMBOL_GPL(line6_resume);
705ececd 661
e1a164d7 662#endif /* CONFIG_PM */
1027f476 663
705ececd
MG
664MODULE_AUTHOR(DRIVER_AUTHOR);
665MODULE_DESCRIPTION(DRIVER_DESC);
666MODULE_LICENSE("GPL");
This page took 1.826775 seconds and 5 git commands to generate.