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