Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1 | /* |
Chris Rorvick | c078a4a | 2015-01-20 02:20:50 -0600 | [diff] [blame] | 2 | * Line 6 Linux USB driver |
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 | |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 12 | #include <linux/slab.h> |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 13 | #include <linux/wait.h> |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 14 | #include <linux/interrupt.h> |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/usb.h> |
| 17 | |
| 18 | #include <sound/core.h> |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 19 | #include <sound/control.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 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 "playback.h" |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 24 | #include "usbdefs.h" |
| 25 | |
| 26 | /* |
| 27 | Locate name in binary program dump |
| 28 | */ |
| 29 | #define POD_NAME_OFFSET 0 |
| 30 | #define POD_NAME_LENGTH 16 |
| 31 | |
| 32 | /* |
| 33 | Other constants |
| 34 | */ |
| 35 | #define POD_CONTROL_SIZE 0x80 |
| 36 | #define POD_BUFSIZE_DUMPREQ 7 |
| 37 | #define POD_STARTUP_DELAY 1000 |
| 38 | |
| 39 | /* |
| 40 | Stages of POD startup procedure |
| 41 | */ |
| 42 | enum { |
| 43 | POD_STARTUP_INIT = 1, |
| 44 | POD_STARTUP_VERSIONREQ, |
| 45 | POD_STARTUP_WORKQUEUE, |
| 46 | POD_STARTUP_SETUP, |
| 47 | POD_STARTUP_LAST = POD_STARTUP_SETUP - 1 |
| 48 | }; |
| 49 | |
| 50 | enum { |
| 51 | LINE6_BASSPODXT, |
| 52 | LINE6_BASSPODXTLIVE, |
| 53 | LINE6_BASSPODXTPRO, |
| 54 | LINE6_POCKETPOD, |
| 55 | LINE6_PODXT, |
| 56 | LINE6_PODXTLIVE_POD, |
| 57 | LINE6_PODXTPRO, |
| 58 | }; |
| 59 | |
| 60 | struct usb_line6_pod { |
| 61 | /** |
Chris Rorvick | c6fffce | 2015-01-20 02:20:49 -0600 | [diff] [blame] | 62 | Generic Line 6 USB data. |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 63 | */ |
| 64 | struct usb_line6 line6; |
| 65 | |
| 66 | /** |
| 67 | Instrument monitor level. |
| 68 | */ |
| 69 | int monitor_level; |
| 70 | |
| 71 | /** |
| 72 | Timer for device initializaton. |
| 73 | */ |
| 74 | struct timer_list startup_timer; |
| 75 | |
| 76 | /** |
| 77 | Work handler for device initializaton. |
| 78 | */ |
| 79 | struct work_struct startup_work; |
| 80 | |
| 81 | /** |
| 82 | Current progress in startup procedure. |
| 83 | */ |
| 84 | int startup_progress; |
| 85 | |
| 86 | /** |
| 87 | Serial number of device. |
| 88 | */ |
| 89 | int serial_number; |
| 90 | |
| 91 | /** |
| 92 | Firmware version (x 100). |
| 93 | */ |
| 94 | int firmware_version; |
| 95 | |
| 96 | /** |
| 97 | Device ID. |
| 98 | */ |
| 99 | int device_id; |
| 100 | }; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 101 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 102 | #define POD_SYSEX_CODE 3 |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 103 | #define POD_BYTES_PER_FRAME 6 /* 24bit audio (stereo) */ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 104 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 105 | /* *INDENT-OFF* */ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 106 | |
| 107 | enum { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 108 | POD_SYSEX_SAVE = 0x24, |
| 109 | POD_SYSEX_SYSTEM = 0x56, |
| 110 | POD_SYSEX_SYSTEMREQ = 0x57, |
| 111 | /* POD_SYSEX_UPDATE = 0x6c, */ /* software update! */ |
| 112 | POD_SYSEX_STORE = 0x71, |
| 113 | POD_SYSEX_FINISH = 0x72, |
| 114 | POD_SYSEX_DUMPMEM = 0x73, |
| 115 | POD_SYSEX_DUMP = 0x74, |
| 116 | POD_SYSEX_DUMPREQ = 0x75 |
Stefan Hajnoczi | 0a1eb4e | 2013-01-11 23:08:12 +0100 | [diff] [blame] | 117 | |
| 118 | /* dumps entire internal memory of PODxt Pro */ |
| 119 | /* POD_SYSEX_DUMPMEM2 = 0x76 */ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 120 | }; |
| 121 | |
| 122 | enum { |
Stefan Hajnoczi | 7936095 | 2013-01-11 23:08:14 +0100 | [diff] [blame] | 123 | POD_MONITOR_LEVEL = 0x04, |
| 124 | POD_SYSTEM_INVALID = 0x10000 |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 125 | }; |
| 126 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 127 | /* *INDENT-ON* */ |
| 128 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 129 | enum { |
| 130 | POD_DUMP_MEMORY = 2 |
| 131 | }; |
| 132 | |
| 133 | enum { |
| 134 | POD_BUSY_READ, |
| 135 | POD_BUSY_WRITE, |
| 136 | POD_CHANNEL_DIRTY, |
| 137 | POD_SAVE_PRESSED, |
| 138 | POD_BUSY_MIDISEND |
| 139 | }; |
| 140 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 141 | static struct snd_ratden pod_ratden = { |
| 142 | .num_min = 78125, |
| 143 | .num_max = 78125, |
| 144 | .num_step = 1, |
| 145 | .den = 2 |
| 146 | }; |
| 147 | |
| 148 | static struct line6_pcm_properties pod_pcm_properties = { |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 149 | .snd_line6_playback_hw = { |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 150 | .info = (SNDRV_PCM_INFO_MMAP | |
| 151 | SNDRV_PCM_INFO_INTERLEAVED | |
| 152 | SNDRV_PCM_INFO_BLOCK_TRANSFER | |
| 153 | SNDRV_PCM_INFO_MMAP_VALID | |
| 154 | SNDRV_PCM_INFO_PAUSE | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 155 | SNDRV_PCM_INFO_SYNC_START), |
| 156 | .formats = SNDRV_PCM_FMTBIT_S24_3LE, |
| 157 | .rates = SNDRV_PCM_RATE_KNOT, |
| 158 | .rate_min = 39062, |
| 159 | .rate_max = 39063, |
| 160 | .channels_min = 2, |
| 161 | .channels_max = 2, |
| 162 | .buffer_bytes_max = 60000, |
| 163 | .period_bytes_min = 64, |
| 164 | .period_bytes_max = 8192, |
| 165 | .periods_min = 1, |
| 166 | .periods_max = 1024}, |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 167 | .snd_line6_capture_hw = { |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 168 | .info = (SNDRV_PCM_INFO_MMAP | |
| 169 | SNDRV_PCM_INFO_INTERLEAVED | |
| 170 | SNDRV_PCM_INFO_BLOCK_TRANSFER | |
| 171 | SNDRV_PCM_INFO_MMAP_VALID | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 172 | SNDRV_PCM_INFO_SYNC_START), |
| 173 | .formats = SNDRV_PCM_FMTBIT_S24_3LE, |
| 174 | .rates = SNDRV_PCM_RATE_KNOT, |
| 175 | .rate_min = 39062, |
| 176 | .rate_max = 39063, |
| 177 | .channels_min = 2, |
| 178 | .channels_max = 2, |
| 179 | .buffer_bytes_max = 60000, |
| 180 | .period_bytes_min = 64, |
| 181 | .period_bytes_max = 8192, |
| 182 | .periods_min = 1, |
| 183 | .periods_max = 1024}, |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 184 | .snd_line6_rates = { |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 185 | .nrats = 1, |
| 186 | .rats = &pod_ratden}, |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 187 | .bytes_per_frame = POD_BYTES_PER_FRAME |
| 188 | }; |
| 189 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 190 | static const char pod_version_header[] = { |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 191 | 0xf2, 0x7e, 0x7f, 0x06, 0x02 |
| 192 | }; |
| 193 | |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 194 | /* forward declarations: */ |
| 195 | static void pod_startup2(unsigned long data); |
| 196 | static void pod_startup3(struct usb_line6_pod *pod); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 197 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 198 | static char *pod_alloc_sysex_buffer(struct usb_line6_pod *pod, int code, |
| 199 | int size) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 200 | { |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 201 | return line6_alloc_sysex_buffer(&pod->line6, POD_SYSEX_CODE, code, |
| 202 | size); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | /* |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 206 | Process a completely received message. |
| 207 | */ |
Chris Rorvick | 01f6b2b | 2015-01-12 12:42:58 -0800 | [diff] [blame] | 208 | static void line6_pod_process_message(struct usb_line6 *line6) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 209 | { |
Chris Rorvick | 1cad3e8 | 2015-01-12 12:42:57 -0800 | [diff] [blame] | 210 | struct usb_line6_pod *pod = (struct usb_line6_pod *) line6; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 211 | const unsigned char *buf = pod->line6.buffer_message; |
| 212 | |
Stefan Hajnoczi | 4e6a8ff | 2013-01-19 11:18:43 +0100 | [diff] [blame] | 213 | if (memcmp(buf, pod_version_header, sizeof(pod_version_header)) == 0) { |
| 214 | pod->firmware_version = buf[13] * 100 + buf[14] * 10 + buf[15]; |
| 215 | pod->device_id = ((int)buf[8] << 16) | ((int)buf[9] << 8) | |
| 216 | (int) buf[10]; |
| 217 | pod_startup3(pod); |
| 218 | return; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 219 | } |
| 220 | |
Stefan Hajnoczi | 4e6a8ff | 2013-01-19 11:18:43 +0100 | [diff] [blame] | 221 | /* Only look for sysex messages from this device */ |
| 222 | if (buf[0] != (LINE6_SYSEX_BEGIN | LINE6_CHANNEL_DEVICE) && |
| 223 | buf[0] != (LINE6_SYSEX_BEGIN | LINE6_CHANNEL_UNKNOWN)) { |
| 224 | return; |
| 225 | } |
Laurent Navet | c19e946 | 2013-02-25 14:08:49 +0100 | [diff] [blame] | 226 | if (memcmp(buf + 1, line6_midi_id, sizeof(line6_midi_id)) != 0) |
Stefan Hajnoczi | 4e6a8ff | 2013-01-19 11:18:43 +0100 | [diff] [blame] | 227 | return; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 228 | |
Stefan Hajnoczi | 4e6a8ff | 2013-01-19 11:18:43 +0100 | [diff] [blame] | 229 | if (buf[5] == POD_SYSEX_SYSTEM && buf[6] == POD_MONITOR_LEVEL) { |
| 230 | short value = ((int)buf[7] << 12) | ((int)buf[8] << 8) | |
| 231 | ((int)buf[9] << 4) | (int)buf[10]; |
| 232 | pod->monitor_level = value; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 233 | } |
| 234 | } |
| 235 | |
| 236 | /* |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 237 | Send system parameter (from integer). |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 238 | */ |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 239 | static int pod_set_system_param_int(struct usb_line6_pod *pod, int value, |
| 240 | int code) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 241 | { |
| 242 | char *sysex; |
| 243 | static const int size = 5; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 244 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 245 | sysex = pod_alloc_sysex_buffer(pod, POD_SYSEX_SYSTEM, size); |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 246 | if (!sysex) |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 247 | return -ENOMEM; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 248 | sysex[SYSEX_DATA_OFS] = code; |
| 249 | sysex[SYSEX_DATA_OFS + 1] = (value >> 12) & 0x0f; |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 250 | sysex[SYSEX_DATA_OFS + 2] = (value >> 8) & 0x0f; |
| 251 | sysex[SYSEX_DATA_OFS + 3] = (value >> 4) & 0x0f; |
| 252 | sysex[SYSEX_DATA_OFS + 4] = (value) & 0x0f; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 253 | line6_send_sysex_message(&pod->line6, sysex, size); |
| 254 | kfree(sysex); |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 255 | return 0; |
| 256 | } |
| 257 | |
| 258 | /* |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 259 | "read" request on "serial_number" special file. |
| 260 | */ |
Greg Kroah-Hartman | e7c8a7e | 2013-08-24 10:36:49 -0700 | [diff] [blame] | 261 | static ssize_t serial_number_show(struct device *dev, |
| 262 | struct device_attribute *attr, char *buf) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 263 | { |
| 264 | struct usb_interface *interface = to_usb_interface(dev); |
| 265 | struct usb_line6_pod *pod = usb_get_intfdata(interface); |
Jerry Snitselaar | f3c5261 | 2014-04-24 00:31:48 -0700 | [diff] [blame] | 266 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 267 | return sprintf(buf, "%d\n", pod->serial_number); |
| 268 | } |
| 269 | |
| 270 | /* |
| 271 | "read" request on "firmware_version" special file. |
| 272 | */ |
Greg Kroah-Hartman | e7c8a7e | 2013-08-24 10:36:49 -0700 | [diff] [blame] | 273 | static ssize_t firmware_version_show(struct device *dev, |
| 274 | struct device_attribute *attr, char *buf) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 275 | { |
| 276 | struct usb_interface *interface = to_usb_interface(dev); |
| 277 | struct usb_line6_pod *pod = usb_get_intfdata(interface); |
Jerry Snitselaar | f3c5261 | 2014-04-24 00:31:48 -0700 | [diff] [blame] | 278 | |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 279 | return sprintf(buf, "%d.%02d\n", pod->firmware_version / 100, |
| 280 | pod->firmware_version % 100); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | /* |
| 284 | "read" request on "device_id" special file. |
| 285 | */ |
Greg Kroah-Hartman | e7c8a7e | 2013-08-24 10:36:49 -0700 | [diff] [blame] | 286 | static ssize_t device_id_show(struct device *dev, |
| 287 | struct device_attribute *attr, char *buf) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 288 | { |
| 289 | struct usb_interface *interface = to_usb_interface(dev); |
| 290 | struct usb_line6_pod *pod = usb_get_intfdata(interface); |
Jerry Snitselaar | f3c5261 | 2014-04-24 00:31:48 -0700 | [diff] [blame] | 291 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 292 | return sprintf(buf, "%d\n", pod->device_id); |
| 293 | } |
| 294 | |
| 295 | /* |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 296 | POD startup procedure. |
| 297 | This is a sequence of functions with special requirements (e.g., must |
| 298 | not run immediately after initialization, must not run in interrupt |
| 299 | context). After the last one has finished, the device is ready to use. |
| 300 | */ |
| 301 | |
| 302 | static void pod_startup1(struct usb_line6_pod *pod) |
| 303 | { |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 304 | CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_INIT); |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 305 | |
| 306 | /* delay startup procedure: */ |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 307 | line6_start_timer(&pod->startup_timer, POD_STARTUP_DELAY, pod_startup2, |
| 308 | (unsigned long)pod); |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | static void pod_startup2(unsigned long data) |
| 312 | { |
| 313 | struct usb_line6_pod *pod = (struct usb_line6_pod *)data; |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 314 | struct usb_line6 *line6 = &pod->line6; |
Jerry Snitselaar | f3c5261 | 2014-04-24 00:31:48 -0700 | [diff] [blame] | 315 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 316 | CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_VERSIONREQ); |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 317 | |
| 318 | /* request firmware version: */ |
| 319 | line6_version_request_async(line6); |
| 320 | } |
| 321 | |
Stefan Hajnoczi | 09fda10 | 2012-11-22 20:49:24 +0100 | [diff] [blame] | 322 | static void pod_startup3(struct usb_line6_pod *pod) |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 323 | { |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 324 | CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_WORKQUEUE); |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 325 | |
| 326 | /* schedule work for global work queue: */ |
| 327 | schedule_work(&pod->startup_work); |
| 328 | } |
| 329 | |
Stefan Hajnoczi | 09fda10 | 2012-11-22 20:49:24 +0100 | [diff] [blame] | 330 | static void pod_startup4(struct work_struct *work) |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 331 | { |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 332 | struct usb_line6_pod *pod = |
| 333 | container_of(work, struct usb_line6_pod, startup_work); |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 334 | struct usb_line6 *line6 = &pod->line6; |
| 335 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 336 | CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_SETUP); |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 337 | |
| 338 | /* serial number: */ |
| 339 | line6_read_serial_number(&pod->line6, &pod->serial_number); |
| 340 | |
| 341 | /* ALSA audio interface: */ |
Takashi Iwai | 85a9339 | 2015-01-19 15:54:00 +0100 | [diff] [blame] | 342 | snd_card_register(line6->card); |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 343 | } |
| 344 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 345 | /* POD special files: */ |
Greg Kroah-Hartman | e7c8a7e | 2013-08-24 10:36:49 -0700 | [diff] [blame] | 346 | static DEVICE_ATTR_RO(device_id); |
| 347 | static DEVICE_ATTR_RO(firmware_version); |
| 348 | static DEVICE_ATTR_RO(serial_number); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 349 | |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 350 | /* control info callback */ |
| 351 | static int snd_pod_control_monitor_info(struct snd_kcontrol *kcontrol, |
| 352 | struct snd_ctl_elem_info *uinfo) |
| 353 | { |
| 354 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 355 | uinfo->count = 1; |
| 356 | uinfo->value.integer.min = 0; |
| 357 | uinfo->value.integer.max = 65535; |
| 358 | return 0; |
| 359 | } |
| 360 | |
| 361 | /* control get callback */ |
| 362 | static int snd_pod_control_monitor_get(struct snd_kcontrol *kcontrol, |
| 363 | struct snd_ctl_elem_value *ucontrol) |
| 364 | { |
| 365 | struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol); |
| 366 | struct usb_line6_pod *pod = (struct usb_line6_pod *)line6pcm->line6; |
Jerry Snitselaar | f3c5261 | 2014-04-24 00:31:48 -0700 | [diff] [blame] | 367 | |
Stefan Hajnoczi | 2c35dc2 | 2012-11-22 20:48:47 +0100 | [diff] [blame] | 368 | ucontrol->value.integer.value[0] = pod->monitor_level; |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 369 | return 0; |
| 370 | } |
| 371 | |
| 372 | /* control put callback */ |
| 373 | static int snd_pod_control_monitor_put(struct snd_kcontrol *kcontrol, |
| 374 | struct snd_ctl_elem_value *ucontrol) |
| 375 | { |
| 376 | struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol); |
| 377 | struct usb_line6_pod *pod = (struct usb_line6_pod *)line6pcm->line6; |
| 378 | |
Stefan Hajnoczi | 2c35dc2 | 2012-11-22 20:48:47 +0100 | [diff] [blame] | 379 | if (ucontrol->value.integer.value[0] == pod->monitor_level) |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 380 | return 0; |
| 381 | |
Stefan Hajnoczi | 2c35dc2 | 2012-11-22 20:48:47 +0100 | [diff] [blame] | 382 | pod->monitor_level = ucontrol->value.integer.value[0]; |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 383 | pod_set_system_param_int(pod, ucontrol->value.integer.value[0], |
Stefan Hajnoczi | 7936095 | 2013-01-11 23:08:14 +0100 | [diff] [blame] | 384 | POD_MONITOR_LEVEL); |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 385 | return 1; |
| 386 | } |
| 387 | |
| 388 | /* control definition */ |
| 389 | static struct snd_kcontrol_new pod_control_monitor = { |
| 390 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 391 | .name = "Monitor Playback Volume", |
| 392 | .index = 0, |
| 393 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, |
| 394 | .info = snd_pod_control_monitor_info, |
| 395 | .get = snd_pod_control_monitor_get, |
| 396 | .put = snd_pod_control_monitor_put |
| 397 | }; |
| 398 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 399 | /* |
Chris Rorvick | d29b854 | 2015-01-12 12:43:00 -0800 | [diff] [blame] | 400 | POD device disconnected. |
| 401 | */ |
Takashi Iwai | f66fd99 | 2015-01-25 18:22:58 +0100 | [diff] [blame] | 402 | static void line6_pod_disconnect(struct usb_line6 *line6) |
Chris Rorvick | d29b854 | 2015-01-12 12:43:00 -0800 | [diff] [blame] | 403 | { |
Takashi Iwai | f66fd99 | 2015-01-25 18:22:58 +0100 | [diff] [blame] | 404 | struct usb_line6_pod *pod = (struct usb_line6_pod *)line6; |
| 405 | struct device *dev = line6->ifcdev; |
Chris Rorvick | d29b854 | 2015-01-12 12:43:00 -0800 | [diff] [blame] | 406 | |
Takashi Iwai | 8a3b7c0 | 2015-01-20 08:42:42 +0100 | [diff] [blame] | 407 | /* remove sysfs entries: */ |
| 408 | device_remove_file(dev, &dev_attr_device_id); |
| 409 | device_remove_file(dev, &dev_attr_firmware_version); |
| 410 | device_remove_file(dev, &dev_attr_serial_number); |
Chris Rorvick | d29b854 | 2015-01-12 12:43:00 -0800 | [diff] [blame] | 411 | |
Takashi Iwai | 8a3b7c0 | 2015-01-20 08:42:42 +0100 | [diff] [blame] | 412 | del_timer_sync(&pod->startup_timer); |
| 413 | cancel_work_sync(&pod->startup_work); |
Chris Rorvick | d29b854 | 2015-01-12 12:43:00 -0800 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | /* |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 417 | Create sysfs entries. |
| 418 | */ |
Greg Kroah-Hartman | b702ed25 | 2009-02-27 20:45:03 -0800 | [diff] [blame] | 419 | static int pod_create_files2(struct device *dev) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 420 | { |
| 421 | int err; |
| 422 | |
Takashi Iwai | b2a3b02 | 2015-01-19 16:08:02 +0100 | [diff] [blame] | 423 | err = device_create_file(dev, &dev_attr_device_id); |
| 424 | if (err < 0) |
| 425 | return err; |
| 426 | err = device_create_file(dev, &dev_attr_firmware_version); |
| 427 | if (err < 0) |
| 428 | return err; |
| 429 | err = device_create_file(dev, &dev_attr_serial_number); |
| 430 | if (err < 0) |
| 431 | return err; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 432 | return 0; |
| 433 | } |
| 434 | |
| 435 | /* |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 436 | Try to init POD device. |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 437 | */ |
Takashi Iwai | f66fd99 | 2015-01-25 18:22:58 +0100 | [diff] [blame] | 438 | static int pod_init(struct usb_line6 *line6, |
| 439 | const struct usb_device_id *id) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 440 | { |
| 441 | int err; |
Chris Rorvick | a221dd4 | 2015-01-12 12:42:56 -0800 | [diff] [blame] | 442 | struct usb_line6_pod *pod = (struct usb_line6_pod *) line6; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 443 | |
Chris Rorvick | 01f6b2b | 2015-01-12 12:42:58 -0800 | [diff] [blame] | 444 | line6->process_message = line6_pod_process_message; |
Chris Rorvick | a46c467 | 2015-01-12 12:42:59 -0800 | [diff] [blame] | 445 | line6->disconnect = line6_pod_disconnect; |
Chris Rorvick | 01f6b2b | 2015-01-12 12:42:58 -0800 | [diff] [blame] | 446 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 447 | init_timer(&pod->startup_timer); |
Stefan Hajnoczi | 09fda10 | 2012-11-22 20:49:24 +0100 | [diff] [blame] | 448 | INIT_WORK(&pod->startup_work, pod_startup4); |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 449 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 450 | /* create sysfs entries: */ |
Takashi Iwai | f66fd99 | 2015-01-25 18:22:58 +0100 | [diff] [blame] | 451 | err = pod_create_files2(line6->ifcdev); |
Greg Kroah-Hartman | 027360c | 2010-09-21 16:58:00 -0700 | [diff] [blame] | 452 | if (err < 0) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 453 | return err; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 454 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 455 | /* initialize MIDI subsystem: */ |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 456 | err = line6_init_midi(line6); |
Greg Kroah-Hartman | 027360c | 2010-09-21 16:58:00 -0700 | [diff] [blame] | 457 | if (err < 0) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 458 | return err; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 459 | |
| 460 | /* initialize PCM subsystem: */ |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 461 | err = line6_init_pcm(line6, &pod_pcm_properties); |
Greg Kroah-Hartman | 027360c | 2010-09-21 16:58:00 -0700 | [diff] [blame] | 462 | if (err < 0) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 463 | return err; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 464 | |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 465 | /* register monitor control: */ |
Greg Kroah-Hartman | 027360c | 2010-09-21 16:58:00 -0700 | [diff] [blame] | 466 | err = snd_ctl_add(line6->card, |
| 467 | snd_ctl_new1(&pod_control_monitor, line6->line6pcm)); |
| 468 | if (err < 0) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 469 | return err; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 470 | |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 471 | /* |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 472 | When the sound card is registered at this point, the PODxt Live |
| 473 | displays "Invalid Code Error 07", so we do it later in the event |
| 474 | handler. |
| 475 | */ |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 476 | |
Chris Rorvick | 4cb1a4a | 2015-01-12 12:42:45 -0800 | [diff] [blame] | 477 | if (pod->line6.properties->capabilities & LINE6_CAP_CONTROL) { |
Stefan Hajnoczi | 7936095 | 2013-01-11 23:08:14 +0100 | [diff] [blame] | 478 | pod->monitor_level = POD_SYSTEM_INVALID; |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 479 | |
| 480 | /* initiate startup procedure: */ |
| 481 | pod_startup1(pod); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | return 0; |
| 485 | } |
| 486 | |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 487 | #define LINE6_DEVICE(prod) USB_DEVICE(0x0e41, prod) |
| 488 | #define LINE6_IF_NUM(prod, n) USB_DEVICE_INTERFACE_NUMBER(0x0e41, prod, n) |
| 489 | |
| 490 | /* table of devices that work with this driver */ |
| 491 | static const struct usb_device_id pod_id_table[] = { |
| 492 | { LINE6_DEVICE(0x4250), .driver_info = LINE6_BASSPODXT }, |
| 493 | { LINE6_DEVICE(0x4642), .driver_info = LINE6_BASSPODXTLIVE }, |
| 494 | { LINE6_DEVICE(0x4252), .driver_info = LINE6_BASSPODXTPRO }, |
| 495 | { LINE6_IF_NUM(0x5051, 1), .driver_info = LINE6_POCKETPOD }, |
| 496 | { LINE6_DEVICE(0x5044), .driver_info = LINE6_PODXT }, |
| 497 | { LINE6_IF_NUM(0x4650, 0), .driver_info = LINE6_PODXTLIVE_POD }, |
| 498 | { LINE6_DEVICE(0x5050), .driver_info = LINE6_PODXTPRO }, |
| 499 | {} |
| 500 | }; |
| 501 | |
| 502 | MODULE_DEVICE_TABLE(usb, pod_id_table); |
| 503 | |
| 504 | static const struct line6_properties pod_properties_table[] = { |
| 505 | [LINE6_BASSPODXT] = { |
| 506 | .id = "BassPODxt", |
| 507 | .name = "BassPODxt", |
| 508 | .capabilities = LINE6_CAP_CONTROL |
| 509 | | LINE6_CAP_PCM |
| 510 | | LINE6_CAP_HWMON, |
| 511 | .altsetting = 5, |
| 512 | .ep_ctrl_r = 0x84, |
| 513 | .ep_ctrl_w = 0x03, |
| 514 | .ep_audio_r = 0x82, |
| 515 | .ep_audio_w = 0x01, |
| 516 | }, |
| 517 | [LINE6_BASSPODXTLIVE] = { |
| 518 | .id = "BassPODxtLive", |
| 519 | .name = "BassPODxt Live", |
| 520 | .capabilities = LINE6_CAP_CONTROL |
| 521 | | LINE6_CAP_PCM |
| 522 | | LINE6_CAP_HWMON, |
| 523 | .altsetting = 1, |
| 524 | .ep_ctrl_r = 0x84, |
| 525 | .ep_ctrl_w = 0x03, |
| 526 | .ep_audio_r = 0x82, |
| 527 | .ep_audio_w = 0x01, |
| 528 | }, |
| 529 | [LINE6_BASSPODXTPRO] = { |
| 530 | .id = "BassPODxtPro", |
| 531 | .name = "BassPODxt Pro", |
| 532 | .capabilities = LINE6_CAP_CONTROL |
| 533 | | LINE6_CAP_PCM |
| 534 | | LINE6_CAP_HWMON, |
| 535 | .altsetting = 5, |
| 536 | .ep_ctrl_r = 0x84, |
| 537 | .ep_ctrl_w = 0x03, |
| 538 | .ep_audio_r = 0x82, |
| 539 | .ep_audio_w = 0x01, |
| 540 | }, |
| 541 | [LINE6_POCKETPOD] = { |
| 542 | .id = "PocketPOD", |
| 543 | .name = "Pocket POD", |
| 544 | .capabilities = LINE6_CAP_CONTROL, |
| 545 | .altsetting = 0, |
| 546 | .ep_ctrl_r = 0x82, |
| 547 | .ep_ctrl_w = 0x02, |
| 548 | /* no audio channel */ |
| 549 | }, |
| 550 | [LINE6_PODXT] = { |
| 551 | .id = "PODxt", |
| 552 | .name = "PODxt", |
| 553 | .capabilities = LINE6_CAP_CONTROL |
| 554 | | LINE6_CAP_PCM |
| 555 | | LINE6_CAP_HWMON, |
| 556 | .altsetting = 5, |
| 557 | .ep_ctrl_r = 0x84, |
| 558 | .ep_ctrl_w = 0x03, |
| 559 | .ep_audio_r = 0x82, |
| 560 | .ep_audio_w = 0x01, |
| 561 | }, |
| 562 | [LINE6_PODXTLIVE_POD] = { |
| 563 | .id = "PODxtLive", |
| 564 | .name = "PODxt Live", |
| 565 | .capabilities = LINE6_CAP_CONTROL |
| 566 | | LINE6_CAP_PCM |
| 567 | | LINE6_CAP_HWMON, |
| 568 | .altsetting = 1, |
| 569 | .ep_ctrl_r = 0x84, |
| 570 | .ep_ctrl_w = 0x03, |
| 571 | .ep_audio_r = 0x82, |
| 572 | .ep_audio_w = 0x01, |
| 573 | }, |
| 574 | [LINE6_PODXTPRO] = { |
| 575 | .id = "PODxtPro", |
| 576 | .name = "PODxt Pro", |
| 577 | .capabilities = LINE6_CAP_CONTROL |
| 578 | | LINE6_CAP_PCM |
| 579 | | LINE6_CAP_HWMON, |
| 580 | .altsetting = 5, |
| 581 | .ep_ctrl_r = 0x84, |
| 582 | .ep_ctrl_w = 0x03, |
| 583 | .ep_audio_r = 0x82, |
| 584 | .ep_audio_w = 0x01, |
| 585 | }, |
| 586 | }; |
| 587 | |
| 588 | /* |
| 589 | Probe USB device. |
| 590 | */ |
| 591 | static int pod_probe(struct usb_interface *interface, |
| 592 | const struct usb_device_id *id) |
| 593 | { |
Takashi Iwai | aca514b | 2015-01-25 18:36:29 +0100 | [diff] [blame^] | 594 | return line6_probe(interface, id, |
Takashi Iwai | 85a9339 | 2015-01-19 15:54:00 +0100 | [diff] [blame] | 595 | &pod_properties_table[id->driver_info], |
Takashi Iwai | aca514b | 2015-01-25 18:36:29 +0100 | [diff] [blame^] | 596 | pod_init, sizeof(struct usb_line6_pod)); |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | static struct usb_driver pod_driver = { |
| 600 | .name = KBUILD_MODNAME, |
| 601 | .probe = pod_probe, |
| 602 | .disconnect = line6_disconnect, |
| 603 | #ifdef CONFIG_PM |
| 604 | .suspend = line6_suspend, |
| 605 | .resume = line6_resume, |
| 606 | .reset_resume = line6_resume, |
| 607 | #endif |
| 608 | .id_table = pod_id_table, |
| 609 | }; |
| 610 | |
| 611 | module_usb_driver(pod_driver); |
| 612 | |
Chris Rorvick | c6fffce | 2015-01-20 02:20:49 -0600 | [diff] [blame] | 613 | MODULE_DESCRIPTION("Line 6 POD USB driver"); |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 614 | MODULE_LICENSE("GPL"); |