driver.c 16.0 KB
Newer Older
M
Markus Grabner 已提交
1
/*
2
 * Line6 Linux USB driver - 0.9.1beta
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 18 19
#include <linux/usb.h>

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

#define DRIVER_AUTHOR  "Markus Grabner <grabner@icg.tugraz.at>"
#define DRIVER_DESC    "Line6 USB Driver"
28
#define DRIVER_VERSION "0.9.1beta" DRIVER_REVISION
M
Markus Grabner 已提交
29 30 31 32

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

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

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

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

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

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

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

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

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

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

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

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

	return done;
}

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

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

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

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

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

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

	return 0;
}

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

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

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

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

191
	if (urb == NULL) {
M
Markus Grabner 已提交
192 193 194 195 196 197 198 199 200 201 202 203 204 205
		kfree(msg);
		dev_err(line6->ifcdev, "Out of memory\n");
		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 已提交
206
EXPORT_SYMBOL_GPL(line6_send_raw_message_async);
M
Markus Grabner 已提交
207

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

216 217
	buffer = kmemdup(line6_request_version,
			sizeof(line6_request_version), GFP_ATOMIC);
218 219 220 221 222 223 224 225 226
	if (buffer == NULL) {
		dev_err(line6->ifcdev, "Out of memory");
		return -ENOMEM;
	}

	retval = line6_send_raw_message_async(line6, buffer,
					      sizeof(line6_request_version));
	kfree(buffer);
	return retval;
227
}
T
Takashi Iwai 已提交
228
EXPORT_SYMBOL_GPL(line6_version_request_async);
229

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

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

252
	if (!buffer)
253
		return NULL;
M
Markus Grabner 已提交
254 255 256 257 258 259 260 261

	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 已提交
262
EXPORT_SYMBOL_GPL(line6_alloc_sysex_buffer);
M
Markus Grabner 已提交
263 264 265 266

/*
	Notification of data received from the Line6 device.
*/
267
static void line6_data_received(struct urb *urb)
M
Markus Grabner 已提交
268 269
{
	struct usb_line6 *line6 = (struct usb_line6 *)urb->context;
270
	struct midi_buffer *mb = &line6->line6midi->midibuf_in;
M
Markus Grabner 已提交
271 272
	int done;

273
	if (urb->status == -ESHUTDOWN)
M
Markus Grabner 已提交
274 275
		return;

276 277
	done =
	    line6_midibuf_write(mb, urb->transfer_buffer, urb->actual_length);
M
Markus Grabner 已提交
278

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

285
	for (;;) {
286 287 288
		done =
		    line6_midibuf_read(mb, line6->buffer_message,
				       LINE6_MESSAGE_MAXLEN);
M
Markus Grabner 已提交
289

290
		if (done == 0)
M
Markus Grabner 已提交
291 292 293 294 295
			break;

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

296 297
		if (line6->process_message)
			line6->process_message(line6);
M
Markus Grabner 已提交
298 299 300 301 302 303 304 305
	}

	line6_start_listen(line6);
}

/*
	Send channel number (i.e., switch to a different sound).
*/
306
int line6_send_program(struct usb_line6 *line6, u8 value)
M
Markus Grabner 已提交
307
{
308
	int retval;
M
Markus Grabner 已提交
309
	unsigned char *buffer;
310 311 312
	int partial;

	buffer = kmalloc(2, GFP_KERNEL);
313
	if (!buffer)
M
Markus Grabner 已提交
314 315 316 317 318
		return -ENOMEM;

	buffer[0] = LINE6_PROGRAM_CHANGE | LINE6_CHANNEL_HOST;
	buffer[1] = value;

319 320
	retval = usb_interrupt_msg(line6->usbdev,
				   usb_sndintpipe(line6->usbdev,
321
						  line6->properties->ep_ctrl_w),
322 323 324
				   buffer, 2, &partial, LINE6_TIMEOUT * HZ);

	if (retval)
325 326
		dev_err(line6->ifcdev, "usb_interrupt_msg failed (%d)\n",
			retval);
327 328 329

	kfree(buffer);
	return retval;
M
Markus Grabner 已提交
330 331 332 333 334
}

/*
	Transmit Line6 control parameter.
*/
335
int line6_transmit_parameter(struct usb_line6 *line6, int param, u8 value)
M
Markus Grabner 已提交
336
{
337
	int retval;
M
Markus Grabner 已提交
338
	unsigned char *buffer;
339 340 341
	int partial;

	buffer = kmalloc(3, GFP_KERNEL);
342
	if (!buffer)
M
Markus Grabner 已提交
343 344 345 346 347 348
		return -ENOMEM;

	buffer[0] = LINE6_PARAM_CHANGE | LINE6_CHANNEL_HOST;
	buffer[1] = param;
	buffer[2] = value;

349
	retval = usb_interrupt_msg(line6->usbdev,
350
				   usb_sndintpipe(line6->usbdev,
351
						  line6->properties->ep_ctrl_w),
352 353 354
				   buffer, 3, &partial, LINE6_TIMEOUT * HZ);

	if (retval)
355 356
		dev_err(line6->ifcdev, "usb_interrupt_msg failed (%d)\n",
			retval);
357 358 359

	kfree(buffer);
	return retval;
M
Markus Grabner 已提交
360 361 362 363 364
}

/*
	Read data from device.
*/
365 366
int line6_read_data(struct usb_line6 *line6, int address, void *data,
		    size_t datalen)
M
Markus Grabner 已提交
367 368 369 370 371 372 373
{
	struct usb_device *usbdev = line6->usbdev;
	int ret;
	unsigned char len;

	/* query the serial number: */
	ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67,
374 375 376
			      USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
			      (datalen << 8) | 0x21, address,
			      NULL, 0, LINE6_TIMEOUT * HZ);
M
Markus Grabner 已提交
377

378
	if (ret < 0) {
M
Markus Grabner 已提交
379 380 381 382
		dev_err(line6->ifcdev, "read request failed (error %d)\n", ret);
		return ret;
	}

383
	/* Wait for data length. We'll get 0xff until length arrives. */
M
Markus Grabner 已提交
384 385
	do {
		ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
386 387 388 389 390 391 392
				      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 已提交
393 394
			return ret;
		}
395
	} while (len == 0xff);
396 397 398 399 400 401

	if (len != datalen) {
		/* should be equal or something went wrong */
		dev_err(line6->ifcdev,
			"length mismatch (expected %d, got %d)\n",
			(int)datalen, (int)len);
M
Markus Grabner 已提交
402 403 404 405 406
		return -EINVAL;
	}

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

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

	return 0;
}
T
Takashi Iwai 已提交
418
EXPORT_SYMBOL_GPL(line6_read_data);
M
Markus Grabner 已提交
419 420 421 422

/*
	Write data to device.
*/
423 424
int line6_write_data(struct usb_line6 *line6, int address, void *data,
		     size_t datalen)
M
Markus Grabner 已提交
425 426 427 428 429
{
	struct usb_device *usbdev = line6->usbdev;
	int ret;
	unsigned char status;

430 431 432 433
	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 已提交
434

435 436 437
	if (ret < 0) {
		dev_err(line6->ifcdev,
			"write request failed (error %d)\n", ret);
M
Markus Grabner 已提交
438 439 440 441
		return ret;
	}

	do {
442 443 444 445 446 447 448 449 450 451
		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 已提交
452 453
			return ret;
		}
454
	} while (status == 0xff);
M
Markus Grabner 已提交
455

456
	if (status != 0) {
M
Markus Grabner 已提交
457 458 459 460 461 462
		dev_err(line6->ifcdev, "write failed (error %d)\n", ret);
		return -EINVAL;
	}

	return 0;
}
T
Takashi Iwai 已提交
463
EXPORT_SYMBOL_GPL(line6_write_data);
M
Markus Grabner 已提交
464 465 466 467 468 469 470

/*
	Read Line6 device serial number.
	(POD, TonePort, GuitarPort)
*/
int line6_read_serial_number(struct usb_line6 *line6, int *serial_number)
{
471 472
	return line6_read_data(line6, 0x80d0, serial_number,
			       sizeof(*serial_number));
M
Markus Grabner 已提交
473
}
T
Takashi Iwai 已提交
474
EXPORT_SYMBOL_GPL(line6_read_serial_number);
M
Markus Grabner 已提交
475 476 477 478

/*
	No operation (i.e., unsupported).
*/
479 480
ssize_t line6_nop_read(struct device *dev, struct device_attribute *attr,
		       char *buf)
M
Markus Grabner 已提交
481 482 483
{
	return 0;
}
T
Takashi Iwai 已提交
484
EXPORT_SYMBOL_GPL(line6_nop_read);
M
Markus Grabner 已提交
485 486 487 488 489 490 491

/*
	Generic destructor.
*/
static void line6_destruct(struct usb_interface *interface)
{
	struct usb_line6 *line6;
492 493 494

	if (interface == NULL)
		return;
M
Markus Grabner 已提交
495
	line6 = usb_get_intfdata(interface);
496 497
	if (line6 == NULL)
		return;
M
Markus Grabner 已提交
498 499

	/* free buffer memory first: */
500 501
	kfree(line6->buffer_message);
	kfree(line6->buffer_listen);
M
Markus Grabner 已提交
502 503

	/* then free URBs: */
504
	usb_free_urb(line6->urb_listen);
M
Markus Grabner 已提交
505 506 507 508 509 510 511 512

	/* make sure the device isn't destructed twice: */
	usb_set_intfdata(interface, NULL);
}

/*
	Probe USB device.
*/
T
Takashi Iwai 已提交
513 514 515 516
int line6_probe(struct usb_interface *interface,
		struct usb_line6 *line6,
		const struct line6_properties *properties,
		int (*private_init)(struct usb_interface *, struct usb_line6 *))
M
Markus Grabner 已提交
517
{
518
	struct usb_device *usbdev;
519
	int interface_number;
M
Markus Grabner 已提交
520 521
	int ret;

T
Takashi Iwai 已提交
522 523 524 525
	if (!interface) {
		ret = -ENODEV;
		goto err_put;
	}
M
Markus Grabner 已提交
526
	usbdev = interface_to_usbdev(interface);
T
Takashi Iwai 已提交
527 528 529 530
	if (!usbdev) {
		ret = -ENODEV;
		goto err_put;
	}
M
Markus Grabner 已提交
531 532

	/* we don't handle multiple configurations */
533 534 535 536
	if (usbdev->descriptor.bNumConfigurations != 1) {
		ret = -ENODEV;
		goto err_put;
	}
M
Markus Grabner 已提交
537 538 539 540 541 542 543

	/* initialize device info: */
	dev_info(&interface->dev, "Line6 %s found\n", properties->name);

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

544 545
	ret = usb_set_interface(usbdev, interface_number,
			properties->altsetting);
546
	if (ret < 0) {
M
Markus Grabner 已提交
547
		dev_err(&interface->dev, "set_interface failed\n");
548
		goto err_put;
M
Markus Grabner 已提交
549 550 551 552 553 554 555 556 557 558
	}

	/* store basic data: */
	line6->properties = properties;
	line6->usbdev = usbdev;
	line6->ifcdev = &interface->dev;

	/* get data from endpoint descriptor (see usb_maxpacket): */
	{
		struct usb_host_endpoint *ep;
559 560
		unsigned pipe = usb_rcvintpipe(usbdev, properties->ep_ctrl_r);
		unsigned epnum = usb_pipeendpoint(pipe);
M
Markus Grabner 已提交
561 562
		ep = usbdev->ep_in[epnum];

563
		if (ep != NULL) {
M
Markus Grabner 已提交
564
			line6->interval = ep->desc.bInterval;
565 566
			line6->max_packet_size =
			    le16_to_cpu(ep->desc.wMaxPacketSize);
567
		} else {
M
Markus Grabner 已提交
568 569
			line6->interval = LINE6_FALLBACK_INTERVAL;
			line6->max_packet_size = LINE6_FALLBACK_MAXPACKETSIZE;
570 571
			dev_err(line6->ifcdev,
				"endpoint not available, using fallback values");
M
Markus Grabner 已提交
572 573 574 575 576
		}
	}

	usb_set_intfdata(interface, line6);

577
	if (properties->capabilities & LINE6_CAP_CONTROL) {
M
Markus Grabner 已提交
578
		/* initialize USB buffers: */
579 580
		line6->buffer_listen =
		    kmalloc(LINE6_BUFSIZE_LISTEN, GFP_KERNEL);
581
		if (line6->buffer_listen == NULL) {
582 583
			ret = -ENOMEM;
			goto err_destruct;
M
Markus Grabner 已提交
584 585
		}

586 587
		line6->buffer_message =
		    kmalloc(LINE6_MESSAGE_MAXLEN, GFP_KERNEL);
588
		if (line6->buffer_message == NULL) {
589 590
			ret = -ENOMEM;
			goto err_destruct;
M
Markus Grabner 已提交
591 592 593 594
		}

		line6->urb_listen = usb_alloc_urb(0, GFP_KERNEL);

595
		if (line6->urb_listen == NULL) {
M
Markus Grabner 已提交
596
			dev_err(&interface->dev, "Out of memory\n");
597 598
			ret = -ENOMEM;
			goto err_destruct;
M
Markus Grabner 已提交
599 600
		}

601 602 603 604
		ret = line6_start_listen(line6);
		if (ret < 0) {
			dev_err(&interface->dev, "%s: usb_submit_urb failed\n",
				__func__);
605
			goto err_destruct;
M
Markus Grabner 已提交
606 607 608
		}
	}

609
	/* initialize device data based on device: */
T
Takashi Iwai 已提交
610
	ret = private_init(interface, line6);
611 612
	if (ret < 0)
		goto err_destruct;
M
Markus Grabner 已提交
613

614 615
	/* creation of additional special files should go here */

616 617
	dev_info(&interface->dev, "Line6 %s now attached\n",
		 line6->properties->name);
618 619 620 621 622

	/* increment reference counters: */
	usb_get_intf(interface);
	usb_get_dev(usbdev);

623 624 625 626 627
	return 0;

err_destruct:
	line6_destruct(interface);
err_put:
M
Markus Grabner 已提交
628 629
	return ret;
}
T
Takashi Iwai 已提交
630
EXPORT_SYMBOL_GPL(line6_probe);
M
Markus Grabner 已提交
631 632 633 634

/*
	Line6 device disconnected.
*/
T
Takashi Iwai 已提交
635
void line6_disconnect(struct usb_interface *interface)
M
Markus Grabner 已提交
636 637 638
{
	struct usb_line6 *line6;
	struct usb_device *usbdev;
639
	int interface_number;
M
Markus Grabner 已提交
640

641 642
	if (interface == NULL)
		return;
M
Markus Grabner 已提交
643
	usbdev = interface_to_usbdev(interface);
644 645
	if (usbdev == NULL)
		return;
M
Markus Grabner 已提交
646 647 648 649

	interface_number = interface->cur_altsetting->desc.bInterfaceNumber;
	line6 = usb_get_intfdata(interface);

650 651
	if (line6 != NULL) {
		if (line6->urb_listen != NULL)
652
			line6_stop_listen(line6);
M
Markus Grabner 已提交
653

654 655 656
		if (usbdev != line6->usbdev)
			dev_err(line6->ifcdev,
				"driver bug: inconsistent usb device\n");
M
Markus Grabner 已提交
657

658
		line6->disconnect(interface);
M
Markus Grabner 已提交
659

660 661
		dev_info(&interface->dev, "Line6 %s now disconnected\n",
			 line6->properties->name);
M
Markus Grabner 已提交
662 663 664 665
	}

	line6_destruct(interface);

T
Takashi Iwai 已提交
666 667 668
	/* free interface data: */
	kfree(line6);

M
Markus Grabner 已提交
669 670 671
	/* decrement reference counters: */
	usb_put_intf(interface);
	usb_put_dev(usbdev);
672
}
T
Takashi Iwai 已提交
673
EXPORT_SYMBOL_GPL(line6_disconnect);
674 675 676 677 678 679

#ifdef CONFIG_PM

/*
	Suspend Line6 device.
*/
T
Takashi Iwai 已提交
680
int line6_suspend(struct usb_interface *interface, pm_message_t message)
681 682 683 684 685 686
{
	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);

687
	if (line6->properties->capabilities & LINE6_CAP_CONTROL)
688 689 690 691 692 693 694 695 696 697
		line6_stop_listen(line6);

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

	return 0;
}
T
Takashi Iwai 已提交
698
EXPORT_SYMBOL_GPL(line6_suspend);
699 700 701 702

/*
	Resume Line6 device.
*/
T
Takashi Iwai 已提交
703
int line6_resume(struct usb_interface *interface)
704 705 706
{
	struct usb_line6 *line6 = usb_get_intfdata(interface);

707
	if (line6->properties->capabilities & LINE6_CAP_CONTROL)
708 709 710 711 712
		line6_start_listen(line6);

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

715
#endif /* CONFIG_PM */
716

M
Markus Grabner 已提交
717 718 719 720
MODULE_AUTHOR(DRIVER_AUTHOR);
MODULE_DESCRIPTION(DRIVER_DESC);
MODULE_LICENSE("GPL");
MODULE_VERSION(DRIVER_VERSION);