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