driver.c 15.6 KB
Newer Older
M
Markus Grabner 已提交
1
/*
2
 * Line 6 Linux USB driver
M
Markus Grabner 已提交
3
 *
4
 * Copyright (C) 2004-2010 Markus Grabner (grabner@icg.tugraz.at)
M
Markus Grabner 已提交
5 6 7 8 9 10 11 12 13
 *
 *	This program is free software; you can redistribute it and/or
 *	modify it under the terms of the GNU General Public License as
 *	published by the Free Software Foundation, version 2.
 *
 */

#include <linux/kernel.h>
#include <linux/module.h>
T
Takashi Iwai 已提交
14
#include <linux/export.h>
15
#include <linux/slab.h>
M
Markus Grabner 已提交
16 17
#include <linux/usb.h>

18 19 20
#include <sound/core.h>
#include <sound/initval.h>

M
Markus Grabner 已提交
21
#include "capture.h"
22
#include "driver.h"
M
Markus Grabner 已提交
23 24 25 26
#include "midi.h"
#include "playback.h"

#define DRIVER_AUTHOR  "Markus Grabner <grabner@icg.tugraz.at>"
27
#define DRIVER_DESC    "Line 6 USB Driver"
M
Markus Grabner 已提交
28 29

/*
30
	This is Line 6's MIDI manufacturer ID.
M
Markus Grabner 已提交
31
*/
32 33 34
const unsigned char line6_midi_id[] = {
	0x00, 0x01, 0x0c
};
T
Takashi Iwai 已提交
35
EXPORT_SYMBOL_GPL(line6_midi_id);
36 37 38 39 40

/*
	Code to request version of POD, Variax interface
	(and maybe other devices).
*/
41
static const char line6_request_version[] = {
42 43 44
	0xf0, 0x7e, 0x7f, 0x06, 0x01, 0xf7
};

45
/*
M
Markus Grabner 已提交
46 47
	 Class for asynchronous messages.
*/
48
struct message {
M
Markus Grabner 已提交
49 50 51 52 53 54 55 56 57
	struct usb_line6 *line6;
	const char *buffer;
	int size;
	int done;
};

/*
	Forward declarations.
*/
58
static void line6_data_received(struct urb *urb);
59 60
static int line6_send_raw_message_async_part(struct message *msg,
					     struct urb *urb);
M
Markus Grabner 已提交
61 62 63 64 65 66

/*
	Start to listen on endpoint.
*/
static int line6_start_listen(struct usb_line6 *line6)
{
67
	int err;
68

69
	usb_fill_int_urb(line6->urb_listen, line6->usbdev,
70 71 72
		usb_rcvintpipe(line6->usbdev, line6->properties->ep_ctrl_r),
		line6->buffer_listen, LINE6_BUFSIZE_LISTEN,
		line6_data_received, line6, line6->interval);
M
Markus Grabner 已提交
73
	line6->urb_listen->actual_length = 0;
74
	err = usb_submit_urb(line6->urb_listen, GFP_ATOMIC);
75 76 77 78 79 80 81 82 83
	return err;
}

/*
	Stop listening on endpoint.
*/
static void line6_stop_listen(struct usb_line6 *line6)
{
	usb_kill_urb(line6->urb_listen);
M
Markus Grabner 已提交
84 85 86
}

/*
87
	Send raw message in pieces of wMaxPacketSize bytes.
M
Markus Grabner 已提交
88
*/
89 90
static int line6_send_raw_message(struct usb_line6 *line6, const char *buffer,
				  int size)
M
Markus Grabner 已提交
91 92 93
{
	int i, done = 0;

94 95
	for (i = 0; i < size; i += line6->max_packet_size) {
		int partial;
M
Markus Grabner 已提交
96 97
		const char *frag_buf = buffer + i;
		int frag_size = min(line6->max_packet_size, size - i);
98 99 100
		int retval;

		retval = usb_interrupt_msg(line6->usbdev,
D
Davide Berardi 已提交
101
					usb_sndintpipe(line6->usbdev,
102
						line6->properties->ep_ctrl_w),
D
Davide Berardi 已提交
103 104
					(char *)frag_buf, frag_size,
					&partial, LINE6_TIMEOUT * HZ);
M
Markus Grabner 已提交
105

106 107 108
		if (retval) {
			dev_err(line6->ifcdev,
				"usb_interrupt_msg failed (%d)\n", retval);
M
Markus Grabner 已提交
109 110 111
			break;
		}

112
		done += frag_size;
M
Markus Grabner 已提交
113 114 115 116 117 118 119 120
	}

	return done;
}

/*
	Notification of completion of asynchronous request transmission.
*/
121
static void line6_async_request_sent(struct urb *urb)
M
Markus Grabner 已提交
122 123 124
{
	struct message *msg = (struct message *)urb->context;

125
	if (msg->done >= msg->size) {
M
Markus Grabner 已提交
126 127
		usb_free_urb(urb);
		kfree(msg);
128
	} else
M
Markus Grabner 已提交
129 130 131 132 133 134
		line6_send_raw_message_async_part(msg, urb);
}

/*
	Asynchronously send part of a raw message.
*/
135 136
static int line6_send_raw_message_async_part(struct message *msg,
					     struct urb *urb)
M
Markus Grabner 已提交
137 138 139 140 141 142
{
	int retval;
	struct usb_line6 *line6 = msg->line6;
	int done = msg->done;
	int bytes = min(msg->size - done, line6->max_packet_size);

143
	usb_fill_int_urb(urb, line6->usbdev,
144 145 146
		usb_sndintpipe(line6->usbdev, line6->properties->ep_ctrl_w),
		(char *)msg->buffer + done, bytes,
		line6_async_request_sent, msg, line6->interval);
M
Markus Grabner 已提交
147 148 149 150

	msg->done += bytes;
	retval = usb_submit_urb(urb, GFP_ATOMIC);

151 152 153
	if (retval < 0) {
		dev_err(line6->ifcdev, "%s: usb_submit_urb failed (%d)\n",
			__func__, retval);
M
Markus Grabner 已提交
154 155
		usb_free_urb(urb);
		kfree(msg);
156
		return retval;
M
Markus Grabner 已提交
157 158 159 160 161
	}

	return 0;
}

162 163 164
/*
	Setup and start timer.
*/
165
void line6_start_timer(struct timer_list *timer, unsigned long msecs,
166
		       void (*function)(unsigned long), unsigned long data)
167 168
{
	setup_timer(timer, function, data);
169
	mod_timer(timer, jiffies + msecs_to_jiffies(msecs));
170
}
T
Takashi Iwai 已提交
171
EXPORT_SYMBOL_GPL(line6_start_timer);
172

M
Markus Grabner 已提交
173 174 175
/*
	Asynchronously send raw message.
*/
176 177
int line6_send_raw_message_async(struct usb_line6 *line6, const char *buffer,
				 int size)
M
Markus Grabner 已提交
178 179 180 181 182 183
{
	struct message *msg;
	struct urb *urb;

	/* create message: */
	msg = kmalloc(sizeof(struct message), GFP_ATOMIC);
184
	if (msg == NULL)
M
Markus Grabner 已提交
185 186 187 188 189
		return -ENOMEM;

	/* create URB: */
	urb = usb_alloc_urb(0, GFP_ATOMIC);

190
	if (urb == NULL) {
M
Markus Grabner 已提交
191 192 193 194 195 196 197 198 199 200 201 202 203
		kfree(msg);
		return -ENOMEM;
	}

	/* set message data: */
	msg->line6 = line6;
	msg->buffer = buffer;
	msg->size = size;
	msg->done = 0;

	/* start sending: */
	return line6_send_raw_message_async_part(msg, urb);
}
T
Takashi Iwai 已提交
204
EXPORT_SYMBOL_GPL(line6_send_raw_message_async);
M
Markus Grabner 已提交
205

206 207 208 209 210
/*
	Send asynchronous device version request.
*/
int line6_version_request_async(struct usb_line6 *line6)
{
211 212 213
	char *buffer;
	int retval;

214 215
	buffer = kmemdup(line6_request_version,
			sizeof(line6_request_version), GFP_ATOMIC);
216
	if (buffer == NULL)
217 218 219 220 221 222
		return -ENOMEM;

	retval = line6_send_raw_message_async(line6, buffer,
					      sizeof(line6_request_version));
	kfree(buffer);
	return retval;
223
}
T
Takashi Iwai 已提交
224
EXPORT_SYMBOL_GPL(line6_version_request_async);
225

M
Markus Grabner 已提交
226 227 228
/*
	Send sysex message in pieces of wMaxPacketSize bytes.
*/
229 230
int line6_send_sysex_message(struct usb_line6 *line6, const char *buffer,
			     int size)
M
Markus Grabner 已提交
231
{
232 233 234
	return line6_send_raw_message(line6, buffer,
				      size + SYSEX_EXTRA_SIZE) -
	    SYSEX_EXTRA_SIZE;
M
Markus Grabner 已提交
235
}
T
Takashi Iwai 已提交
236
EXPORT_SYMBOL_GPL(line6_send_sysex_message);
M
Markus Grabner 已提交
237 238 239 240 241 242

/*
	Allocate buffer for sysex message and prepare header.
	@param code sysex message code
	@param size number of bytes between code and sysex end
*/
243 244
char *line6_alloc_sysex_buffer(struct usb_line6 *line6, int code1, int code2,
			       int size)
M
Markus Grabner 已提交
245
{
246
	char *buffer = kmalloc(size + SYSEX_EXTRA_SIZE, GFP_ATOMIC);
M
Markus Grabner 已提交
247

248
	if (!buffer)
249
		return NULL;
M
Markus Grabner 已提交
250 251 252 253 254 255 256 257

	buffer[0] = LINE6_SYSEX_BEGIN;
	memcpy(buffer + 1, line6_midi_id, sizeof(line6_midi_id));
	buffer[sizeof(line6_midi_id) + 1] = code1;
	buffer[sizeof(line6_midi_id) + 2] = code2;
	buffer[sizeof(line6_midi_id) + 3 + size] = LINE6_SYSEX_END;
	return buffer;
}
T
Takashi Iwai 已提交
258
EXPORT_SYMBOL_GPL(line6_alloc_sysex_buffer);
M
Markus Grabner 已提交
259 260

/*
261
	Notification of data received from the Line 6 device.
M
Markus Grabner 已提交
262
*/
263
static void line6_data_received(struct urb *urb)
M
Markus Grabner 已提交
264 265
{
	struct usb_line6 *line6 = (struct usb_line6 *)urb->context;
266
	struct midi_buffer *mb = &line6->line6midi->midibuf_in;
M
Markus Grabner 已提交
267 268
	int done;

269
	if (urb->status == -ESHUTDOWN)
M
Markus Grabner 已提交
270 271
		return;

272 273
	done =
	    line6_midibuf_write(mb, urb->transfer_buffer, urb->actual_length);
M
Markus Grabner 已提交
274

275
	if (done < urb->actual_length) {
276
		line6_midibuf_ignore(mb, done);
277 278
		dev_dbg(line6->ifcdev, "%d %d buffer overflow - message skipped\n",
			done, urb->actual_length);
M
Markus Grabner 已提交
279 280
	}

281
	for (;;) {
282 283 284
		done =
		    line6_midibuf_read(mb, line6->buffer_message,
				       LINE6_MESSAGE_MAXLEN);
M
Markus Grabner 已提交
285

286
		if (done == 0)
M
Markus Grabner 已提交
287 288 289 290 291
			break;

		line6->message_length = done;
		line6_midi_receive(line6, line6->buffer_message, done);

292 293
		if (line6->process_message)
			line6->process_message(line6);
M
Markus Grabner 已提交
294 295 296 297 298
	}

	line6_start_listen(line6);
}

299
#define LINE6_READ_WRITE_STATUS_DELAY 2  /* milliseconds */
300
#define LINE6_READ_WRITE_MAX_RETRIES 50
301

M
Markus Grabner 已提交
302 303 304
/*
	Read data from device.
*/
305 306
int line6_read_data(struct usb_line6 *line6, unsigned address, void *data,
		    unsigned datalen)
M
Markus Grabner 已提交
307 308 309 310
{
	struct usb_device *usbdev = line6->usbdev;
	int ret;
	unsigned char len;
311
	unsigned count;
M
Markus Grabner 已提交
312

313 314 315
	if (address > 0xffff || datalen > 0xff)
		return -EINVAL;

M
Markus Grabner 已提交
316 317
	/* query the serial number: */
	ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67,
318 319 320
			      USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
			      (datalen << 8) | 0x21, address,
			      NULL, 0, LINE6_TIMEOUT * HZ);
M
Markus Grabner 已提交
321

322
	if (ret < 0) {
M
Markus Grabner 已提交
323 324 325 326
		dev_err(line6->ifcdev, "read request failed (error %d)\n", ret);
		return ret;
	}

327
	/* Wait for data length. We'll get 0xff until length arrives. */
328
	for (count = 0; count < LINE6_READ_WRITE_MAX_RETRIES; count++) {
329 330
		mdelay(LINE6_READ_WRITE_STATUS_DELAY);

M
Markus Grabner 已提交
331
		ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
332 333 334 335 336 337 338
				      USB_TYPE_VENDOR | USB_RECIP_DEVICE |
				      USB_DIR_IN,
				      0x0012, 0x0000, &len, 1,
				      LINE6_TIMEOUT * HZ);
		if (ret < 0) {
			dev_err(line6->ifcdev,
				"receive length failed (error %d)\n", ret);
M
Markus Grabner 已提交
339 340
			return ret;
		}
341

342 343 344 345 346 347 348 349 350
		if (len != 0xff)
			break;
	}

	if (len == 0xff) {
		dev_err(line6->ifcdev, "read failed after %d retries\n",
			count);
		return -EIO;
	} else if (len != datalen) {
351 352 353 354
		/* should be equal or something went wrong */
		dev_err(line6->ifcdev,
			"length mismatch (expected %d, got %d)\n",
			(int)datalen, (int)len);
355
		return -EIO;
M
Markus Grabner 已提交
356 357 358 359
	}

	/* receive the result: */
	ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
360 361 362
			      USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
			      0x0013, 0x0000, data, datalen,
			      LINE6_TIMEOUT * HZ);
M
Markus Grabner 已提交
363

364
	if (ret < 0) {
M
Markus Grabner 已提交
365 366 367 368 369 370
		dev_err(line6->ifcdev, "read failed (error %d)\n", ret);
		return ret;
	}

	return 0;
}
T
Takashi Iwai 已提交
371
EXPORT_SYMBOL_GPL(line6_read_data);
M
Markus Grabner 已提交
372 373 374 375

/*
	Write data to device.
*/
376 377
int line6_write_data(struct usb_line6 *line6, unsigned address, void *data,
		     unsigned datalen)
M
Markus Grabner 已提交
378 379 380 381
{
	struct usb_device *usbdev = line6->usbdev;
	int ret;
	unsigned char status;
382
	int count;
M
Markus Grabner 已提交
383

384 385 386
	if (address > 0xffff || datalen > 0xffff)
		return -EINVAL;

387 388 389 390
	ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67,
			      USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
			      0x0022, address, data, datalen,
			      LINE6_TIMEOUT * HZ);
M
Markus Grabner 已提交
391

392 393 394
	if (ret < 0) {
		dev_err(line6->ifcdev,
			"write request failed (error %d)\n", ret);
M
Markus Grabner 已提交
395 396 397
		return ret;
	}

398
	for (count = 0; count < LINE6_READ_WRITE_MAX_RETRIES; count++) {
399 400
		mdelay(LINE6_READ_WRITE_STATUS_DELAY);

401 402 403 404 405 406 407 408 409 410
		ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0),
				      0x67,
				      USB_TYPE_VENDOR | USB_RECIP_DEVICE |
				      USB_DIR_IN,
				      0x0012, 0x0000,
				      &status, 1, LINE6_TIMEOUT * HZ);

		if (ret < 0) {
			dev_err(line6->ifcdev,
				"receiving status failed (error %d)\n", ret);
M
Markus Grabner 已提交
411 412 413
			return ret;
		}

414 415 416 417 418 419 420 421 422
		if (status != 0xff)
			break;
	}

	if (status == 0xff) {
		dev_err(line6->ifcdev, "write failed after %d retries\n",
			count);
		return -EIO;
	} else if (status != 0) {
M
Markus Grabner 已提交
423
		dev_err(line6->ifcdev, "write failed (error %d)\n", ret);
424
		return -EIO;
M
Markus Grabner 已提交
425 426 427 428
	}

	return 0;
}
T
Takashi Iwai 已提交
429
EXPORT_SYMBOL_GPL(line6_write_data);
M
Markus Grabner 已提交
430 431

/*
432
	Read Line 6 device serial number.
M
Markus Grabner 已提交
433 434
	(POD, TonePort, GuitarPort)
*/
435
int line6_read_serial_number(struct usb_line6 *line6, u32 *serial_number)
M
Markus Grabner 已提交
436
{
437 438
	return line6_read_data(line6, 0x80d0, serial_number,
			       sizeof(*serial_number));
M
Markus Grabner 已提交
439
}
T
Takashi Iwai 已提交
440
EXPORT_SYMBOL_GPL(line6_read_serial_number);
M
Markus Grabner 已提交
441 442

/*
443
	Card destructor.
M
Markus Grabner 已提交
444
*/
445
static void line6_destruct(struct snd_card *card)
M
Markus Grabner 已提交
446
{
447
	struct usb_line6 *line6 = card->private_data;
448
	struct usb_device *usbdev = line6->usbdev;
M
Markus Grabner 已提交
449 450

	/* free buffer memory first: */
451 452
	kfree(line6->buffer_message);
	kfree(line6->buffer_listen);
M
Markus Grabner 已提交
453 454

	/* then free URBs: */
455
	usb_free_urb(line6->urb_listen);
M
Markus Grabner 已提交
456

457 458
	/* decrement reference counters: */
	usb_put_dev(usbdev);
M
Markus Grabner 已提交
459 460
}

T
Takashi Iwai 已提交
461 462 463 464
/* get data from endpoint descriptor (see usb_maxpacket): */
static void line6_get_interval(struct usb_line6 *line6)
{
	struct usb_device *usbdev = line6->usbdev;
465
	struct usb_host_endpoint *ep = usbdev->ep_in[line6->properties->ep_ctrl_r];
T
Takashi Iwai 已提交
466 467 468

	if (ep) {
		line6->interval = ep->desc.bInterval;
469 470 471 472 473 474 475 476
		if (usbdev->speed == USB_SPEED_LOW) {
			line6->intervals_per_second = USB_LOW_INTERVALS_PER_SECOND;
			line6->iso_buffers = USB_LOW_ISO_BUFFERS;
		} else {
			line6->intervals_per_second = USB_HIGH_INTERVALS_PER_SECOND;
			line6->iso_buffers = USB_HIGH_ISO_BUFFERS;
		}

T
Takashi Iwai 已提交
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511
		line6->max_packet_size = le16_to_cpu(ep->desc.wMaxPacketSize);
	} else {
		dev_err(line6->ifcdev,
			"endpoint not available, using fallback values");
		line6->interval = LINE6_FALLBACK_INTERVAL;
		line6->max_packet_size = LINE6_FALLBACK_MAXPACKETSIZE;
	}
}

static int line6_init_cap_control(struct usb_line6 *line6)
{
	int ret;

	/* initialize USB buffers: */
	line6->buffer_listen = kmalloc(LINE6_BUFSIZE_LISTEN, GFP_KERNEL);
	if (!line6->buffer_listen)
		return -ENOMEM;

	line6->buffer_message = kmalloc(LINE6_MESSAGE_MAXLEN, GFP_KERNEL);
	if (!line6->buffer_message)
		return -ENOMEM;

	line6->urb_listen = usb_alloc_urb(0, GFP_KERNEL);
	if (!line6->urb_listen)
		return -ENOMEM;

	ret = line6_start_listen(line6);
	if (ret < 0) {
		dev_err(line6->ifcdev, "cannot start listening: %d\n", ret);
		return ret;
	}

	return 0;
}

M
Markus Grabner 已提交
512 513 514
/*
	Probe USB device.
*/
T
Takashi Iwai 已提交
515
int line6_probe(struct usb_interface *interface,
516
		const struct usb_device_id *id,
517
		const char *driver_name,
T
Takashi Iwai 已提交
518
		const struct line6_properties *properties,
519 520
		int (*private_init)(struct usb_line6 *, const struct usb_device_id *id),
		size_t data_size)
M
Markus Grabner 已提交
521
{
522
	struct usb_device *usbdev = interface_to_usbdev(interface);
523
	struct snd_card *card;
524
	struct usb_line6 *line6;
525
	int interface_number;
M
Markus Grabner 已提交
526 527
	int ret;

528 529 530
	if (WARN_ON(data_size < sizeof(*line6)))
		return -EINVAL;

531 532 533 534
	/* we don't handle multiple configurations */
	if (usbdev->descriptor.bNumConfigurations != 1)
		return -ENODEV;

535 536
	ret = snd_card_new(&interface->dev,
			   SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
537 538
			   THIS_MODULE, data_size, &card);
	if (ret < 0)
539
		return ret;
M
Markus Grabner 已提交
540 541

	/* store basic data: */
542
	line6 = card->private_data;
543
	line6->card = card;
M
Markus Grabner 已提交
544 545 546 547
	line6->properties = properties;
	line6->usbdev = usbdev;
	line6->ifcdev = &interface->dev;

548
	strcpy(card->id, properties->id);
549
	strcpy(card->driver, driver_name);
550 551
	strcpy(card->shortname, properties->name);
	sprintf(card->longname, "Line 6 %s at USB %s", properties->name,
552 553 554
		dev_name(line6->ifcdev));
	card->private_free = line6_destruct;

M
Markus Grabner 已提交
555 556
	usb_set_intfdata(interface, line6);

557 558 559
	/* increment reference counters: */
	usb_get_dev(usbdev);

560 561 562 563 564 565
	/* initialize device info: */
	dev_info(&interface->dev, "Line 6 %s found\n", properties->name);

	/* query interface number */
	interface_number = interface->cur_altsetting->desc.bInterfaceNumber;

566
	/* TODO reserves the bus bandwidth even without actual transfer */
567
	ret = usb_set_interface(usbdev, interface_number,
568
				properties->altsetting);
569 570 571 572 573 574 575
	if (ret < 0) {
		dev_err(&interface->dev, "set_interface failed\n");
		goto error;
	}

	line6_get_interval(line6);

576
	if (properties->capabilities & LINE6_CAP_CONTROL) {
T
Takashi Iwai 已提交
577 578
		ret = line6_init_cap_control(line6);
		if (ret < 0)
579
			goto error;
M
Markus Grabner 已提交
580 581
	}

582
	/* initialize device data based on device: */
583
	ret = private_init(line6, id);
584
	if (ret < 0)
585
		goto error;
M
Markus Grabner 已提交
586

587 588
	/* creation of additional special files should go here */

589
	dev_info(&interface->dev, "Line 6 %s now attached\n",
590
		 properties->name);
591

592 593
	return 0;

594
 error:
595
	if (line6->disconnect)
596
		line6->disconnect(line6);
597
	snd_card_free(card);
M
Markus Grabner 已提交
598 599
	return ret;
}
T
Takashi Iwai 已提交
600
EXPORT_SYMBOL_GPL(line6_probe);
M
Markus Grabner 已提交
601 602

/*
603
	Line 6 device disconnected.
M
Markus Grabner 已提交
604
*/
T
Takashi Iwai 已提交
605
void line6_disconnect(struct usb_interface *interface)
M
Markus Grabner 已提交
606
{
607 608
	struct usb_line6 *line6 = usb_get_intfdata(interface);
	struct usb_device *usbdev = interface_to_usbdev(interface);
M
Markus Grabner 已提交
609

610 611
	if (!line6)
		return;
M
Markus Grabner 已提交
612

613 614 615
	if (WARN_ON(usbdev != line6->usbdev))
		return;

616 617
	if (line6->urb_listen != NULL)
		line6_stop_listen(line6);
M
Markus Grabner 已提交
618

619
	snd_card_disconnect(line6->card);
620 621
	if (line6->line6pcm)
		line6_pcm_disconnect(line6->line6pcm);
622
	if (line6->disconnect)
623
		line6->disconnect(line6);
M
Markus Grabner 已提交
624

625
	dev_info(&interface->dev, "Line 6 %s now disconnected\n",
626
		 line6->properties->name);
M
Markus Grabner 已提交
627

628 629
	/* make sure the device isn't destructed twice: */
	usb_set_intfdata(interface, NULL);
T
Takashi Iwai 已提交
630

631
	snd_card_free_when_closed(line6->card);
632
}
T
Takashi Iwai 已提交
633
EXPORT_SYMBOL_GPL(line6_disconnect);
634 635 636 637

#ifdef CONFIG_PM

/*
638
	Suspend Line 6 device.
639
*/
T
Takashi Iwai 已提交
640
int line6_suspend(struct usb_interface *interface, pm_message_t message)
641 642 643 644 645 646
{
	struct usb_line6 *line6 = usb_get_intfdata(interface);
	struct snd_line6_pcm *line6pcm = line6->line6pcm;

	snd_power_change_state(line6->card, SNDRV_CTL_POWER_D3hot);

647
	if (line6->properties->capabilities & LINE6_CAP_CONTROL)
648 649 650 651 652 653 654 655 656
		line6_stop_listen(line6);

	if (line6pcm != NULL) {
		snd_pcm_suspend_all(line6pcm->pcm);
		line6pcm->flags = 0;
	}

	return 0;
}
T
Takashi Iwai 已提交
657
EXPORT_SYMBOL_GPL(line6_suspend);
658 659

/*
660
	Resume Line 6 device.
661
*/
T
Takashi Iwai 已提交
662
int line6_resume(struct usb_interface *interface)
663 664 665
{
	struct usb_line6 *line6 = usb_get_intfdata(interface);

666
	if (line6->properties->capabilities & LINE6_CAP_CONTROL)
667 668 669 670 671
		line6_start_listen(line6);

	snd_power_change_state(line6->card, SNDRV_CTL_POWER_D0);
	return 0;
}
T
Takashi Iwai 已提交
672
EXPORT_SYMBOL_GPL(line6_resume);
M
Markus Grabner 已提交
673

674
#endif /* CONFIG_PM */
675

M
Markus Grabner 已提交
676 677 678
MODULE_AUTHOR(DRIVER_AUTHOR);
MODULE_DESCRIPTION(DRIVER_DESC);
MODULE_LICENSE("GPL");