blob: c8f723c3a0336905d02afc8d33a51031985430e6 [file] [log] [blame]
Markus Grabner705ecec2009-02-27 19:43:04 -08001/*
Chris Rorvickc078a4a2015-01-20 02:20:50 -06002 * Line 6 Linux USB driver
Markus Grabner705ecec2009-02-27 19:43:04 -08003 *
Markus Grabner1027f472010-08-12 01:35:30 +02004 * Copyright (C) 2004-2010 Markus Grabner (grabner@icg.tugraz.at)
Markus Grabner705ecec2009-02-27 19:43:04 -08005 *
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
Markus Grabner705ecec2009-02-27 19:43:04 -080012#include <linux/kernel.h>
13#include <linux/module.h>
Takashi Iwaiccddbe42015-01-15 08:22:31 +010014#include <linux/export.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090015#include <linux/slab.h>
Markus Grabner705ecec2009-02-27 19:43:04 -080016#include <linux/usb.h>
17
Takashi Iwai85a93392015-01-19 15:54:00 +010018#include <sound/core.h>
19#include <sound/initval.h>
Andrej Krutaka16039cb2016-09-18 20:59:32 +020020#include <sound/hwdep.h>
Takashi Iwai85a93392015-01-19 15:54:00 +010021
Markus Grabner705ecec2009-02-27 19:43:04 -080022#include "capture.h"
Markus Grabner1027f472010-08-12 01:35:30 +020023#include "driver.h"
Markus Grabner705ecec2009-02-27 19:43:04 -080024#include "midi.h"
25#include "playback.h"
Markus Grabner705ecec2009-02-27 19:43:04 -080026
Markus Grabner705ecec2009-02-27 19:43:04 -080027#define DRIVER_AUTHOR "Markus Grabner <grabner@icg.tugraz.at>"
Chris Rorvickc6fffce2015-01-20 02:20:49 -060028#define DRIVER_DESC "Line 6 USB Driver"
Markus Grabner705ecec2009-02-27 19:43:04 -080029
Markus Grabner705ecec2009-02-27 19:43:04 -080030/*
Chris Rorvickc6fffce2015-01-20 02:20:49 -060031 This is Line 6's MIDI manufacturer ID.
Markus Grabner705ecec2009-02-27 19:43:04 -080032*/
Takashi Sakamoto8da08ca2016-09-25 22:00:20 +090033const unsigned char line6_midi_id[3] = {
Markus Grabner1027f472010-08-12 01:35:30 +020034 0x00, 0x01, 0x0c
35};
Takashi Iwaiccddbe42015-01-15 08:22:31 +010036EXPORT_SYMBOL_GPL(line6_midi_id);
Markus Grabner1027f472010-08-12 01:35:30 +020037
38/*
39 Code to request version of POD, Variax interface
40 (and maybe other devices).
41*/
Greg Kroah-Hartmanc46b8a62012-04-23 16:09:56 -070042static const char line6_request_version[] = {
Markus Grabner1027f472010-08-12 01:35:30 +020043 0xf0, 0x7e, 0x7f, 0x06, 0x01, 0xf7
44};
45
Takashi Iwaicddbd4f2015-01-28 14:43:11 +010046/*
Markus Grabner705ecec2009-02-27 19:43:04 -080047 Class for asynchronous messages.
48*/
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -080049struct message {
Markus Grabner705ecec2009-02-27 19:43:04 -080050 struct usb_line6 *line6;
51 const char *buffer;
52 int size;
53 int done;
54};
55
Markus Grabner705ecec2009-02-27 19:43:04 -080056/*
57 Forward declarations.
58*/
Greg Kroah-Hartman0c7ab152009-02-27 20:28:04 -080059static void line6_data_received(struct urb *urb);
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -080060static int line6_send_raw_message_async_part(struct message *msg,
61 struct urb *urb);
Markus Grabner705ecec2009-02-27 19:43:04 -080062
Markus Grabner705ecec2009-02-27 19:43:04 -080063/*
64 Start to listen on endpoint.
65*/
66static int line6_start_listen(struct usb_line6 *line6)
67{
Markus Grabner1027f472010-08-12 01:35:30 +020068 int err;
Fabian Mewesa6b46992014-03-24 23:46:31 +010069
Andrej Krutak174e1fc2016-09-18 20:59:26 +020070 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);
80 }
Markus Grabner705ecec2009-02-27 19:43:04 -080081 line6->urb_listen->actual_length = 0;
Markus Grabnere1a164d2010-08-23 01:08:25 +020082 err = usb_submit_urb(line6->urb_listen, GFP_ATOMIC);
Markus Grabner1027f472010-08-12 01:35:30 +020083 return err;
Markus Grabner705ecec2009-02-27 19:43:04 -080084}
85
Markus Grabner1027f472010-08-12 01:35:30 +020086/*
87 Stop listening on endpoint.
88*/
89static void line6_stop_listen(struct usb_line6 *line6)
90{
91 usb_kill_urb(line6->urb_listen);
92}
93
Markus Grabner705ecec2009-02-27 19:43:04 -080094/*
Markus Grabner1027f472010-08-12 01:35:30 +020095 Send raw message in pieces of wMaxPacketSize bytes.
Markus Grabner705ecec2009-02-27 19:43:04 -080096*/
Takashi Iwai73723192015-01-19 16:36:21 +010097static int line6_send_raw_message(struct usb_line6 *line6, const char *buffer,
98 int size)
Markus Grabner705ecec2009-02-27 19:43:04 -080099{
100 int i, done = 0;
Andrej Krutak174e1fc2016-09-18 20:59:26 +0200101 const struct line6_properties *properties = line6->properties;
Markus Grabner705ecec2009-02-27 19:43:04 -0800102
Markus Grabner1027f472010-08-12 01:35:30 +0200103 for (i = 0; i < size; i += line6->max_packet_size) {
104 int partial;
Markus Grabner705ecec2009-02-27 19:43:04 -0800105 const char *frag_buf = buffer + i;
106 int frag_size = min(line6->max_packet_size, size - i);
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800107 int retval;
Markus Grabner705ecec2009-02-27 19:43:04 -0800108
Andrej Krutak174e1fc2016-09-18 20:59:26 +0200109 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);
119 }
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800120
121 if (retval) {
122 dev_err(line6->ifcdev,
Andrej Krutak174e1fc2016-09-18 20:59:26 +0200123 "usb_bulk_msg failed (%d)\n", retval);
Markus Grabner705ecec2009-02-27 19:43:04 -0800124 break;
125 }
126
Markus Grabner1027f472010-08-12 01:35:30 +0200127 done += frag_size;
Markus Grabner705ecec2009-02-27 19:43:04 -0800128 }
129
130 return done;
131}
132
133/*
134 Notification of completion of asynchronous request transmission.
135*/
Greg Kroah-Hartman0c7ab152009-02-27 20:28:04 -0800136static void line6_async_request_sent(struct urb *urb)
Markus Grabner705ecec2009-02-27 19:43:04 -0800137{
138 struct message *msg = (struct message *)urb->context;
139
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800140 if (msg->done >= msg->size) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800141 usb_free_urb(urb);
142 kfree(msg);
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800143 } else
Markus Grabner705ecec2009-02-27 19:43:04 -0800144 line6_send_raw_message_async_part(msg, urb);
145}
146
147/*
148 Asynchronously send part of a raw message.
149*/
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800150static int line6_send_raw_message_async_part(struct message *msg,
151 struct urb *urb)
Markus Grabner705ecec2009-02-27 19:43:04 -0800152{
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);
157
Andrej Krutak174e1fc2016-09-18 20:59:26 +0200158 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);
168 }
Markus Grabner705ecec2009-02-27 19:43:04 -0800169
Markus Grabner705ecec2009-02-27 19:43:04 -0800170 msg->done += bytes;
171 retval = usb_submit_urb(urb, GFP_ATOMIC);
172
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800173 if (retval < 0) {
174 dev_err(line6->ifcdev, "%s: usb_submit_urb failed (%d)\n",
175 __func__, retval);
Markus Grabner705ecec2009-02-27 19:43:04 -0800176 usb_free_urb(urb);
177 kfree(msg);
Ashvini Varatharaj056e0af2013-10-19 22:01:22 +0530178 return retval;
Markus Grabner705ecec2009-02-27 19:43:04 -0800179 }
180
181 return 0;
182}
183
184/*
Markus Grabner1027f472010-08-12 01:35:30 +0200185 Setup and start timer.
186*/
Nicholas Mc Guire6ccd93b2015-02-03 02:38:56 -0500187void line6_start_timer(struct timer_list *timer, unsigned long msecs,
Monam Agarwal1cad6082014-02-27 21:05:18 +0530188 void (*function)(unsigned long), unsigned long data)
Markus Grabner1027f472010-08-12 01:35:30 +0200189{
190 setup_timer(timer, function, data);
Nicholas Mc Guire695758c2015-02-03 02:38:39 -0500191 mod_timer(timer, jiffies + msecs_to_jiffies(msecs));
Markus Grabner1027f472010-08-12 01:35:30 +0200192}
Takashi Iwaiccddbe42015-01-15 08:22:31 +0100193EXPORT_SYMBOL_GPL(line6_start_timer);
Markus Grabner1027f472010-08-12 01:35:30 +0200194
195/*
Markus Grabner705ecec2009-02-27 19:43:04 -0800196 Asynchronously send raw message.
197*/
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800198int line6_send_raw_message_async(struct usb_line6 *line6, const char *buffer,
199 int size)
Markus Grabner705ecec2009-02-27 19:43:04 -0800200{
201 struct message *msg;
202 struct urb *urb;
203
204 /* create message: */
205 msg = kmalloc(sizeof(struct message), GFP_ATOMIC);
Joe Perches78110bb2013-02-11 09:41:29 -0800206 if (msg == NULL)
Markus Grabner705ecec2009-02-27 19:43:04 -0800207 return -ENOMEM;
Markus Grabner705ecec2009-02-27 19:43:04 -0800208
209 /* create URB: */
210 urb = usb_alloc_urb(0, GFP_ATOMIC);
211
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800212 if (urb == NULL) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800213 kfree(msg);
Markus Grabner705ecec2009-02-27 19:43:04 -0800214 return -ENOMEM;
215 }
216
217 /* set message data: */
218 msg->line6 = line6;
219 msg->buffer = buffer;
220 msg->size = size;
221 msg->done = 0;
222
223 /* start sending: */
224 return line6_send_raw_message_async_part(msg, urb);
225}
Takashi Iwaiccddbe42015-01-15 08:22:31 +0100226EXPORT_SYMBOL_GPL(line6_send_raw_message_async);
Markus Grabner705ecec2009-02-27 19:43:04 -0800227
228/*
Markus Grabner1027f472010-08-12 01:35:30 +0200229 Send asynchronous device version request.
230*/
231int line6_version_request_async(struct usb_line6 *line6)
232{
Greg Kroah-Hartmanc46b8a62012-04-23 16:09:56 -0700233 char *buffer;
234 int retval;
235
Laurent Navet77ecb6f2012-12-03 14:20:25 +0100236 buffer = kmemdup(line6_request_version,
237 sizeof(line6_request_version), GFP_ATOMIC);
Takashi Iwaia019f5e2015-01-19 15:05:10 +0100238 if (buffer == NULL)
Greg Kroah-Hartmanc46b8a62012-04-23 16:09:56 -0700239 return -ENOMEM;
Greg Kroah-Hartmanc46b8a62012-04-23 16:09:56 -0700240
Greg Kroah-Hartmanc46b8a62012-04-23 16:09:56 -0700241 retval = line6_send_raw_message_async(line6, buffer,
242 sizeof(line6_request_version));
243 kfree(buffer);
244 return retval;
Markus Grabner1027f472010-08-12 01:35:30 +0200245}
Takashi Iwaiccddbe42015-01-15 08:22:31 +0100246EXPORT_SYMBOL_GPL(line6_version_request_async);
Markus Grabner1027f472010-08-12 01:35:30 +0200247
248/*
Markus Grabner705ecec2009-02-27 19:43:04 -0800249 Send sysex message in pieces of wMaxPacketSize bytes.
250*/
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800251int line6_send_sysex_message(struct usb_line6 *line6, const char *buffer,
252 int size)
Markus Grabner705ecec2009-02-27 19:43:04 -0800253{
Markus Grabnere1a164d2010-08-23 01:08:25 +0200254 return line6_send_raw_message(line6, buffer,
255 size + SYSEX_EXTRA_SIZE) -
256 SYSEX_EXTRA_SIZE;
Markus Grabner705ecec2009-02-27 19:43:04 -0800257}
Takashi Iwaiccddbe42015-01-15 08:22:31 +0100258EXPORT_SYMBOL_GPL(line6_send_sysex_message);
Markus Grabner705ecec2009-02-27 19:43:04 -0800259
260/*
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
264*/
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800265char *line6_alloc_sysex_buffer(struct usb_line6 *line6, int code1, int code2,
266 int size)
Markus Grabner705ecec2009-02-27 19:43:04 -0800267{
Markus Grabner1027f472010-08-12 01:35:30 +0200268 char *buffer = kmalloc(size + SYSEX_EXTRA_SIZE, GFP_ATOMIC);
Markus Grabner705ecec2009-02-27 19:43:04 -0800269
Joe Perches78110bb2013-02-11 09:41:29 -0800270 if (!buffer)
Greg Kroah-Hartman536165d2009-02-27 20:49:46 -0800271 return NULL;
Markus Grabner705ecec2009-02-27 19:43:04 -0800272
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;
279}
Takashi Iwaiccddbe42015-01-15 08:22:31 +0100280EXPORT_SYMBOL_GPL(line6_alloc_sysex_buffer);
Markus Grabner705ecec2009-02-27 19:43:04 -0800281
282/*
Chris Rorvickc6fffce2015-01-20 02:20:49 -0600283 Notification of data received from the Line 6 device.
Markus Grabner705ecec2009-02-27 19:43:04 -0800284*/
Greg Kroah-Hartman0c7ab152009-02-27 20:28:04 -0800285static void line6_data_received(struct urb *urb)
Markus Grabner705ecec2009-02-27 19:43:04 -0800286{
287 struct usb_line6 *line6 = (struct usb_line6 *)urb->context;
Stefan Hajnoczi269edc82013-01-11 23:08:09 +0100288 struct midi_buffer *mb = &line6->line6midi->midibuf_in;
Markus Grabner705ecec2009-02-27 19:43:04 -0800289 int done;
290
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800291 if (urb->status == -ESHUTDOWN)
Markus Grabner705ecec2009-02-27 19:43:04 -0800292 return;
293
Andrej Krutak7811a3a2016-09-18 20:59:27 +0200294 if (line6->properties->capabilities & LINE6_CAP_CONTROL_MIDI) {
Markus Grabnere1a164d2010-08-23 01:08:25 +0200295 done =
Andrej Krutak7811a3a2016-09-18 20:59:27 +0200296 line6_midibuf_write(mb, urb->transfer_buffer, urb->actual_length);
Markus Grabner705ecec2009-02-27 19:43:04 -0800297
Andrej Krutak7811a3a2016-09-18 20:59:27 +0200298 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);
302 }
Markus Grabner705ecec2009-02-27 19:43:04 -0800303
Andrej Krutak7811a3a2016-09-18 20:59:27 +0200304 for (;;) {
305 done =
306 line6_midibuf_read(mb, line6->buffer_message,
Andrej Krutaka16039cb2016-09-18 20:59:32 +0200307 LINE6_MIDI_MESSAGE_MAXLEN);
Markus Grabner705ecec2009-02-27 19:43:04 -0800308
Andrej Krutak7811a3a2016-09-18 20:59:27 +0200309 if (done == 0)
310 break;
311
312 line6->message_length = done;
313 line6_midi_receive(line6, line6->buffer_message, done);
314
315 if (line6->process_message)
316 line6->process_message(line6);
317 }
318 } else {
Andrej Krutaka16039cb2016-09-18 20:59:32 +0200319 line6->buffer_message = urb->transfer_buffer;
320 line6->message_length = urb->actual_length;
Chris Rorvick01f6b2b2015-01-12 12:42:58 -0800321 if (line6->process_message)
322 line6->process_message(line6);
Andrej Krutaka16039cb2016-09-18 20:59:32 +0200323 line6->buffer_message = NULL;
Markus Grabner705ecec2009-02-27 19:43:04 -0800324 }
325
326 line6_start_listen(line6);
327}
328
Chris Rorvicke64e94d2015-02-10 23:03:13 -0600329#define LINE6_READ_WRITE_STATUS_DELAY 2 /* milliseconds */
Chris Rorvickf3dfd1b2015-02-10 23:03:14 -0600330#define LINE6_READ_WRITE_MAX_RETRIES 50
Chris Rorvicke64e94d2015-02-10 23:03:13 -0600331
Markus Grabner705ecec2009-02-27 19:43:04 -0800332/*
Markus Grabner705ecec2009-02-27 19:43:04 -0800333 Read data from device.
334*/
Chris Rorvick25a07072015-02-11 06:03:31 -0600335int line6_read_data(struct usb_line6 *line6, unsigned address, void *data,
336 unsigned datalen)
Markus Grabner705ecec2009-02-27 19:43:04 -0800337{
338 struct usb_device *usbdev = line6->usbdev;
339 int ret;
340 unsigned char len;
Chris Rorvickf3dfd1b2015-02-10 23:03:14 -0600341 unsigned count;
Markus Grabner705ecec2009-02-27 19:43:04 -0800342
Chris Rorvick25a07072015-02-11 06:03:31 -0600343 if (address > 0xffff || datalen > 0xff)
344 return -EINVAL;
345
Markus Grabner705ecec2009-02-27 19:43:04 -0800346 /* query the serial number: */
347 ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67,
Markus Grabner1027f472010-08-12 01:35:30 +0200348 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
349 (datalen << 8) | 0x21, address,
350 NULL, 0, LINE6_TIMEOUT * HZ);
Markus Grabner705ecec2009-02-27 19:43:04 -0800351
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800352 if (ret < 0) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800353 dev_err(line6->ifcdev, "read request failed (error %d)\n", ret);
354 return ret;
355 }
356
Stefan Hajnoczibc776f22013-01-11 23:08:10 +0100357 /* Wait for data length. We'll get 0xff until length arrives. */
Chris Rorvickf3dfd1b2015-02-10 23:03:14 -0600358 for (count = 0; count < LINE6_READ_WRITE_MAX_RETRIES; count++) {
Chris Rorvicke64e94d2015-02-10 23:03:13 -0600359 mdelay(LINE6_READ_WRITE_STATUS_DELAY);
360
Markus Grabner705ecec2009-02-27 19:43:04 -0800361 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800362 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);
Markus Grabner705ecec2009-02-27 19:43:04 -0800369 return ret;
370 }
Markus Grabner705ecec2009-02-27 19:43:04 -0800371
Chris Rorvickf3dfd1b2015-02-10 23:03:14 -0600372 if (len != 0xff)
373 break;
374 }
375
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) {
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800381 /* 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);
Chris Rorvicke474e7f2015-02-10 23:03:15 -0600385 return -EIO;
Markus Grabner705ecec2009-02-27 19:43:04 -0800386 }
387
388 /* receive the result: */
389 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800390 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
391 0x0013, 0x0000, data, datalen,
392 LINE6_TIMEOUT * HZ);
Markus Grabner705ecec2009-02-27 19:43:04 -0800393
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800394 if (ret < 0) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800395 dev_err(line6->ifcdev, "read failed (error %d)\n", ret);
396 return ret;
397 }
398
399 return 0;
400}
Takashi Iwaiccddbe42015-01-15 08:22:31 +0100401EXPORT_SYMBOL_GPL(line6_read_data);
Markus Grabner705ecec2009-02-27 19:43:04 -0800402
403/*
404 Write data to device.
405*/
Chris Rorvick25a07072015-02-11 06:03:31 -0600406int line6_write_data(struct usb_line6 *line6, unsigned address, void *data,
407 unsigned datalen)
Markus Grabner705ecec2009-02-27 19:43:04 -0800408{
409 struct usb_device *usbdev = line6->usbdev;
410 int ret;
411 unsigned char status;
Chris Rorvickf3dfd1b2015-02-10 23:03:14 -0600412 int count;
Markus Grabner705ecec2009-02-27 19:43:04 -0800413
Chris Rorvick25a07072015-02-11 06:03:31 -0600414 if (address > 0xffff || datalen > 0xffff)
415 return -EINVAL;
416
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800417 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);
Markus Grabner705ecec2009-02-27 19:43:04 -0800421
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800422 if (ret < 0) {
423 dev_err(line6->ifcdev,
424 "write request failed (error %d)\n", ret);
Markus Grabner705ecec2009-02-27 19:43:04 -0800425 return ret;
426 }
427
Chris Rorvickf3dfd1b2015-02-10 23:03:14 -0600428 for (count = 0; count < LINE6_READ_WRITE_MAX_RETRIES; count++) {
Chris Rorvicke64e94d2015-02-10 23:03:13 -0600429 mdelay(LINE6_READ_WRITE_STATUS_DELAY);
430
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800431 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);
Markus Grabner705ecec2009-02-27 19:43:04 -0800437
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800438 if (ret < 0) {
439 dev_err(line6->ifcdev,
440 "receiving status failed (error %d)\n", ret);
Markus Grabner705ecec2009-02-27 19:43:04 -0800441 return ret;
442 }
Markus Grabner705ecec2009-02-27 19:43:04 -0800443
Chris Rorvickf3dfd1b2015-02-10 23:03:14 -0600444 if (status != 0xff)
445 break;
446 }
447
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) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800453 dev_err(line6->ifcdev, "write failed (error %d)\n", ret);
Chris Rorvicke474e7f2015-02-10 23:03:15 -0600454 return -EIO;
Markus Grabner705ecec2009-02-27 19:43:04 -0800455 }
456
457 return 0;
458}
Takashi Iwaiccddbe42015-01-15 08:22:31 +0100459EXPORT_SYMBOL_GPL(line6_write_data);
Markus Grabner705ecec2009-02-27 19:43:04 -0800460
461/*
Chris Rorvickc6fffce2015-01-20 02:20:49 -0600462 Read Line 6 device serial number.
Markus Grabner705ecec2009-02-27 19:43:04 -0800463 (POD, TonePort, GuitarPort)
464*/
Chris Rorvick12b00152015-02-10 23:03:16 -0600465int line6_read_serial_number(struct usb_line6 *line6, u32 *serial_number)
Markus Grabner705ecec2009-02-27 19:43:04 -0800466{
Markus Grabnere1a164d2010-08-23 01:08:25 +0200467 return line6_read_data(line6, 0x80d0, serial_number,
468 sizeof(*serial_number));
Markus Grabner705ecec2009-02-27 19:43:04 -0800469}
Takashi Iwaiccddbe42015-01-15 08:22:31 +0100470EXPORT_SYMBOL_GPL(line6_read_serial_number);
Markus Grabner705ecec2009-02-27 19:43:04 -0800471
472/*
Takashi Iwai85a93392015-01-19 15:54:00 +0100473 Card destructor.
Markus Grabner705ecec2009-02-27 19:43:04 -0800474*/
Takashi Iwai85a93392015-01-19 15:54:00 +0100475static void line6_destruct(struct snd_card *card)
Markus Grabner705ecec2009-02-27 19:43:04 -0800476{
Takashi Iwai85a93392015-01-19 15:54:00 +0100477 struct usb_line6 *line6 = card->private_data;
Takashi Iwaiaca514b2015-01-25 18:36:29 +0100478 struct usb_device *usbdev = line6->usbdev;
Markus Grabner705ecec2009-02-27 19:43:04 -0800479
Andrej Krutaka16039cb2016-09-18 20:59:32 +0200480 /* 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
482 */
kbuild test robota4bc7462016-09-20 08:10:13 +0800483 kfree(line6->buffer_message);
Andrej Krutak7811a3a2016-09-18 20:59:27 +0200484
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800485 kfree(line6->buffer_listen);
Markus Grabner705ecec2009-02-27 19:43:04 -0800486
487 /* then free URBs: */
Greg Kroah-Hartman36445bc2009-02-27 22:42:18 -0800488 usb_free_urb(line6->urb_listen);
Andrej Krutaka16039cb2016-09-18 20:59:32 +0200489 line6->urb_listen = NULL;
Markus Grabner705ecec2009-02-27 19:43:04 -0800490
Takashi Iwai85a93392015-01-19 15:54:00 +0100491 /* decrement reference counters: */
492 usb_put_dev(usbdev);
Markus Grabner705ecec2009-02-27 19:43:04 -0800493}
494
Andrej Krutak5d812962017-02-06 20:34:58 +0100495static void line6_get_usb_properties(struct usb_line6 *line6)
Takashi Iwai644d9082015-01-23 12:24:03 +0100496{
497 struct usb_device *usbdev = line6->usbdev;
Andrej Krutak174e1fc2016-09-18 20:59:26 +0200498 const struct line6_properties *properties = line6->properties;
499 int pipe;
Andrej Krutak5d812962017-02-06 20:34:58 +0100500 struct usb_host_endpoint *ep = NULL;
Andrej Krutak174e1fc2016-09-18 20:59:26 +0200501
Andrej Krutak5d812962017-02-06 20:34:58 +0100502 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);
509 }
510 ep = usbdev->ep_in[usb_pipeendpoint(pipe)];
Andrej Krutak174e1fc2016-09-18 20:59:26 +0200511 }
Takashi Iwai644d9082015-01-23 12:24:03 +0100512
Andrej Krutak5d812962017-02-06 20:34:58 +0100513 /* Control data transfer properties */
Takashi Iwai644d9082015-01-23 12:24:03 +0100514 if (ep) {
515 line6->interval = ep->desc.bInterval;
516 line6->max_packet_size = le16_to_cpu(ep->desc.wMaxPacketSize);
517 } else {
Andrej Krutak5d812962017-02-06 20:34:58 +0100518 if (properties->capabilities & LINE6_CAP_CONTROL) {
519 dev_err(line6->ifcdev,
520 "endpoint not available, using fallback values");
521 }
Takashi Iwai644d9082015-01-23 12:24:03 +0100522 line6->interval = LINE6_FALLBACK_INTERVAL;
523 line6->max_packet_size = LINE6_FALLBACK_MAXPACKETSIZE;
524 }
Takashi Iwai644d9082015-01-23 12:24:03 +0100525
Andrej Krutak5d812962017-02-06 20:34:58 +0100526 /* 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;
533 }
534}
Andrej Krutaka16039cb2016-09-18 20:59:32 +0200535
536/* Enable buffering of incoming messages, flush the buffer */
537static int line6_hwdep_open(struct snd_hwdep *hw, struct file *file)
538{
539 struct usb_line6 *line6 = hw->private_data;
540
541 /* NOTE: hwdep layer provides atomicity here */
542
543 line6->messages.active = 1;
544
545 return 0;
546}
547
548/* Stop buffering */
549static int line6_hwdep_release(struct snd_hwdep *hw, struct file *file)
550{
551 struct usb_line6 *line6 = hw->private_data;
552
553 line6->messages.active = 0;
554
555 return 0;
556}
557
558/* Read from circular buffer, return to user */
559static long
560line6_hwdep_read(struct snd_hwdep *hwdep, char __user *buf, long count,
561 loff_t *offset)
562{
563 struct usb_line6 *line6 = hwdep->private_data;
564 long rv = 0;
565 unsigned int out_count;
566
567 if (mutex_lock_interruptible(&line6->messages.read_lock))
568 return -ERESTARTSYS;
569
570 while (kfifo_len(&line6->messages.fifo) == 0) {
571 mutex_unlock(&line6->messages.read_lock);
572
573 rv = wait_event_interruptible(
574 line6->messages.wait_queue,
575 kfifo_len(&line6->messages.fifo) != 0);
576 if (rv < 0)
577 return rv;
578
579 if (mutex_lock_interruptible(&line6->messages.read_lock))
580 return -ERESTARTSYS;
581 }
582
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;
590 }
591
592 mutex_unlock(&line6->messages.read_lock);
593 return rv;
594}
595
596/* Write directly (no buffering) to device by user*/
597static long
598line6_hwdep_write(struct snd_hwdep *hwdep, const char __user *data, long count,
599 loff_t *offset)
600{
601 struct usb_line6 *line6 = hwdep->private_data;
602 int rv;
603 char *data_copy;
604
605 if (count > line6->max_packet_size * LINE6_RAW_MESSAGES_MAXCOUNT) {
606 /* This is an arbitrary limit - still better than nothing... */
607 return -EINVAL;
608 }
609
610 data_copy = memdup_user(data, count);
Dan Carpenterfdd82182016-10-12 09:21:40 +0300611 if (IS_ERR(data_copy))
612 return PTR_ERR(data_copy);
Andrej Krutaka16039cb2016-09-18 20:59:32 +0200613
614 rv = line6_send_raw_message(line6, data_copy, count);
615
616 kfree(data_copy);
617 return rv;
618}
619
620static 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,
625};
626
627/* Insert into circular buffer */
628static void line6_hwdep_push_message(struct usb_line6 *line6)
629{
630 if (!line6->messages.active)
631 return;
632
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 */
638
639 wake_up_interruptible(&line6->messages.wait_queue);
640}
641
642static int line6_hwdep_init(struct usb_line6 *line6)
643{
644 int err;
645 struct snd_hwdep *hwdep;
646
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);
653
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;
662
663end:
664 return err;
665}
666
Andrej Krutak7811a3a2016-09-18 20:59:27 +0200667static int line6_init_cap_control(struct usb_line6 *line6)
Takashi Iwai644d9082015-01-23 12:24:03 +0100668{
669 int ret;
670
671 /* initialize USB buffers: */
672 line6->buffer_listen = kmalloc(LINE6_BUFSIZE_LISTEN, GFP_KERNEL);
673 if (!line6->buffer_listen)
674 return -ENOMEM;
675
Takashi Iwai644d9082015-01-23 12:24:03 +0100676 line6->urb_listen = usb_alloc_urb(0, GFP_KERNEL);
677 if (!line6->urb_listen)
678 return -ENOMEM;
679
Andrej Krutak7811a3a2016-09-18 20:59:27 +0200680 if (line6->properties->capabilities & LINE6_CAP_CONTROL_MIDI) {
Andrej Krutaka16039cb2016-09-18 20:59:32 +0200681 line6->buffer_message = kmalloc(LINE6_MIDI_MESSAGE_MAXLEN, GFP_KERNEL);
Andrej Krutak7811a3a2016-09-18 20:59:27 +0200682 if (!line6->buffer_message)
683 return -ENOMEM;
Andrej Krutaka16039cb2016-09-18 20:59:32 +0200684 } else {
685 ret = line6_hwdep_init(line6);
686 if (ret < 0)
687 return ret;
Andrej Krutak7811a3a2016-09-18 20:59:27 +0200688 }
689
Takashi Iwai644d9082015-01-23 12:24:03 +0100690 ret = line6_start_listen(line6);
691 if (ret < 0) {
692 dev_err(line6->ifcdev, "cannot start listening: %d\n", ret);
693 return ret;
694 }
695
696 return 0;
697}
698
Markus Grabner705ecec2009-02-27 19:43:04 -0800699/*
700 Probe USB device.
701*/
Takashi Iwaiccddbe42015-01-15 08:22:31 +0100702int line6_probe(struct usb_interface *interface,
Takashi Iwaif66fd992015-01-25 18:22:58 +0100703 const struct usb_device_id *id,
Chris Rorvick12865ca2015-02-07 10:43:19 -0600704 const char *driver_name,
Takashi Iwaiccddbe42015-01-15 08:22:31 +0100705 const struct line6_properties *properties,
Takashi Iwaiaca514b2015-01-25 18:36:29 +0100706 int (*private_init)(struct usb_line6 *, const struct usb_device_id *id),
707 size_t data_size)
Markus Grabner705ecec2009-02-27 19:43:04 -0800708{
Chris Rorvick35ae48a2015-01-20 02:20:48 -0600709 struct usb_device *usbdev = interface_to_usbdev(interface);
Takashi Iwai85a93392015-01-19 15:54:00 +0100710 struct snd_card *card;
Takashi Iwaiaca514b2015-01-25 18:36:29 +0100711 struct usb_line6 *line6;
Chris Rorvick7b9584f2015-01-12 12:42:52 -0800712 int interface_number;
Markus Grabner705ecec2009-02-27 19:43:04 -0800713 int ret;
714
Takashi Iwaiaca514b2015-01-25 18:36:29 +0100715 if (WARN_ON(data_size < sizeof(*line6)))
716 return -EINVAL;
717
Takashi Iwaid6ca69d2015-01-25 18:41:26 +0100718 /* we don't handle multiple configurations */
719 if (usbdev->descriptor.bNumConfigurations != 1)
720 return -ENODEV;
721
Takashi Iwai6b562f62015-01-23 12:27:39 +0100722 ret = snd_card_new(&interface->dev,
723 SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
Takashi Iwaiaca514b2015-01-25 18:36:29 +0100724 THIS_MODULE, data_size, &card);
725 if (ret < 0)
Takashi Iwai6b562f62015-01-23 12:27:39 +0100726 return ret;
Markus Grabner705ecec2009-02-27 19:43:04 -0800727
Markus Grabner705ecec2009-02-27 19:43:04 -0800728 /* store basic data: */
Takashi Iwaiaca514b2015-01-25 18:36:29 +0100729 line6 = card->private_data;
Takashi Iwai6b562f62015-01-23 12:27:39 +0100730 line6->card = card;
Markus Grabner705ecec2009-02-27 19:43:04 -0800731 line6->properties = properties;
732 line6->usbdev = usbdev;
733 line6->ifcdev = &interface->dev;
Markus Grabner705ecec2009-02-27 19:43:04 -0800734
Takashi Iwaid6ca69d2015-01-25 18:41:26 +0100735 strcpy(card->id, properties->id);
Chris Rorvick12865ca2015-02-07 10:43:19 -0600736 strcpy(card->driver, driver_name);
Takashi Iwaid6ca69d2015-01-25 18:41:26 +0100737 strcpy(card->shortname, properties->name);
738 sprintf(card->longname, "Line 6 %s at USB %s", properties->name,
Takashi Iwai85a93392015-01-19 15:54:00 +0100739 dev_name(line6->ifcdev));
Takashi Iwai85a93392015-01-19 15:54:00 +0100740 card->private_free = line6_destruct;
741
Markus Grabner705ecec2009-02-27 19:43:04 -0800742 usb_set_intfdata(interface, line6);
743
Takashi Iwai85a93392015-01-19 15:54:00 +0100744 /* increment reference counters: */
745 usb_get_dev(usbdev);
746
Takashi Iwai6b562f62015-01-23 12:27:39 +0100747 /* initialize device info: */
748 dev_info(&interface->dev, "Line 6 %s found\n", properties->name);
749
750 /* query interface number */
751 interface_number = interface->cur_altsetting->desc.bInterfaceNumber;
752
Andrej Krutak79faa2b2016-09-18 20:59:22 +0200753 /* TODO reserves the bus bandwidth even without actual transfer */
Takashi Iwai6b562f62015-01-23 12:27:39 +0100754 ret = usb_set_interface(usbdev, interface_number,
Takashi Iwaid6ca69d2015-01-25 18:41:26 +0100755 properties->altsetting);
Takashi Iwai6b562f62015-01-23 12:27:39 +0100756 if (ret < 0) {
757 dev_err(&interface->dev, "set_interface failed\n");
758 goto error;
759 }
760
Andrej Krutak5d812962017-02-06 20:34:58 +0100761 line6_get_usb_properties(line6);
Takashi Iwaif3d83312017-02-07 09:32:30 +0100762
Andrej Krutak7811a3a2016-09-18 20:59:27 +0200763 if (properties->capabilities & LINE6_CAP_CONTROL) {
764 ret = line6_init_cap_control(line6);
Takashi Iwai644d9082015-01-23 12:24:03 +0100765 if (ret < 0)
Takashi Iwai6b562f62015-01-23 12:27:39 +0100766 goto error;
Markus Grabner705ecec2009-02-27 19:43:04 -0800767 }
768
Chris Rorvicka23a8bf2015-01-12 12:42:42 -0800769 /* initialize device data based on device: */
Takashi Iwaif66fd992015-01-25 18:22:58 +0100770 ret = private_init(line6, id);
Kulikov Vasiliyab366c12010-07-13 15:22:46 +0400771 if (ret < 0)
Takashi Iwai6b562f62015-01-23 12:27:39 +0100772 goto error;
Markus Grabner705ecec2009-02-27 19:43:04 -0800773
Markus Grabner1027f472010-08-12 01:35:30 +0200774 /* creation of additional special files should go here */
775
Chris Rorvickc6fffce2015-01-20 02:20:49 -0600776 dev_info(&interface->dev, "Line 6 %s now attached\n",
Takashi Iwaid6ca69d2015-01-25 18:41:26 +0100777 properties->name);
Markus Grabner1027f472010-08-12 01:35:30 +0200778
Kulikov Vasiliyab366c12010-07-13 15:22:46 +0400779 return 0;
780
Takashi Iwai6b562f62015-01-23 12:27:39 +0100781 error:
Takashi Iwaic95072b2017-10-09 14:51:23 +0200782 /* we can call disconnect callback here because no close-sync is
783 * needed yet at this point
784 */
785 line6_disconnect(interface);
Markus Grabner705ecec2009-02-27 19:43:04 -0800786 return ret;
787}
Takashi Iwaiccddbe42015-01-15 08:22:31 +0100788EXPORT_SYMBOL_GPL(line6_probe);
Markus Grabner705ecec2009-02-27 19:43:04 -0800789
790/*
Chris Rorvickc6fffce2015-01-20 02:20:49 -0600791 Line 6 device disconnected.
Markus Grabner705ecec2009-02-27 19:43:04 -0800792*/
Takashi Iwaiccddbe42015-01-15 08:22:31 +0100793void line6_disconnect(struct usb_interface *interface)
Markus Grabner705ecec2009-02-27 19:43:04 -0800794{
Takashi Iwai270fd9c2015-01-20 08:40:51 +0100795 struct usb_line6 *line6 = usb_get_intfdata(interface);
796 struct usb_device *usbdev = interface_to_usbdev(interface);
Markus Grabner705ecec2009-02-27 19:43:04 -0800797
Takashi Iwai85a93392015-01-19 15:54:00 +0100798 if (!line6)
799 return;
Markus Grabner705ecec2009-02-27 19:43:04 -0800800
Takashi Iwai2a324fc2015-01-20 09:58:54 +0100801 if (WARN_ON(usbdev != line6->usbdev))
802 return;
803
Takashi Iwai85a93392015-01-19 15:54:00 +0100804 if (line6->urb_listen != NULL)
805 line6_stop_listen(line6);
Markus Grabner705ecec2009-02-27 19:43:04 -0800806
Takashi Iwai85a93392015-01-19 15:54:00 +0100807 snd_card_disconnect(line6->card);
Takashi Iwai5a475312015-01-19 16:15:54 +0100808 if (line6->line6pcm)
809 line6_pcm_disconnect(line6->line6pcm);
Takashi Iwai85a93392015-01-19 15:54:00 +0100810 if (line6->disconnect)
Takashi Iwaif66fd992015-01-25 18:22:58 +0100811 line6->disconnect(line6);
Markus Grabner705ecec2009-02-27 19:43:04 -0800812
Chris Rorvickc6fffce2015-01-20 02:20:49 -0600813 dev_info(&interface->dev, "Line 6 %s now disconnected\n",
Takashi Iwai85a93392015-01-19 15:54:00 +0100814 line6->properties->name);
Markus Grabner705ecec2009-02-27 19:43:04 -0800815
Takashi Iwai85a93392015-01-19 15:54:00 +0100816 /* make sure the device isn't destructed twice: */
817 usb_set_intfdata(interface, NULL);
Markus Grabner705ecec2009-02-27 19:43:04 -0800818
Takashi Iwai85a93392015-01-19 15:54:00 +0100819 snd_card_free_when_closed(line6->card);
Markus Grabner705ecec2009-02-27 19:43:04 -0800820}
Takashi Iwaiccddbe42015-01-15 08:22:31 +0100821EXPORT_SYMBOL_GPL(line6_disconnect);
Markus Grabner705ecec2009-02-27 19:43:04 -0800822
Markus Grabner1027f472010-08-12 01:35:30 +0200823#ifdef CONFIG_PM
824
825/*
Chris Rorvickc6fffce2015-01-20 02:20:49 -0600826 Suspend Line 6 device.
Markus Grabner1027f472010-08-12 01:35:30 +0200827*/
Takashi Iwaiccddbe42015-01-15 08:22:31 +0100828int line6_suspend(struct usb_interface *interface, pm_message_t message)
Markus Grabner1027f472010-08-12 01:35:30 +0200829{
830 struct usb_line6 *line6 = usb_get_intfdata(interface);
831 struct snd_line6_pcm *line6pcm = line6->line6pcm;
832
833 snd_power_change_state(line6->card, SNDRV_CTL_POWER_D3hot);
834
Andrej Krutak7811a3a2016-09-18 20:59:27 +0200835 if (line6->properties->capabilities & LINE6_CAP_CONTROL)
Markus Grabner1027f472010-08-12 01:35:30 +0200836 line6_stop_listen(line6);
837
838 if (line6pcm != NULL) {
839 snd_pcm_suspend_all(line6pcm->pcm);
Markus Grabner1027f472010-08-12 01:35:30 +0200840 line6pcm->flags = 0;
841 }
842
843 return 0;
844}
Takashi Iwaiccddbe42015-01-15 08:22:31 +0100845EXPORT_SYMBOL_GPL(line6_suspend);
Markus Grabner1027f472010-08-12 01:35:30 +0200846
847/*
Chris Rorvickc6fffce2015-01-20 02:20:49 -0600848 Resume Line 6 device.
Markus Grabner1027f472010-08-12 01:35:30 +0200849*/
Takashi Iwaiccddbe42015-01-15 08:22:31 +0100850int line6_resume(struct usb_interface *interface)
Markus Grabner1027f472010-08-12 01:35:30 +0200851{
852 struct usb_line6 *line6 = usb_get_intfdata(interface);
853
Andrej Krutak7811a3a2016-09-18 20:59:27 +0200854 if (line6->properties->capabilities & LINE6_CAP_CONTROL)
Markus Grabner1027f472010-08-12 01:35:30 +0200855 line6_start_listen(line6);
856
857 snd_power_change_state(line6->card, SNDRV_CTL_POWER_D0);
858 return 0;
859}
Takashi Iwaiccddbe42015-01-15 08:22:31 +0100860EXPORT_SYMBOL_GPL(line6_resume);
Markus Grabner1027f472010-08-12 01:35:30 +0200861
Markus Grabnere1a164d2010-08-23 01:08:25 +0200862#endif /* CONFIG_PM */
Markus Grabner1027f472010-08-12 01:35:30 +0200863
Markus Grabner705ecec2009-02-27 19:43:04 -0800864MODULE_AUTHOR(DRIVER_AUTHOR);
865MODULE_DESCRIPTION(DRIVER_DESC);
866MODULE_LICENSE("GPL");
Andrej Krutaka16039cb2016-09-18 20:59:32 +0200867