Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1 | /* |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 2 | * Line6 Linux USB driver - 0.9.1beta |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 3 | * |
Markus Grabner | 1027f476 | 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 | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 13 | #include <linux/wait.h> |
| 14 | #include <sound/control.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 15 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 16 | #include "audio.h" |
| 17 | #include "capture.h" |
| 18 | #include "control.h" |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 19 | #include "driver.h" |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 20 | #include "playback.h" |
| 21 | #include "pod.h" |
| 22 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 23 | #define POD_SYSEX_CODE 3 |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 24 | #define POD_BYTES_PER_FRAME 6 /* 24bit audio (stereo) */ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 25 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 26 | /* *INDENT-OFF* */ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 27 | |
| 28 | enum { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 29 | POD_SYSEX_SAVE = 0x24, |
| 30 | POD_SYSEX_SYSTEM = 0x56, |
| 31 | POD_SYSEX_SYSTEMREQ = 0x57, |
| 32 | /* POD_SYSEX_UPDATE = 0x6c, */ /* software update! */ |
| 33 | POD_SYSEX_STORE = 0x71, |
| 34 | POD_SYSEX_FINISH = 0x72, |
| 35 | POD_SYSEX_DUMPMEM = 0x73, |
| 36 | POD_SYSEX_DUMP = 0x74, |
| 37 | POD_SYSEX_DUMPREQ = 0x75 |
| 38 | /* POD_SYSEX_DUMPMEM2 = 0x76 */ /* dumps entire internal memory of PODxt Pro */ |
| 39 | }; |
| 40 | |
| 41 | enum { |
| 42 | POD_monitor_level = 0x04, |
| 43 | POD_routing = 0x05, |
| 44 | POD_tuner_mute = 0x13, |
| 45 | POD_tuner_freq = 0x15, |
| 46 | POD_tuner_note = 0x16, |
| 47 | POD_tuner_pitch = 0x17, |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 48 | POD_system_invalid = 0x10000 |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 49 | }; |
| 50 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 51 | /* *INDENT-ON* */ |
| 52 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 53 | enum { |
| 54 | POD_DUMP_MEMORY = 2 |
| 55 | }; |
| 56 | |
| 57 | enum { |
| 58 | POD_BUSY_READ, |
| 59 | POD_BUSY_WRITE, |
| 60 | POD_CHANNEL_DIRTY, |
| 61 | POD_SAVE_PRESSED, |
| 62 | POD_BUSY_MIDISEND |
| 63 | }; |
| 64 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 65 | static struct snd_ratden pod_ratden = { |
| 66 | .num_min = 78125, |
| 67 | .num_max = 78125, |
| 68 | .num_step = 1, |
| 69 | .den = 2 |
| 70 | }; |
| 71 | |
| 72 | static struct line6_pcm_properties pod_pcm_properties = { |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 73 | .snd_line6_playback_hw = { |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 74 | .info = (SNDRV_PCM_INFO_MMAP | |
| 75 | SNDRV_PCM_INFO_INTERLEAVED | |
| 76 | SNDRV_PCM_INFO_BLOCK_TRANSFER | |
| 77 | SNDRV_PCM_INFO_MMAP_VALID | |
| 78 | SNDRV_PCM_INFO_PAUSE | |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 79 | #ifdef CONFIG_PM |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 80 | SNDRV_PCM_INFO_RESUME | |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 81 | #endif |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 82 | SNDRV_PCM_INFO_SYNC_START), |
| 83 | .formats = SNDRV_PCM_FMTBIT_S24_3LE, |
| 84 | .rates = SNDRV_PCM_RATE_KNOT, |
| 85 | .rate_min = 39062, |
| 86 | .rate_max = 39063, |
| 87 | .channels_min = 2, |
| 88 | .channels_max = 2, |
| 89 | .buffer_bytes_max = 60000, |
| 90 | .period_bytes_min = 64, |
| 91 | .period_bytes_max = 8192, |
| 92 | .periods_min = 1, |
| 93 | .periods_max = 1024}, |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 94 | .snd_line6_capture_hw = { |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 95 | .info = (SNDRV_PCM_INFO_MMAP | |
| 96 | SNDRV_PCM_INFO_INTERLEAVED | |
| 97 | SNDRV_PCM_INFO_BLOCK_TRANSFER | |
| 98 | SNDRV_PCM_INFO_MMAP_VALID | |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 99 | #ifdef CONFIG_PM |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 100 | SNDRV_PCM_INFO_RESUME | |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 101 | #endif |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 102 | SNDRV_PCM_INFO_SYNC_START), |
| 103 | .formats = SNDRV_PCM_FMTBIT_S24_3LE, |
| 104 | .rates = SNDRV_PCM_RATE_KNOT, |
| 105 | .rate_min = 39062, |
| 106 | .rate_max = 39063, |
| 107 | .channels_min = 2, |
| 108 | .channels_max = 2, |
| 109 | .buffer_bytes_max = 60000, |
| 110 | .period_bytes_min = 64, |
| 111 | .period_bytes_max = 8192, |
| 112 | .periods_min = 1, |
| 113 | .periods_max = 1024}, |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 114 | .snd_line6_rates = { |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 115 | .nrats = 1, |
| 116 | .rats = &pod_ratden}, |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 117 | .bytes_per_frame = POD_BYTES_PER_FRAME |
| 118 | }; |
| 119 | |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 120 | static const char pod_request_channel[] = { |
| 121 | 0xf0, 0x00, 0x01, 0x0c, 0x03, 0x75, 0xf7 |
| 122 | }; |
| 123 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 124 | static const char pod_version_header[] = { |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 125 | 0xf2, 0x7e, 0x7f, 0x06, 0x02 |
| 126 | }; |
| 127 | |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 128 | /* forward declarations: */ |
| 129 | static void pod_startup2(unsigned long data); |
| 130 | static void pod_startup3(struct usb_line6_pod *pod); |
| 131 | static void pod_startup4(struct usb_line6_pod *pod); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 132 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 133 | static char *pod_alloc_sysex_buffer(struct usb_line6_pod *pod, int code, |
| 134 | int size) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 135 | { |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 136 | return line6_alloc_sysex_buffer(&pod->line6, POD_SYSEX_CODE, code, |
| 137 | size); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | /* |
Stefan Hajnoczi | b772fe9 | 2012-11-22 20:48:43 +0100 | [diff] [blame] | 141 | Store parameter value in driver memory. |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 142 | */ |
| 143 | static void pod_store_parameter(struct usb_line6_pod *pod, int param, int value) |
| 144 | { |
| 145 | pod->prog_data.control[param] = value; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | /* |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 149 | Handle SAVE button. |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 150 | */ |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 151 | static void pod_save_button_pressed(struct usb_line6_pod *pod, int type, |
| 152 | int index) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 153 | { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 154 | set_bit(POD_SAVE_PRESSED, &pod->atomic_flags); |
| 155 | } |
| 156 | |
| 157 | /* |
| 158 | Process a completely received message. |
| 159 | */ |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 160 | void line6_pod_process_message(struct usb_line6_pod *pod) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 161 | { |
| 162 | const unsigned char *buf = pod->line6.buffer_message; |
| 163 | |
| 164 | /* filter messages by type */ |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 165 | switch (buf[0] & 0xf0) { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 166 | case LINE6_PARAM_CHANGE: |
| 167 | case LINE6_PROGRAM_CHANGE: |
| 168 | case LINE6_SYSEX_BEGIN: |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 169 | break; /* handle these further down */ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 170 | |
| 171 | default: |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 172 | return; /* ignore all others */ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | /* process all remaining messages */ |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 176 | switch (buf[0]) { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 177 | case LINE6_PARAM_CHANGE | LINE6_CHANNEL_DEVICE: |
| 178 | pod_store_parameter(pod, buf[1], buf[2]); |
| 179 | /* intentionally no break here! */ |
| 180 | |
| 181 | case LINE6_PARAM_CHANGE | LINE6_CHANNEL_HOST: |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 182 | if ((buf[1] == POD_amp_model_setup) || |
| 183 | (buf[1] == POD_effect_setup)) |
| 184 | /* these also affect other settings */ |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 185 | line6_dump_request_async(&pod->dumpreq, &pod->line6, 0, |
| 186 | LINE6_DUMP_CURRENT); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 187 | |
| 188 | break; |
| 189 | |
| 190 | case LINE6_PROGRAM_CHANGE | LINE6_CHANNEL_DEVICE: |
| 191 | case LINE6_PROGRAM_CHANGE | LINE6_CHANNEL_HOST: |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 192 | set_bit(POD_CHANNEL_DIRTY, &pod->atomic_flags); |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 193 | line6_dump_request_async(&pod->dumpreq, &pod->line6, 0, |
| 194 | LINE6_DUMP_CURRENT); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 195 | break; |
| 196 | |
| 197 | case LINE6_SYSEX_BEGIN | LINE6_CHANNEL_DEVICE: |
| 198 | case LINE6_SYSEX_BEGIN | LINE6_CHANNEL_UNKNOWN: |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 199 | if (memcmp(buf + 1, line6_midi_id, sizeof(line6_midi_id)) == 0) { |
| 200 | switch (buf[5]) { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 201 | case POD_SYSEX_DUMP: |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 202 | if (pod->line6.message_length == |
| 203 | sizeof(pod->prog_data) + 7) { |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 204 | switch (pod->dumpreq.in_progress) { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 205 | case LINE6_DUMP_CURRENT: |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 206 | memcpy(&pod->prog_data, buf + 7, |
| 207 | sizeof(pod->prog_data)); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 208 | break; |
| 209 | |
| 210 | case POD_DUMP_MEMORY: |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 211 | memcpy(&pod->prog_data_buf, |
| 212 | buf + 7, |
| 213 | sizeof |
| 214 | (pod->prog_data_buf)); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 215 | break; |
| 216 | |
| 217 | default: |
Stefan Hajnoczi | e00d33c | 2012-11-11 13:52:24 +0100 | [diff] [blame] | 218 | dev_dbg(pod->line6.ifcdev, |
| 219 | "unknown dump code %02X\n", |
| 220 | pod->dumpreq.in_progress); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | line6_dump_finished(&pod->dumpreq); |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 224 | pod_startup3(pod); |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 225 | } else |
Stefan Hajnoczi | e00d33c | 2012-11-11 13:52:24 +0100 | [diff] [blame] | 226 | dev_dbg(pod->line6.ifcdev, |
| 227 | "wrong size of channel dump message (%d instead of %d)\n", |
| 228 | pod->line6.message_length, |
| 229 | (int)sizeof(pod->prog_data) + |
| 230 | 7); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 231 | |
| 232 | break; |
| 233 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 234 | case POD_SYSEX_SYSTEM:{ |
| 235 | short value = |
| 236 | ((int)buf[7] << 12) | ((int)buf[8] |
| 237 | << 8) | |
| 238 | ((int)buf[9] << 4) | (int)buf[10]; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 239 | |
| 240 | #define PROCESS_SYSTEM_PARAM(x) \ |
| 241 | case POD_ ## x: \ |
| 242 | pod->x.value = value; \ |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 243 | wake_up(&pod->x.wait); \ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 244 | break; |
| 245 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 246 | switch (buf[6]) { |
| 247 | PROCESS_SYSTEM_PARAM |
| 248 | (monitor_level); |
| 249 | PROCESS_SYSTEM_PARAM(routing); |
| 250 | PROCESS_SYSTEM_PARAM |
| 251 | (tuner_mute); |
| 252 | PROCESS_SYSTEM_PARAM |
| 253 | (tuner_freq); |
| 254 | PROCESS_SYSTEM_PARAM |
| 255 | (tuner_note); |
| 256 | PROCESS_SYSTEM_PARAM |
| 257 | (tuner_pitch); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 258 | |
| 259 | #undef PROCESS_SYSTEM_PARAM |
| 260 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 261 | default: |
Stefan Hajnoczi | e00d33c | 2012-11-11 13:52:24 +0100 | [diff] [blame] | 262 | dev_dbg(pod->line6.ifcdev, |
| 263 | "unknown tuner/system response %02X\n", |
| 264 | buf[6]); |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 265 | } |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 266 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 267 | break; |
| 268 | } |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 269 | |
| 270 | case POD_SYSEX_FINISH: |
| 271 | /* do we need to respond to this? */ |
| 272 | break; |
| 273 | |
| 274 | case POD_SYSEX_SAVE: |
| 275 | pod_save_button_pressed(pod, buf[6], buf[7]); |
| 276 | break; |
| 277 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 278 | case POD_SYSEX_STORE: |
Stefan Hajnoczi | e00d33c | 2012-11-11 13:52:24 +0100 | [diff] [blame] | 279 | dev_dbg(pod->line6.ifcdev, |
| 280 | "message %02X not yet implemented\n", |
| 281 | buf[5]); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 282 | break; |
| 283 | |
| 284 | default: |
Stefan Hajnoczi | e00d33c | 2012-11-11 13:52:24 +0100 | [diff] [blame] | 285 | dev_dbg(pod->line6.ifcdev, |
| 286 | "unknown sysex message %02X\n", |
| 287 | buf[5]); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 288 | } |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 289 | } else |
| 290 | if (memcmp |
| 291 | (buf, pod_version_header, |
| 292 | sizeof(pod_version_header)) == 0) { |
| 293 | pod->firmware_version = |
| 294 | buf[13] * 100 + buf[14] * 10 + buf[15]; |
| 295 | pod->device_id = |
| 296 | ((int)buf[8] << 16) | ((int)buf[9] << 8) | (int) |
| 297 | buf[10]; |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 298 | pod_startup4(pod); |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 299 | } else |
Stefan Hajnoczi | e00d33c | 2012-11-11 13:52:24 +0100 | [diff] [blame] | 300 | dev_dbg(pod->line6.ifcdev, "unknown sysex header\n"); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 301 | |
| 302 | break; |
| 303 | |
| 304 | case LINE6_SYSEX_END: |
| 305 | break; |
| 306 | |
| 307 | default: |
Stefan Hajnoczi | e00d33c | 2012-11-11 13:52:24 +0100 | [diff] [blame] | 308 | dev_dbg(pod->line6.ifcdev, "POD: unknown message %02X\n", |
| 309 | buf[0]); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 310 | } |
| 311 | } |
| 312 | |
| 313 | /* |
| 314 | Detect some cases that require a channel dump after sending a command to the |
| 315 | device. Important notes: |
| 316 | *) The actual dump request can not be sent here since we are not allowed to |
| 317 | wait for the completion of the first message in this context, and sending |
| 318 | the dump request before completion of the previous message leaves the POD |
| 319 | in an undefined state. The dump request will be sent when the echoed |
| 320 | commands are received. |
| 321 | *) This method fails if a param change message is "chopped" after the first |
| 322 | byte. |
| 323 | */ |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 324 | void line6_pod_midi_postprocess(struct usb_line6_pod *pod, unsigned char *data, |
| 325 | int length) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 326 | { |
| 327 | int i; |
| 328 | |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 329 | if (!pod->midi_postprocess) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 330 | return; |
| 331 | |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 332 | for (i = 0; i < length; ++i) { |
| 333 | if (data[i] == (LINE6_PROGRAM_CHANGE | LINE6_CHANNEL_HOST)) { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 334 | line6_invalidate_current(&pod->dumpreq); |
| 335 | break; |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 336 | } else |
| 337 | if ((data[i] == (LINE6_PARAM_CHANGE | LINE6_CHANNEL_HOST)) |
| 338 | && (i < length - 1)) |
| 339 | if ((data[i + 1] == POD_amp_model_setup) |
| 340 | || (data[i + 1] == POD_effect_setup)) { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 341 | line6_invalidate_current(&pod->dumpreq); |
| 342 | break; |
| 343 | } |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | /* |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 348 | Transmit PODxt Pro control parameter. |
| 349 | */ |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 350 | void line6_pod_transmit_parameter(struct usb_line6_pod *pod, int param, |
Johannes Thumshirn | 5b9bd2a | 2012-06-27 21:25:57 +0200 | [diff] [blame] | 351 | u8 value) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 352 | { |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 353 | if (line6_transmit_parameter(&pod->line6, param, value) == 0) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 354 | pod_store_parameter(pod, param, value); |
| 355 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 356 | if ((param == POD_amp_model_setup) || (param == POD_effect_setup)) /* these also affect other settings */ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 357 | line6_invalidate_current(&pod->dumpreq); |
| 358 | } |
| 359 | |
| 360 | /* |
| 361 | Resolve value to memory location. |
| 362 | */ |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 363 | static int pod_resolve(const char *buf, short block0, short block1, |
| 364 | unsigned char *location) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 365 | { |
Johannes Thumshirn | 1d0e834 | 2012-06-27 21:26:01 +0200 | [diff] [blame] | 366 | u8 value; |
Shawn Bohrer | 7e4d5c1 | 2009-11-15 22:18:01 -0600 | [diff] [blame] | 367 | short block; |
| 368 | int ret; |
| 369 | |
Johannes Thumshirn | 1d0e834 | 2012-06-27 21:26:01 +0200 | [diff] [blame] | 370 | ret = kstrtou8(buf, 10, &value); |
Shawn Bohrer | 7e4d5c1 | 2009-11-15 22:18:01 -0600 | [diff] [blame] | 371 | if (ret) |
| 372 | return ret; |
| 373 | |
| 374 | block = (value < 0x40) ? block0 : block1; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 375 | value &= 0x3f; |
| 376 | location[0] = block >> 7; |
| 377 | location[1] = value | (block & 0x7f); |
Shawn Bohrer | 7e4d5c1 | 2009-11-15 22:18:01 -0600 | [diff] [blame] | 378 | return 0; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | /* |
| 382 | Send command to store channel/effects setup/amp setup to PODxt Pro. |
| 383 | */ |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 384 | static ssize_t pod_send_store_command(struct device *dev, const char *buf, |
| 385 | size_t count, short block0, short block1) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 386 | { |
| 387 | struct usb_interface *interface = to_usb_interface(dev); |
| 388 | struct usb_line6_pod *pod = usb_get_intfdata(interface); |
Shawn Bohrer | 7e4d5c1 | 2009-11-15 22:18:01 -0600 | [diff] [blame] | 389 | int ret; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 390 | int size = 3 + sizeof(pod->prog_data_buf); |
| 391 | char *sysex = pod_alloc_sysex_buffer(pod, POD_SYSEX_STORE, size); |
Shawn Bohrer | 7e4d5c1 | 2009-11-15 22:18:01 -0600 | [diff] [blame] | 392 | |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 393 | if (!sysex) |
| 394 | return 0; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 395 | |
Stefan Hajnoczi | 980688f | 2012-11-22 20:48:44 +0100 | [diff] [blame^] | 396 | /* Don't know what this is good for, but PODxt Pro transmits it, so we |
| 397 | * also do... */ |
| 398 | sysex[SYSEX_DATA_OFS] = 5; |
Shawn Bohrer | 7e4d5c1 | 2009-11-15 22:18:01 -0600 | [diff] [blame] | 399 | ret = pod_resolve(buf, block0, block1, sysex + SYSEX_DATA_OFS + 1); |
| 400 | if (ret) { |
| 401 | kfree(sysex); |
| 402 | return ret; |
| 403 | } |
| 404 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 405 | memcpy(sysex + SYSEX_DATA_OFS + 3, &pod->prog_data_buf, |
| 406 | sizeof(pod->prog_data_buf)); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 407 | |
| 408 | line6_send_sysex_message(&pod->line6, sysex, size); |
| 409 | kfree(sysex); |
| 410 | /* needs some delay here on AMD64 platform */ |
| 411 | return count; |
| 412 | } |
| 413 | |
| 414 | /* |
| 415 | Send command to retrieve channel/effects setup/amp setup to PODxt Pro. |
| 416 | */ |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 417 | static ssize_t pod_send_retrieve_command(struct device *dev, const char *buf, |
| 418 | size_t count, short block0, |
| 419 | short block1) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 420 | { |
| 421 | struct usb_interface *interface = to_usb_interface(dev); |
| 422 | struct usb_line6_pod *pod = usb_get_intfdata(interface); |
Shawn Bohrer | 7e4d5c1 | 2009-11-15 22:18:01 -0600 | [diff] [blame] | 423 | int ret; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 424 | int size = 4; |
| 425 | char *sysex = pod_alloc_sysex_buffer(pod, POD_SYSEX_DUMPMEM, size); |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 426 | |
| 427 | if (!sysex) |
| 428 | return 0; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 429 | |
Shawn Bohrer | 7e4d5c1 | 2009-11-15 22:18:01 -0600 | [diff] [blame] | 430 | ret = pod_resolve(buf, block0, block1, sysex + SYSEX_DATA_OFS); |
| 431 | if (ret) { |
| 432 | kfree(sysex); |
| 433 | return ret; |
| 434 | } |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 435 | sysex[SYSEX_DATA_OFS + 2] = 0; |
| 436 | sysex[SYSEX_DATA_OFS + 3] = 0; |
| 437 | line6_dump_started(&pod->dumpreq, POD_DUMP_MEMORY); |
| 438 | |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 439 | if (line6_send_sysex_message(&pod->line6, sysex, size) < size) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 440 | line6_dump_finished(&pod->dumpreq); |
| 441 | |
| 442 | kfree(sysex); |
| 443 | /* needs some delay here on AMD64 platform */ |
| 444 | return count; |
| 445 | } |
| 446 | |
| 447 | /* |
| 448 | Generic get name function. |
| 449 | */ |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 450 | static ssize_t get_name_generic(struct usb_line6_pod *pod, const char *str, |
| 451 | char *buf) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 452 | { |
| 453 | int length = 0; |
| 454 | const char *p1; |
| 455 | char *p2; |
| 456 | char *last_non_space = buf; |
| 457 | |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 458 | int retval = line6_dump_wait_interruptible(&pod->dumpreq); |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 459 | if (retval < 0) |
| 460 | return retval; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 461 | |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 462 | for (p1 = str, p2 = buf; *p1; ++p1, ++p2) { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 463 | *p2 = *p1; |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 464 | if (*p2 != ' ') |
| 465 | last_non_space = p2; |
| 466 | if (++length == POD_NAME_LENGTH) |
| 467 | break; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | *(last_non_space + 1) = '\n'; |
| 471 | return last_non_space - buf + 2; |
| 472 | } |
| 473 | |
| 474 | /* |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 475 | "read" request on "name" special file. |
| 476 | */ |
Greg Kroah-Hartman | 77491e5 | 2009-02-27 20:25:43 -0800 | [diff] [blame] | 477 | static ssize_t pod_get_name(struct device *dev, struct device_attribute *attr, |
| 478 | char *buf) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 479 | { |
| 480 | struct usb_interface *interface = to_usb_interface(dev); |
| 481 | struct usb_line6_pod *pod = usb_get_intfdata(interface); |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 482 | return get_name_generic(pod, pod->prog_data.header + POD_NAME_OFFSET, |
| 483 | buf); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | /* |
| 487 | "read" request on "name" special file. |
| 488 | */ |
Greg Kroah-Hartman | 77491e5 | 2009-02-27 20:25:43 -0800 | [diff] [blame] | 489 | static ssize_t pod_get_name_buf(struct device *dev, |
| 490 | struct device_attribute *attr, char *buf) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 491 | { |
| 492 | struct usb_interface *interface = to_usb_interface(dev); |
| 493 | struct usb_line6_pod *pod = usb_get_intfdata(interface); |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 494 | return get_name_generic(pod, |
| 495 | pod->prog_data_buf.header + POD_NAME_OFFSET, |
| 496 | buf); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | /* |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 500 | Identify system parameters related to the tuner. |
| 501 | */ |
| 502 | static bool pod_is_tuner(int code) |
| 503 | { |
| 504 | return |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 505 | (code == POD_tuner_mute) || |
| 506 | (code == POD_tuner_freq) || |
| 507 | (code == POD_tuner_note) || (code == POD_tuner_pitch); |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | /* |
| 511 | Get system parameter (as integer). |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 512 | @param tuner non-zero, if code refers to a tuner parameter |
| 513 | */ |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 514 | static int pod_get_system_param_int(struct usb_line6_pod *pod, int *value, |
| 515 | int code, struct ValueWait *param, int sign) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 516 | { |
| 517 | char *sysex; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 518 | static const int size = 1; |
| 519 | int retval = 0; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 520 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 521 | if (((pod->prog_data.control[POD_tuner] & 0x40) == 0) |
| 522 | && pod_is_tuner(code)) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 523 | return -ENODEV; |
| 524 | |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 525 | /* send value request to device: */ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 526 | param->value = POD_system_invalid; |
| 527 | sysex = pod_alloc_sysex_buffer(pod, POD_SYSEX_SYSTEMREQ, size); |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 528 | |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 529 | if (!sysex) |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 530 | return -ENOMEM; |
| 531 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 532 | sysex[SYSEX_DATA_OFS] = code; |
| 533 | line6_send_sysex_message(&pod->line6, sysex, size); |
| 534 | kfree(sysex); |
| 535 | |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 536 | /* wait for device to respond: */ |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 537 | retval = |
| 538 | wait_event_interruptible(param->wait, |
| 539 | param->value != POD_system_invalid); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 540 | |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 541 | if (retval < 0) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 542 | return retval; |
| 543 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 544 | *value = sign ? (int)(signed short)param->value : (int)(unsigned short) |
| 545 | param->value; |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 546 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 547 | if (*value == POD_system_invalid) |
| 548 | *value = 0; /* don't report uninitialized values */ |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 549 | |
| 550 | return 0; |
| 551 | } |
| 552 | |
| 553 | /* |
| 554 | Get system parameter (as string). |
| 555 | @param tuner non-zero, if code refers to a tuner parameter |
| 556 | */ |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 557 | static ssize_t pod_get_system_param_string(struct usb_line6_pod *pod, char *buf, |
| 558 | int code, struct ValueWait *param, |
| 559 | int sign) |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 560 | { |
| 561 | int retval, value = 0; |
| 562 | retval = pod_get_system_param_int(pod, &value, code, param, sign); |
| 563 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 564 | if (retval < 0) |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 565 | return retval; |
| 566 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 567 | return sprintf(buf, "%d\n", value); |
| 568 | } |
| 569 | |
| 570 | /* |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 571 | Send system parameter (from integer). |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 572 | @param tuner non-zero, if code refers to a tuner parameter |
| 573 | */ |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 574 | static int pod_set_system_param_int(struct usb_line6_pod *pod, int value, |
| 575 | int code) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 576 | { |
| 577 | char *sysex; |
| 578 | static const int size = 5; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 579 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 580 | if (((pod->prog_data.control[POD_tuner] & 0x40) == 0) |
| 581 | && pod_is_tuner(code)) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 582 | return -EINVAL; |
| 583 | |
| 584 | /* send value to tuner: */ |
| 585 | sysex = pod_alloc_sysex_buffer(pod, POD_SYSEX_SYSTEM, size); |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 586 | if (!sysex) |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 587 | return -ENOMEM; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 588 | sysex[SYSEX_DATA_OFS] = code; |
| 589 | sysex[SYSEX_DATA_OFS + 1] = (value >> 12) & 0x0f; |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 590 | sysex[SYSEX_DATA_OFS + 2] = (value >> 8) & 0x0f; |
| 591 | sysex[SYSEX_DATA_OFS + 3] = (value >> 4) & 0x0f; |
| 592 | sysex[SYSEX_DATA_OFS + 4] = (value) & 0x0f; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 593 | line6_send_sysex_message(&pod->line6, sysex, size); |
| 594 | kfree(sysex); |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 595 | return 0; |
| 596 | } |
| 597 | |
| 598 | /* |
| 599 | Send system parameter (from string). |
| 600 | @param tuner non-zero, if code refers to a tuner parameter |
| 601 | */ |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 602 | static ssize_t pod_set_system_param_string(struct usb_line6_pod *pod, |
| 603 | const char *buf, int count, int code, |
| 604 | unsigned short mask) |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 605 | { |
| 606 | int retval; |
| 607 | unsigned short value = simple_strtoul(buf, NULL, 10) & mask; |
| 608 | retval = pod_set_system_param_int(pod, value, code); |
| 609 | return (retval < 0) ? retval : count; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | /* |
| 613 | "read" request on "dump_buf" special file. |
| 614 | */ |
Greg Kroah-Hartman | 77491e5 | 2009-02-27 20:25:43 -0800 | [diff] [blame] | 615 | static ssize_t pod_get_dump_buf(struct device *dev, |
| 616 | struct device_attribute *attr, char *buf) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 617 | { |
| 618 | struct usb_interface *interface = to_usb_interface(dev); |
| 619 | struct usb_line6_pod *pod = usb_get_intfdata(interface); |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 620 | int retval = line6_dump_wait_interruptible(&pod->dumpreq); |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 621 | if (retval < 0) |
| 622 | return retval; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 623 | memcpy(buf, &pod->prog_data_buf, sizeof(pod->prog_data_buf)); |
| 624 | return sizeof(pod->prog_data_buf); |
| 625 | } |
| 626 | |
| 627 | /* |
| 628 | "write" request on "dump_buf" special file. |
| 629 | */ |
Greg Kroah-Hartman | 77491e5 | 2009-02-27 20:25:43 -0800 | [diff] [blame] | 630 | static ssize_t pod_set_dump_buf(struct device *dev, |
| 631 | struct device_attribute *attr, |
| 632 | const char *buf, size_t count) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 633 | { |
| 634 | struct usb_interface *interface = to_usb_interface(dev); |
| 635 | struct usb_line6_pod *pod = usb_get_intfdata(interface); |
| 636 | |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 637 | if (count != sizeof(pod->prog_data)) { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 638 | dev_err(pod->line6.ifcdev, |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 639 | "data block must be exactly %d bytes\n", |
| 640 | (int)sizeof(pod->prog_data)); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 641 | return -EINVAL; |
| 642 | } |
| 643 | |
| 644 | memcpy(&pod->prog_data_buf, buf, sizeof(pod->prog_data)); |
| 645 | return sizeof(pod->prog_data); |
| 646 | } |
| 647 | |
| 648 | /* |
| 649 | "write" request on "finish" special file. |
| 650 | */ |
Greg Kroah-Hartman | 77491e5 | 2009-02-27 20:25:43 -0800 | [diff] [blame] | 651 | static ssize_t pod_set_finish(struct device *dev, |
| 652 | struct device_attribute *attr, |
| 653 | const char *buf, size_t count) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 654 | { |
| 655 | struct usb_interface *interface = to_usb_interface(dev); |
| 656 | struct usb_line6_pod *pod = usb_get_intfdata(interface); |
| 657 | int size = 0; |
| 658 | char *sysex = pod_alloc_sysex_buffer(pod, POD_SYSEX_FINISH, size); |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 659 | if (!sysex) |
| 660 | return 0; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 661 | line6_send_sysex_message(&pod->line6, sysex, size); |
| 662 | kfree(sysex); |
| 663 | return count; |
| 664 | } |
| 665 | |
| 666 | /* |
| 667 | "write" request on "store_channel" special file. |
| 668 | */ |
Greg Kroah-Hartman | 77491e5 | 2009-02-27 20:25:43 -0800 | [diff] [blame] | 669 | static ssize_t pod_set_store_channel(struct device *dev, |
| 670 | struct device_attribute *attr, |
| 671 | const char *buf, size_t count) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 672 | { |
| 673 | return pod_send_store_command(dev, buf, count, 0x0000, 0x00c0); |
| 674 | } |
| 675 | |
| 676 | /* |
| 677 | "write" request on "store_effects_setup" special file. |
| 678 | */ |
Greg Kroah-Hartman | 77491e5 | 2009-02-27 20:25:43 -0800 | [diff] [blame] | 679 | static ssize_t pod_set_store_effects_setup(struct device *dev, |
| 680 | struct device_attribute *attr, |
| 681 | const char *buf, size_t count) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 682 | { |
| 683 | return pod_send_store_command(dev, buf, count, 0x0080, 0x0080); |
| 684 | } |
| 685 | |
| 686 | /* |
| 687 | "write" request on "store_amp_setup" special file. |
| 688 | */ |
Greg Kroah-Hartman | 77491e5 | 2009-02-27 20:25:43 -0800 | [diff] [blame] | 689 | static ssize_t pod_set_store_amp_setup(struct device *dev, |
| 690 | struct device_attribute *attr, |
| 691 | const char *buf, size_t count) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 692 | { |
| 693 | return pod_send_store_command(dev, buf, count, 0x0040, 0x0100); |
| 694 | } |
| 695 | |
| 696 | /* |
| 697 | "write" request on "retrieve_channel" special file. |
| 698 | */ |
Greg Kroah-Hartman | 77491e5 | 2009-02-27 20:25:43 -0800 | [diff] [blame] | 699 | static ssize_t pod_set_retrieve_channel(struct device *dev, |
| 700 | struct device_attribute *attr, |
| 701 | const char *buf, size_t count) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 702 | { |
| 703 | return pod_send_retrieve_command(dev, buf, count, 0x0000, 0x00c0); |
| 704 | } |
| 705 | |
| 706 | /* |
| 707 | "write" request on "retrieve_effects_setup" special file. |
| 708 | */ |
Greg Kroah-Hartman | 77491e5 | 2009-02-27 20:25:43 -0800 | [diff] [blame] | 709 | static ssize_t pod_set_retrieve_effects_setup(struct device *dev, |
| 710 | struct device_attribute *attr, |
| 711 | const char *buf, size_t count) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 712 | { |
| 713 | return pod_send_retrieve_command(dev, buf, count, 0x0080, 0x0080); |
| 714 | } |
| 715 | |
| 716 | /* |
| 717 | "write" request on "retrieve_amp_setup" special file. |
| 718 | */ |
Greg Kroah-Hartman | 77491e5 | 2009-02-27 20:25:43 -0800 | [diff] [blame] | 719 | static ssize_t pod_set_retrieve_amp_setup(struct device *dev, |
| 720 | struct device_attribute *attr, |
| 721 | const char *buf, size_t count) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 722 | { |
| 723 | return pod_send_retrieve_command(dev, buf, count, 0x0040, 0x0100); |
| 724 | } |
| 725 | |
| 726 | /* |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 727 | "read" request on "midi_postprocess" special file. |
| 728 | */ |
Greg Kroah-Hartman | 77491e5 | 2009-02-27 20:25:43 -0800 | [diff] [blame] | 729 | static ssize_t pod_get_midi_postprocess(struct device *dev, |
| 730 | struct device_attribute *attr, |
| 731 | char *buf) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 732 | { |
| 733 | struct usb_interface *interface = to_usb_interface(dev); |
| 734 | struct usb_line6_pod *pod = usb_get_intfdata(interface); |
| 735 | return sprintf(buf, "%d\n", pod->midi_postprocess); |
| 736 | } |
| 737 | |
| 738 | /* |
| 739 | "write" request on "midi_postprocess" special file. |
| 740 | */ |
Greg Kroah-Hartman | 77491e5 | 2009-02-27 20:25:43 -0800 | [diff] [blame] | 741 | static ssize_t pod_set_midi_postprocess(struct device *dev, |
| 742 | struct device_attribute *attr, |
| 743 | const char *buf, size_t count) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 744 | { |
| 745 | struct usb_interface *interface = to_usb_interface(dev); |
| 746 | struct usb_line6_pod *pod = usb_get_intfdata(interface); |
Johannes Thumshirn | 0650178 | 2012-06-27 21:26:03 +0200 | [diff] [blame] | 747 | u8 value; |
Shawn Bohrer | 7e4d5c1 | 2009-11-15 22:18:01 -0600 | [diff] [blame] | 748 | int ret; |
| 749 | |
Johannes Thumshirn | 0650178 | 2012-06-27 21:26:03 +0200 | [diff] [blame] | 750 | ret = kstrtou8(buf, 10, &value); |
Shawn Bohrer | 7e4d5c1 | 2009-11-15 22:18:01 -0600 | [diff] [blame] | 751 | if (ret) |
| 752 | return ret; |
| 753 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 754 | pod->midi_postprocess = value ? 1 : 0; |
| 755 | return count; |
| 756 | } |
| 757 | |
| 758 | /* |
| 759 | "read" request on "serial_number" special file. |
| 760 | */ |
Greg Kroah-Hartman | 77491e5 | 2009-02-27 20:25:43 -0800 | [diff] [blame] | 761 | static ssize_t pod_get_serial_number(struct device *dev, |
| 762 | struct device_attribute *attr, char *buf) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 763 | { |
| 764 | struct usb_interface *interface = to_usb_interface(dev); |
| 765 | struct usb_line6_pod *pod = usb_get_intfdata(interface); |
| 766 | return sprintf(buf, "%d\n", pod->serial_number); |
| 767 | } |
| 768 | |
| 769 | /* |
| 770 | "read" request on "firmware_version" special file. |
| 771 | */ |
Greg Kroah-Hartman | 77491e5 | 2009-02-27 20:25:43 -0800 | [diff] [blame] | 772 | static ssize_t pod_get_firmware_version(struct device *dev, |
| 773 | struct device_attribute *attr, |
| 774 | char *buf) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 775 | { |
| 776 | struct usb_interface *interface = to_usb_interface(dev); |
| 777 | struct usb_line6_pod *pod = usb_get_intfdata(interface); |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 778 | return sprintf(buf, "%d.%02d\n", pod->firmware_version / 100, |
| 779 | pod->firmware_version % 100); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | /* |
| 783 | "read" request on "device_id" special file. |
| 784 | */ |
Greg Kroah-Hartman | 77491e5 | 2009-02-27 20:25:43 -0800 | [diff] [blame] | 785 | static ssize_t pod_get_device_id(struct device *dev, |
| 786 | struct device_attribute *attr, char *buf) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 787 | { |
| 788 | struct usb_interface *interface = to_usb_interface(dev); |
| 789 | struct usb_line6_pod *pod = usb_get_intfdata(interface); |
| 790 | return sprintf(buf, "%d\n", pod->device_id); |
| 791 | } |
| 792 | |
| 793 | /* |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 794 | POD startup procedure. |
| 795 | This is a sequence of functions with special requirements (e.g., must |
| 796 | not run immediately after initialization, must not run in interrupt |
| 797 | context). After the last one has finished, the device is ready to use. |
| 798 | */ |
| 799 | |
| 800 | static void pod_startup1(struct usb_line6_pod *pod) |
| 801 | { |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 802 | CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_INIT); |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 803 | |
| 804 | /* delay startup procedure: */ |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 805 | line6_start_timer(&pod->startup_timer, POD_STARTUP_DELAY, pod_startup2, |
| 806 | (unsigned long)pod); |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | static void pod_startup2(unsigned long data) |
| 810 | { |
| 811 | struct usb_line6_pod *pod = (struct usb_line6_pod *)data; |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 812 | |
| 813 | /* schedule another startup procedure until startup is complete: */ |
| 814 | if (pod->startup_progress >= POD_STARTUP_LAST) |
| 815 | return; |
| 816 | |
| 817 | pod->startup_progress = POD_STARTUP_DUMPREQ; |
| 818 | line6_start_timer(&pod->startup_timer, POD_STARTUP_DELAY, pod_startup2, |
| 819 | (unsigned long)pod); |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 820 | |
| 821 | /* current channel dump: */ |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 822 | line6_dump_request_async(&pod->dumpreq, &pod->line6, 0, |
| 823 | LINE6_DUMP_CURRENT); |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | static void pod_startup3(struct usb_line6_pod *pod) |
| 827 | { |
| 828 | struct usb_line6 *line6 = &pod->line6; |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 829 | CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_VERSIONREQ); |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 830 | |
| 831 | /* request firmware version: */ |
| 832 | line6_version_request_async(line6); |
| 833 | } |
| 834 | |
| 835 | static void pod_startup4(struct usb_line6_pod *pod) |
| 836 | { |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 837 | CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_WORKQUEUE); |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 838 | |
| 839 | /* schedule work for global work queue: */ |
| 840 | schedule_work(&pod->startup_work); |
| 841 | } |
| 842 | |
| 843 | static void pod_startup5(struct work_struct *work) |
| 844 | { |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 845 | struct usb_line6_pod *pod = |
| 846 | container_of(work, struct usb_line6_pod, startup_work); |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 847 | struct usb_line6 *line6 = &pod->line6; |
| 848 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 849 | CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_SETUP); |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 850 | |
| 851 | /* serial number: */ |
| 852 | line6_read_serial_number(&pod->line6, &pod->serial_number); |
| 853 | |
| 854 | /* ALSA audio interface: */ |
| 855 | line6_register_audio(line6); |
| 856 | |
| 857 | /* device files: */ |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 858 | line6_pod_create_files(pod->firmware_version, |
| 859 | line6->properties->device_bit, line6->ifcdev); |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | #define POD_GET_SYSTEM_PARAM(code, sign) \ |
Greg Kroah-Hartman | 77491e5 | 2009-02-27 20:25:43 -0800 | [diff] [blame] | 863 | static ssize_t pod_get_ ## code(struct device *dev, \ |
| 864 | struct device_attribute *attr, char *buf) \ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 865 | { \ |
| 866 | struct usb_interface *interface = to_usb_interface(dev); \ |
| 867 | struct usb_line6_pod *pod = usb_get_intfdata(interface); \ |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 868 | return pod_get_system_param_string(pod, buf, POD_ ## code, \ |
| 869 | &pod->code, sign); \ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 870 | } |
| 871 | |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 872 | #define POD_GET_SET_SYSTEM_PARAM(code, mask, sign) \ |
| 873 | POD_GET_SYSTEM_PARAM(code, sign) \ |
Greg Kroah-Hartman | 77491e5 | 2009-02-27 20:25:43 -0800 | [diff] [blame] | 874 | static ssize_t pod_set_ ## code(struct device *dev, \ |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 875 | struct device_attribute *attr, \ |
| 876 | const char *buf, size_t count) \ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 877 | { \ |
| 878 | struct usb_interface *interface = to_usb_interface(dev); \ |
| 879 | struct usb_line6_pod *pod = usb_get_intfdata(interface); \ |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 880 | return pod_set_system_param_string(pod, buf, count, POD_ ## code, mask); \ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 881 | } |
| 882 | |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 883 | POD_GET_SET_SYSTEM_PARAM(monitor_level, 0xffff, 0); |
| 884 | POD_GET_SET_SYSTEM_PARAM(routing, 0x0003, 0); |
| 885 | POD_GET_SET_SYSTEM_PARAM(tuner_mute, 0x0001, 0); |
| 886 | POD_GET_SET_SYSTEM_PARAM(tuner_freq, 0xffff, 0); |
| 887 | POD_GET_SYSTEM_PARAM(tuner_note, 1); |
| 888 | POD_GET_SYSTEM_PARAM(tuner_pitch, 1); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 889 | |
| 890 | #undef GET_SET_SYSTEM_PARAM |
| 891 | #undef GET_SYSTEM_PARAM |
| 892 | |
| 893 | /* POD special files: */ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 894 | static DEVICE_ATTR(device_id, S_IRUGO, pod_get_device_id, line6_nop_write); |
Greg Kroah-Hartman | a3a972a | 2010-11-18 11:21:04 -0800 | [diff] [blame] | 895 | static DEVICE_ATTR(dump_buf, S_IWUSR | S_IRUGO, pod_get_dump_buf, |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 896 | pod_set_dump_buf); |
Greg Kroah-Hartman | a3a972a | 2010-11-18 11:21:04 -0800 | [diff] [blame] | 897 | static DEVICE_ATTR(finish, S_IWUSR, line6_nop_read, pod_set_finish); |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 898 | static DEVICE_ATTR(firmware_version, S_IRUGO, pod_get_firmware_version, |
| 899 | line6_nop_write); |
Greg Kroah-Hartman | a3a972a | 2010-11-18 11:21:04 -0800 | [diff] [blame] | 900 | static DEVICE_ATTR(midi_postprocess, S_IWUSR | S_IRUGO, |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 901 | pod_get_midi_postprocess, pod_set_midi_postprocess); |
Greg Kroah-Hartman | a3a972a | 2010-11-18 11:21:04 -0800 | [diff] [blame] | 902 | static DEVICE_ATTR(monitor_level, S_IWUSR | S_IRUGO, pod_get_monitor_level, |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 903 | pod_set_monitor_level); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 904 | static DEVICE_ATTR(name, S_IRUGO, pod_get_name, line6_nop_write); |
| 905 | static DEVICE_ATTR(name_buf, S_IRUGO, pod_get_name_buf, line6_nop_write); |
Greg Kroah-Hartman | a3a972a | 2010-11-18 11:21:04 -0800 | [diff] [blame] | 906 | static DEVICE_ATTR(retrieve_amp_setup, S_IWUSR, line6_nop_read, |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 907 | pod_set_retrieve_amp_setup); |
Greg Kroah-Hartman | a3a972a | 2010-11-18 11:21:04 -0800 | [diff] [blame] | 908 | static DEVICE_ATTR(retrieve_channel, S_IWUSR, line6_nop_read, |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 909 | pod_set_retrieve_channel); |
Greg Kroah-Hartman | a3a972a | 2010-11-18 11:21:04 -0800 | [diff] [blame] | 910 | static DEVICE_ATTR(retrieve_effects_setup, S_IWUSR, line6_nop_read, |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 911 | pod_set_retrieve_effects_setup); |
Greg Kroah-Hartman | a3a972a | 2010-11-18 11:21:04 -0800 | [diff] [blame] | 912 | static DEVICE_ATTR(routing, S_IWUSR | S_IRUGO, pod_get_routing, |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 913 | pod_set_routing); |
| 914 | static DEVICE_ATTR(serial_number, S_IRUGO, pod_get_serial_number, |
| 915 | line6_nop_write); |
Greg Kroah-Hartman | a3a972a | 2010-11-18 11:21:04 -0800 | [diff] [blame] | 916 | static DEVICE_ATTR(store_amp_setup, S_IWUSR, line6_nop_read, |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 917 | pod_set_store_amp_setup); |
Greg Kroah-Hartman | a3a972a | 2010-11-18 11:21:04 -0800 | [diff] [blame] | 918 | static DEVICE_ATTR(store_channel, S_IWUSR, line6_nop_read, |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 919 | pod_set_store_channel); |
Greg Kroah-Hartman | a3a972a | 2010-11-18 11:21:04 -0800 | [diff] [blame] | 920 | static DEVICE_ATTR(store_effects_setup, S_IWUSR, line6_nop_read, |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 921 | pod_set_store_effects_setup); |
Greg Kroah-Hartman | a3a972a | 2010-11-18 11:21:04 -0800 | [diff] [blame] | 922 | static DEVICE_ATTR(tuner_freq, S_IWUSR | S_IRUGO, pod_get_tuner_freq, |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 923 | pod_set_tuner_freq); |
Greg Kroah-Hartman | a3a972a | 2010-11-18 11:21:04 -0800 | [diff] [blame] | 924 | static DEVICE_ATTR(tuner_mute, S_IWUSR | S_IRUGO, pod_get_tuner_mute, |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 925 | pod_set_tuner_mute); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 926 | static DEVICE_ATTR(tuner_note, S_IRUGO, pod_get_tuner_note, line6_nop_write); |
| 927 | static DEVICE_ATTR(tuner_pitch, S_IRUGO, pod_get_tuner_pitch, line6_nop_write); |
| 928 | |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 929 | #ifdef CONFIG_LINE6_USB_RAW |
Greg Kroah-Hartman | a3a972a | 2010-11-18 11:21:04 -0800 | [diff] [blame] | 930 | static DEVICE_ATTR(raw, S_IWUSR, line6_nop_read, line6_set_raw); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 931 | #endif |
| 932 | |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 933 | /* control info callback */ |
| 934 | static int snd_pod_control_monitor_info(struct snd_kcontrol *kcontrol, |
| 935 | struct snd_ctl_elem_info *uinfo) |
| 936 | { |
| 937 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 938 | uinfo->count = 1; |
| 939 | uinfo->value.integer.min = 0; |
| 940 | uinfo->value.integer.max = 65535; |
| 941 | return 0; |
| 942 | } |
| 943 | |
| 944 | /* control get callback */ |
| 945 | static int snd_pod_control_monitor_get(struct snd_kcontrol *kcontrol, |
| 946 | struct snd_ctl_elem_value *ucontrol) |
| 947 | { |
| 948 | struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol); |
| 949 | struct usb_line6_pod *pod = (struct usb_line6_pod *)line6pcm->line6; |
| 950 | ucontrol->value.integer.value[0] = pod->monitor_level.value; |
| 951 | return 0; |
| 952 | } |
| 953 | |
| 954 | /* control put callback */ |
| 955 | static int snd_pod_control_monitor_put(struct snd_kcontrol *kcontrol, |
| 956 | struct snd_ctl_elem_value *ucontrol) |
| 957 | { |
| 958 | struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol); |
| 959 | struct usb_line6_pod *pod = (struct usb_line6_pod *)line6pcm->line6; |
| 960 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 961 | if (ucontrol->value.integer.value[0] == pod->monitor_level.value) |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 962 | return 0; |
| 963 | |
| 964 | pod->monitor_level.value = ucontrol->value.integer.value[0]; |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 965 | pod_set_system_param_int(pod, ucontrol->value.integer.value[0], |
| 966 | POD_monitor_level); |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 967 | return 1; |
| 968 | } |
| 969 | |
| 970 | /* control definition */ |
| 971 | static struct snd_kcontrol_new pod_control_monitor = { |
| 972 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 973 | .name = "Monitor Playback Volume", |
| 974 | .index = 0, |
| 975 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, |
| 976 | .info = snd_pod_control_monitor_info, |
| 977 | .get = snd_pod_control_monitor_get, |
| 978 | .put = snd_pod_control_monitor_put |
| 979 | }; |
| 980 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 981 | /* |
| 982 | POD destructor. |
| 983 | */ |
| 984 | static void pod_destruct(struct usb_interface *interface) |
| 985 | { |
| 986 | struct usb_line6_pod *pod = usb_get_intfdata(interface); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 987 | |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 988 | if (pod == NULL) |
| 989 | return; |
Stefan Hajnoczi | 188e664 | 2011-12-10 02:12:30 +0100 | [diff] [blame] | 990 | line6_cleanup_audio(&pod->line6); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 991 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 992 | del_timer(&pod->startup_timer); |
| 993 | cancel_work_sync(&pod->startup_work); |
| 994 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 995 | /* free dump request data: */ |
| 996 | line6_dumpreq_destruct(&pod->dumpreq); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 997 | } |
| 998 | |
| 999 | /* |
| 1000 | Create sysfs entries. |
| 1001 | */ |
Greg Kroah-Hartman | b702ed25 | 2009-02-27 20:45:03 -0800 | [diff] [blame] | 1002 | static int pod_create_files2(struct device *dev) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1003 | { |
| 1004 | int err; |
| 1005 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1006 | CHECK_RETURN(device_create_file(dev, &dev_attr_device_id)); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1007 | CHECK_RETURN(device_create_file(dev, &dev_attr_dump_buf)); |
| 1008 | CHECK_RETURN(device_create_file(dev, &dev_attr_finish)); |
| 1009 | CHECK_RETURN(device_create_file(dev, &dev_attr_firmware_version)); |
| 1010 | CHECK_RETURN(device_create_file(dev, &dev_attr_midi_postprocess)); |
| 1011 | CHECK_RETURN(device_create_file(dev, &dev_attr_monitor_level)); |
| 1012 | CHECK_RETURN(device_create_file(dev, &dev_attr_name)); |
| 1013 | CHECK_RETURN(device_create_file(dev, &dev_attr_name_buf)); |
| 1014 | CHECK_RETURN(device_create_file(dev, &dev_attr_retrieve_amp_setup)); |
| 1015 | CHECK_RETURN(device_create_file(dev, &dev_attr_retrieve_channel)); |
| 1016 | CHECK_RETURN(device_create_file(dev, &dev_attr_retrieve_effects_setup)); |
| 1017 | CHECK_RETURN(device_create_file(dev, &dev_attr_routing)); |
| 1018 | CHECK_RETURN(device_create_file(dev, &dev_attr_serial_number)); |
| 1019 | CHECK_RETURN(device_create_file(dev, &dev_attr_store_amp_setup)); |
| 1020 | CHECK_RETURN(device_create_file(dev, &dev_attr_store_channel)); |
| 1021 | CHECK_RETURN(device_create_file(dev, &dev_attr_store_effects_setup)); |
| 1022 | CHECK_RETURN(device_create_file(dev, &dev_attr_tuner_freq)); |
| 1023 | CHECK_RETURN(device_create_file(dev, &dev_attr_tuner_mute)); |
| 1024 | CHECK_RETURN(device_create_file(dev, &dev_attr_tuner_note)); |
| 1025 | CHECK_RETURN(device_create_file(dev, &dev_attr_tuner_pitch)); |
| 1026 | |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 1027 | #ifdef CONFIG_LINE6_USB_RAW |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1028 | CHECK_RETURN(device_create_file(dev, &dev_attr_raw)); |
| 1029 | #endif |
| 1030 | |
| 1031 | return 0; |
| 1032 | } |
| 1033 | |
| 1034 | /* |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 1035 | Try to init POD device. |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1036 | */ |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 1037 | static int pod_try_init(struct usb_interface *interface, |
| 1038 | struct usb_line6_pod *pod) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1039 | { |
| 1040 | int err; |
| 1041 | struct usb_line6 *line6 = &pod->line6; |
| 1042 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 1043 | init_timer(&pod->startup_timer); |
| 1044 | INIT_WORK(&pod->startup_work, pod_startup5); |
| 1045 | |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 1046 | if ((interface == NULL) || (pod == NULL)) |
| 1047 | return -ENODEV; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1048 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1049 | /* initialize wait queues: */ |
| 1050 | init_waitqueue_head(&pod->monitor_level.wait); |
| 1051 | init_waitqueue_head(&pod->routing.wait); |
| 1052 | init_waitqueue_head(&pod->tuner_mute.wait); |
| 1053 | init_waitqueue_head(&pod->tuner_freq.wait); |
| 1054 | init_waitqueue_head(&pod->tuner_note.wait); |
| 1055 | init_waitqueue_head(&pod->tuner_pitch.wait); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1056 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1057 | /* initialize USB buffers: */ |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 1058 | err = line6_dumpreq_init(&pod->dumpreq, pod_request_channel, |
| 1059 | sizeof(pod_request_channel)); |
| 1060 | if (err < 0) { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1061 | dev_err(&interface->dev, "Out of memory\n"); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1062 | return -ENOMEM; |
| 1063 | } |
| 1064 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1065 | /* create sysfs entries: */ |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 1066 | err = pod_create_files2(&interface->dev); |
Greg Kroah-Hartman | 027360c | 2010-09-21 16:58:00 -0700 | [diff] [blame] | 1067 | if (err < 0) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1068 | return err; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1069 | |
| 1070 | /* initialize audio system: */ |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 1071 | err = line6_init_audio(line6); |
Greg Kroah-Hartman | 027360c | 2010-09-21 16:58:00 -0700 | [diff] [blame] | 1072 | if (err < 0) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1073 | return err; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1074 | |
| 1075 | /* initialize MIDI subsystem: */ |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 1076 | err = line6_init_midi(line6); |
Greg Kroah-Hartman | 027360c | 2010-09-21 16:58:00 -0700 | [diff] [blame] | 1077 | if (err < 0) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1078 | return err; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1079 | |
| 1080 | /* initialize PCM subsystem: */ |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 1081 | err = line6_init_pcm(line6, &pod_pcm_properties); |
Greg Kroah-Hartman | 027360c | 2010-09-21 16:58:00 -0700 | [diff] [blame] | 1082 | if (err < 0) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1083 | return err; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1084 | |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 1085 | /* register monitor control: */ |
Greg Kroah-Hartman | 027360c | 2010-09-21 16:58:00 -0700 | [diff] [blame] | 1086 | err = snd_ctl_add(line6->card, |
| 1087 | snd_ctl_new1(&pod_control_monitor, line6->line6pcm)); |
| 1088 | if (err < 0) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1089 | return err; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1090 | |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 1091 | /* |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 1092 | When the sound card is registered at this point, the PODxt Live |
| 1093 | displays "Invalid Code Error 07", so we do it later in the event |
| 1094 | handler. |
| 1095 | */ |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 1096 | |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 1097 | if (pod->line6.properties->capabilities & LINE6_BIT_CONTROL) { |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 1098 | pod->monitor_level.value = POD_system_invalid; |
| 1099 | |
| 1100 | /* initiate startup procedure: */ |
| 1101 | pod_startup1(pod); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1102 | } |
| 1103 | |
| 1104 | return 0; |
| 1105 | } |
| 1106 | |
| 1107 | /* |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 1108 | Init POD device (and clean up in case of failure). |
| 1109 | */ |
| 1110 | int line6_pod_init(struct usb_interface *interface, struct usb_line6_pod *pod) |
| 1111 | { |
| 1112 | int err = pod_try_init(interface, pod); |
| 1113 | |
Greg Kroah-Hartman | 027360c | 2010-09-21 16:58:00 -0700 | [diff] [blame] | 1114 | if (err < 0) |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 1115 | pod_destruct(interface); |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 1116 | |
| 1117 | return err; |
| 1118 | } |
| 1119 | |
| 1120 | /* |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1121 | POD device disconnected. |
| 1122 | */ |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 1123 | void line6_pod_disconnect(struct usb_interface *interface) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1124 | { |
| 1125 | struct usb_line6_pod *pod; |
| 1126 | |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 1127 | if (interface == NULL) |
| 1128 | return; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1129 | pod = usb_get_intfdata(interface); |
| 1130 | |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 1131 | if (pod != NULL) { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1132 | struct snd_line6_pcm *line6pcm = pod->line6.line6pcm; |
| 1133 | struct device *dev = &interface->dev; |
| 1134 | |
Greg Kroah-Hartman | 027360c | 2010-09-21 16:58:00 -0700 | [diff] [blame] | 1135 | if (line6pcm != NULL) |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 1136 | line6_pcm_disconnect(line6pcm); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1137 | |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 1138 | if (dev != NULL) { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1139 | /* remove sysfs entries: */ |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 1140 | line6_pod_remove_files(pod->firmware_version, |
| 1141 | pod->line6. |
| 1142 | properties->device_bit, dev); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1143 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1144 | device_remove_file(dev, &dev_attr_device_id); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1145 | device_remove_file(dev, &dev_attr_dump_buf); |
| 1146 | device_remove_file(dev, &dev_attr_finish); |
| 1147 | device_remove_file(dev, &dev_attr_firmware_version); |
| 1148 | device_remove_file(dev, &dev_attr_midi_postprocess); |
| 1149 | device_remove_file(dev, &dev_attr_monitor_level); |
| 1150 | device_remove_file(dev, &dev_attr_name); |
| 1151 | device_remove_file(dev, &dev_attr_name_buf); |
| 1152 | device_remove_file(dev, &dev_attr_retrieve_amp_setup); |
| 1153 | device_remove_file(dev, &dev_attr_retrieve_channel); |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 1154 | device_remove_file(dev, |
| 1155 | &dev_attr_retrieve_effects_setup); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1156 | device_remove_file(dev, &dev_attr_routing); |
| 1157 | device_remove_file(dev, &dev_attr_serial_number); |
| 1158 | device_remove_file(dev, &dev_attr_store_amp_setup); |
| 1159 | device_remove_file(dev, &dev_attr_store_channel); |
| 1160 | device_remove_file(dev, &dev_attr_store_effects_setup); |
| 1161 | device_remove_file(dev, &dev_attr_tuner_freq); |
| 1162 | device_remove_file(dev, &dev_attr_tuner_mute); |
| 1163 | device_remove_file(dev, &dev_attr_tuner_note); |
| 1164 | device_remove_file(dev, &dev_attr_tuner_pitch); |
| 1165 | |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 1166 | #ifdef CONFIG_LINE6_USB_RAW |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1167 | device_remove_file(dev, &dev_attr_raw); |
| 1168 | #endif |
| 1169 | } |
| 1170 | } |
| 1171 | |
| 1172 | pod_destruct(interface); |
| 1173 | } |