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]) { |
Stefan Hajnoczi | 410cefa | 2012-11-22 20:48:46 +0100 | [diff] [blame] | 247 | case POD_monitor_level: |
Stefan Hajnoczi | 2c35dc2 | 2012-11-22 20:48:47 +0100 | [diff] [blame^] | 248 | pod->monitor_level = value; |
Stefan Hajnoczi | 410cefa | 2012-11-22 20:48:46 +0100 | [diff] [blame] | 249 | break; |
| 250 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 251 | PROCESS_SYSTEM_PARAM(routing); |
| 252 | PROCESS_SYSTEM_PARAM |
| 253 | (tuner_mute); |
| 254 | PROCESS_SYSTEM_PARAM |
| 255 | (tuner_freq); |
| 256 | PROCESS_SYSTEM_PARAM |
| 257 | (tuner_note); |
| 258 | PROCESS_SYSTEM_PARAM |
| 259 | (tuner_pitch); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 260 | |
| 261 | #undef PROCESS_SYSTEM_PARAM |
| 262 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 263 | default: |
Stefan Hajnoczi | e00d33c | 2012-11-11 13:52:24 +0100 | [diff] [blame] | 264 | dev_dbg(pod->line6.ifcdev, |
| 265 | "unknown tuner/system response %02X\n", |
| 266 | buf[6]); |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 267 | } |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 268 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 269 | break; |
| 270 | } |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 271 | |
| 272 | case POD_SYSEX_FINISH: |
| 273 | /* do we need to respond to this? */ |
| 274 | break; |
| 275 | |
| 276 | case POD_SYSEX_SAVE: |
| 277 | pod_save_button_pressed(pod, buf[6], buf[7]); |
| 278 | break; |
| 279 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 280 | case POD_SYSEX_STORE: |
Stefan Hajnoczi | e00d33c | 2012-11-11 13:52:24 +0100 | [diff] [blame] | 281 | dev_dbg(pod->line6.ifcdev, |
| 282 | "message %02X not yet implemented\n", |
| 283 | buf[5]); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 284 | break; |
| 285 | |
| 286 | default: |
Stefan Hajnoczi | e00d33c | 2012-11-11 13:52:24 +0100 | [diff] [blame] | 287 | dev_dbg(pod->line6.ifcdev, |
| 288 | "unknown sysex message %02X\n", |
| 289 | buf[5]); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 290 | } |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 291 | } else |
| 292 | if (memcmp |
| 293 | (buf, pod_version_header, |
| 294 | sizeof(pod_version_header)) == 0) { |
| 295 | pod->firmware_version = |
| 296 | buf[13] * 100 + buf[14] * 10 + buf[15]; |
| 297 | pod->device_id = |
| 298 | ((int)buf[8] << 16) | ((int)buf[9] << 8) | (int) |
| 299 | buf[10]; |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 300 | pod_startup4(pod); |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 301 | } else |
Stefan Hajnoczi | e00d33c | 2012-11-11 13:52:24 +0100 | [diff] [blame] | 302 | dev_dbg(pod->line6.ifcdev, "unknown sysex header\n"); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 303 | |
| 304 | break; |
| 305 | |
| 306 | case LINE6_SYSEX_END: |
| 307 | break; |
| 308 | |
| 309 | default: |
Stefan Hajnoczi | e00d33c | 2012-11-11 13:52:24 +0100 | [diff] [blame] | 310 | dev_dbg(pod->line6.ifcdev, "POD: unknown message %02X\n", |
| 311 | buf[0]); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 312 | } |
| 313 | } |
| 314 | |
| 315 | /* |
| 316 | Detect some cases that require a channel dump after sending a command to the |
| 317 | device. Important notes: |
| 318 | *) The actual dump request can not be sent here since we are not allowed to |
| 319 | wait for the completion of the first message in this context, and sending |
| 320 | the dump request before completion of the previous message leaves the POD |
| 321 | in an undefined state. The dump request will be sent when the echoed |
| 322 | commands are received. |
| 323 | *) This method fails if a param change message is "chopped" after the first |
| 324 | byte. |
| 325 | */ |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 326 | void line6_pod_midi_postprocess(struct usb_line6_pod *pod, unsigned char *data, |
| 327 | int length) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 328 | { |
| 329 | int i; |
| 330 | |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 331 | if (!pod->midi_postprocess) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 332 | return; |
| 333 | |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 334 | for (i = 0; i < length; ++i) { |
| 335 | if (data[i] == (LINE6_PROGRAM_CHANGE | LINE6_CHANNEL_HOST)) { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 336 | line6_invalidate_current(&pod->dumpreq); |
| 337 | break; |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 338 | } else |
| 339 | if ((data[i] == (LINE6_PARAM_CHANGE | LINE6_CHANNEL_HOST)) |
| 340 | && (i < length - 1)) |
| 341 | if ((data[i + 1] == POD_amp_model_setup) |
| 342 | || (data[i + 1] == POD_effect_setup)) { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 343 | line6_invalidate_current(&pod->dumpreq); |
| 344 | break; |
| 345 | } |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | /* |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 350 | Transmit PODxt Pro control parameter. |
| 351 | */ |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 352 | void line6_pod_transmit_parameter(struct usb_line6_pod *pod, int param, |
Johannes Thumshirn | 5b9bd2a | 2012-06-27 21:25:57 +0200 | [diff] [blame] | 353 | u8 value) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 354 | { |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 355 | if (line6_transmit_parameter(&pod->line6, param, value) == 0) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 356 | pod_store_parameter(pod, param, value); |
| 357 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 358 | 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] | 359 | line6_invalidate_current(&pod->dumpreq); |
| 360 | } |
| 361 | |
| 362 | /* |
| 363 | Resolve value to memory location. |
| 364 | */ |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 365 | static int pod_resolve(const char *buf, short block0, short block1, |
| 366 | unsigned char *location) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 367 | { |
Johannes Thumshirn | 1d0e834 | 2012-06-27 21:26:01 +0200 | [diff] [blame] | 368 | u8 value; |
Shawn Bohrer | 7e4d5c1 | 2009-11-15 22:18:01 -0600 | [diff] [blame] | 369 | short block; |
| 370 | int ret; |
| 371 | |
Johannes Thumshirn | 1d0e834 | 2012-06-27 21:26:01 +0200 | [diff] [blame] | 372 | ret = kstrtou8(buf, 10, &value); |
Shawn Bohrer | 7e4d5c1 | 2009-11-15 22:18:01 -0600 | [diff] [blame] | 373 | if (ret) |
| 374 | return ret; |
| 375 | |
| 376 | block = (value < 0x40) ? block0 : block1; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 377 | value &= 0x3f; |
| 378 | location[0] = block >> 7; |
| 379 | location[1] = value | (block & 0x7f); |
Shawn Bohrer | 7e4d5c1 | 2009-11-15 22:18:01 -0600 | [diff] [blame] | 380 | return 0; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | /* |
| 384 | Send command to store channel/effects setup/amp setup to PODxt Pro. |
| 385 | */ |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 386 | static ssize_t pod_send_store_command(struct device *dev, const char *buf, |
| 387 | size_t count, short block0, short block1) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 388 | { |
| 389 | struct usb_interface *interface = to_usb_interface(dev); |
| 390 | struct usb_line6_pod *pod = usb_get_intfdata(interface); |
Shawn Bohrer | 7e4d5c1 | 2009-11-15 22:18:01 -0600 | [diff] [blame] | 391 | int ret; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 392 | int size = 3 + sizeof(pod->prog_data_buf); |
| 393 | char *sysex = pod_alloc_sysex_buffer(pod, POD_SYSEX_STORE, size); |
Shawn Bohrer | 7e4d5c1 | 2009-11-15 22:18:01 -0600 | [diff] [blame] | 394 | |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 395 | if (!sysex) |
| 396 | return 0; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 397 | |
Stefan Hajnoczi | 980688f | 2012-11-22 20:48:44 +0100 | [diff] [blame] | 398 | /* Don't know what this is good for, but PODxt Pro transmits it, so we |
| 399 | * also do... */ |
| 400 | sysex[SYSEX_DATA_OFS] = 5; |
Shawn Bohrer | 7e4d5c1 | 2009-11-15 22:18:01 -0600 | [diff] [blame] | 401 | ret = pod_resolve(buf, block0, block1, sysex + SYSEX_DATA_OFS + 1); |
| 402 | if (ret) { |
| 403 | kfree(sysex); |
| 404 | return ret; |
| 405 | } |
| 406 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 407 | memcpy(sysex + SYSEX_DATA_OFS + 3, &pod->prog_data_buf, |
| 408 | sizeof(pod->prog_data_buf)); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 409 | |
| 410 | line6_send_sysex_message(&pod->line6, sysex, size); |
| 411 | kfree(sysex); |
| 412 | /* needs some delay here on AMD64 platform */ |
| 413 | return count; |
| 414 | } |
| 415 | |
| 416 | /* |
| 417 | Send command to retrieve channel/effects setup/amp setup to PODxt Pro. |
| 418 | */ |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 419 | static ssize_t pod_send_retrieve_command(struct device *dev, const char *buf, |
| 420 | size_t count, short block0, |
| 421 | short block1) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 422 | { |
| 423 | struct usb_interface *interface = to_usb_interface(dev); |
| 424 | struct usb_line6_pod *pod = usb_get_intfdata(interface); |
Shawn Bohrer | 7e4d5c1 | 2009-11-15 22:18:01 -0600 | [diff] [blame] | 425 | int ret; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 426 | int size = 4; |
| 427 | char *sysex = pod_alloc_sysex_buffer(pod, POD_SYSEX_DUMPMEM, size); |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 428 | |
| 429 | if (!sysex) |
| 430 | return 0; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 431 | |
Shawn Bohrer | 7e4d5c1 | 2009-11-15 22:18:01 -0600 | [diff] [blame] | 432 | ret = pod_resolve(buf, block0, block1, sysex + SYSEX_DATA_OFS); |
| 433 | if (ret) { |
| 434 | kfree(sysex); |
| 435 | return ret; |
| 436 | } |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 437 | sysex[SYSEX_DATA_OFS + 2] = 0; |
| 438 | sysex[SYSEX_DATA_OFS + 3] = 0; |
| 439 | line6_dump_started(&pod->dumpreq, POD_DUMP_MEMORY); |
| 440 | |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 441 | if (line6_send_sysex_message(&pod->line6, sysex, size) < size) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 442 | line6_dump_finished(&pod->dumpreq); |
| 443 | |
| 444 | kfree(sysex); |
| 445 | /* needs some delay here on AMD64 platform */ |
| 446 | return count; |
| 447 | } |
| 448 | |
| 449 | /* |
| 450 | Generic get name function. |
| 451 | */ |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 452 | static ssize_t get_name_generic(struct usb_line6_pod *pod, const char *str, |
| 453 | char *buf) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 454 | { |
| 455 | int length = 0; |
| 456 | const char *p1; |
| 457 | char *p2; |
| 458 | char *last_non_space = buf; |
| 459 | |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 460 | int retval = line6_dump_wait_interruptible(&pod->dumpreq); |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 461 | if (retval < 0) |
| 462 | return retval; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 463 | |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 464 | for (p1 = str, p2 = buf; *p1; ++p1, ++p2) { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 465 | *p2 = *p1; |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 466 | if (*p2 != ' ') |
| 467 | last_non_space = p2; |
| 468 | if (++length == POD_NAME_LENGTH) |
| 469 | break; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | *(last_non_space + 1) = '\n'; |
| 473 | return last_non_space - buf + 2; |
| 474 | } |
| 475 | |
| 476 | /* |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 477 | "read" request on "name" special file. |
| 478 | */ |
Greg Kroah-Hartman | 77491e5 | 2009-02-27 20:25:43 -0800 | [diff] [blame] | 479 | static ssize_t pod_get_name(struct device *dev, struct device_attribute *attr, |
| 480 | char *buf) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 481 | { |
| 482 | struct usb_interface *interface = to_usb_interface(dev); |
| 483 | struct usb_line6_pod *pod = usb_get_intfdata(interface); |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 484 | return get_name_generic(pod, pod->prog_data.header + POD_NAME_OFFSET, |
| 485 | buf); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | /* |
| 489 | "read" request on "name" special file. |
| 490 | */ |
Greg Kroah-Hartman | 77491e5 | 2009-02-27 20:25:43 -0800 | [diff] [blame] | 491 | static ssize_t pod_get_name_buf(struct device *dev, |
| 492 | struct device_attribute *attr, char *buf) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 493 | { |
| 494 | struct usb_interface *interface = to_usb_interface(dev); |
| 495 | struct usb_line6_pod *pod = usb_get_intfdata(interface); |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 496 | return get_name_generic(pod, |
| 497 | pod->prog_data_buf.header + POD_NAME_OFFSET, |
| 498 | buf); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | /* |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 502 | Identify system parameters related to the tuner. |
| 503 | */ |
| 504 | static bool pod_is_tuner(int code) |
| 505 | { |
| 506 | return |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 507 | (code == POD_tuner_mute) || |
| 508 | (code == POD_tuner_freq) || |
| 509 | (code == POD_tuner_note) || (code == POD_tuner_pitch); |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | /* |
| 513 | Get system parameter (as integer). |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 514 | @param tuner non-zero, if code refers to a tuner parameter |
| 515 | */ |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 516 | static int pod_get_system_param_int(struct usb_line6_pod *pod, int *value, |
| 517 | int code, struct ValueWait *param, int sign) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 518 | { |
| 519 | char *sysex; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 520 | static const int size = 1; |
| 521 | int retval = 0; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 522 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 523 | if (((pod->prog_data.control[POD_tuner] & 0x40) == 0) |
| 524 | && pod_is_tuner(code)) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 525 | return -ENODEV; |
| 526 | |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 527 | /* send value request to device: */ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 528 | param->value = POD_system_invalid; |
| 529 | sysex = pod_alloc_sysex_buffer(pod, POD_SYSEX_SYSTEMREQ, size); |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 530 | |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 531 | if (!sysex) |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 532 | return -ENOMEM; |
| 533 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 534 | sysex[SYSEX_DATA_OFS] = code; |
| 535 | line6_send_sysex_message(&pod->line6, sysex, size); |
| 536 | kfree(sysex); |
| 537 | |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 538 | /* wait for device to respond: */ |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 539 | retval = |
| 540 | wait_event_interruptible(param->wait, |
| 541 | param->value != POD_system_invalid); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 542 | |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 543 | if (retval < 0) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 544 | return retval; |
| 545 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 546 | *value = sign ? (int)(signed short)param->value : (int)(unsigned short) |
| 547 | param->value; |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 548 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 549 | if (*value == POD_system_invalid) |
| 550 | *value = 0; /* don't report uninitialized values */ |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 551 | |
| 552 | return 0; |
| 553 | } |
| 554 | |
| 555 | /* |
| 556 | Get system parameter (as string). |
| 557 | @param tuner non-zero, if code refers to a tuner parameter |
| 558 | */ |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 559 | static ssize_t pod_get_system_param_string(struct usb_line6_pod *pod, char *buf, |
| 560 | int code, struct ValueWait *param, |
| 561 | int sign) |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 562 | { |
| 563 | int retval, value = 0; |
| 564 | retval = pod_get_system_param_int(pod, &value, code, param, sign); |
| 565 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 566 | if (retval < 0) |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 567 | return retval; |
| 568 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 569 | return sprintf(buf, "%d\n", value); |
| 570 | } |
| 571 | |
| 572 | /* |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 573 | Send system parameter (from integer). |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 574 | @param tuner non-zero, if code refers to a tuner parameter |
| 575 | */ |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 576 | static int pod_set_system_param_int(struct usb_line6_pod *pod, int value, |
| 577 | int code) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 578 | { |
| 579 | char *sysex; |
| 580 | static const int size = 5; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 581 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 582 | if (((pod->prog_data.control[POD_tuner] & 0x40) == 0) |
| 583 | && pod_is_tuner(code)) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 584 | return -EINVAL; |
| 585 | |
| 586 | /* send value to tuner: */ |
| 587 | sysex = pod_alloc_sysex_buffer(pod, POD_SYSEX_SYSTEM, size); |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 588 | if (!sysex) |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 589 | return -ENOMEM; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 590 | sysex[SYSEX_DATA_OFS] = code; |
| 591 | sysex[SYSEX_DATA_OFS + 1] = (value >> 12) & 0x0f; |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 592 | sysex[SYSEX_DATA_OFS + 2] = (value >> 8) & 0x0f; |
| 593 | sysex[SYSEX_DATA_OFS + 3] = (value >> 4) & 0x0f; |
| 594 | sysex[SYSEX_DATA_OFS + 4] = (value) & 0x0f; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 595 | line6_send_sysex_message(&pod->line6, sysex, size); |
| 596 | kfree(sysex); |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 597 | return 0; |
| 598 | } |
| 599 | |
| 600 | /* |
| 601 | Send system parameter (from string). |
| 602 | @param tuner non-zero, if code refers to a tuner parameter |
| 603 | */ |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 604 | static ssize_t pod_set_system_param_string(struct usb_line6_pod *pod, |
| 605 | const char *buf, int count, int code, |
| 606 | unsigned short mask) |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 607 | { |
| 608 | int retval; |
| 609 | unsigned short value = simple_strtoul(buf, NULL, 10) & mask; |
| 610 | retval = pod_set_system_param_int(pod, value, code); |
| 611 | return (retval < 0) ? retval : count; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | /* |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 615 | "write" request on "finish" special file. |
| 616 | */ |
Greg Kroah-Hartman | 77491e5 | 2009-02-27 20:25:43 -0800 | [diff] [blame] | 617 | static ssize_t pod_set_finish(struct device *dev, |
| 618 | struct device_attribute *attr, |
| 619 | const char *buf, size_t count) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 620 | { |
| 621 | struct usb_interface *interface = to_usb_interface(dev); |
| 622 | struct usb_line6_pod *pod = usb_get_intfdata(interface); |
| 623 | int size = 0; |
| 624 | char *sysex = pod_alloc_sysex_buffer(pod, POD_SYSEX_FINISH, size); |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 625 | if (!sysex) |
| 626 | return 0; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 627 | line6_send_sysex_message(&pod->line6, sysex, size); |
| 628 | kfree(sysex); |
| 629 | return count; |
| 630 | } |
| 631 | |
| 632 | /* |
| 633 | "write" request on "store_channel" special file. |
| 634 | */ |
Greg Kroah-Hartman | 77491e5 | 2009-02-27 20:25:43 -0800 | [diff] [blame] | 635 | static ssize_t pod_set_store_channel(struct device *dev, |
| 636 | struct device_attribute *attr, |
| 637 | const char *buf, size_t count) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 638 | { |
| 639 | return pod_send_store_command(dev, buf, count, 0x0000, 0x00c0); |
| 640 | } |
| 641 | |
| 642 | /* |
| 643 | "write" request on "store_effects_setup" special file. |
| 644 | */ |
Greg Kroah-Hartman | 77491e5 | 2009-02-27 20:25:43 -0800 | [diff] [blame] | 645 | static ssize_t pod_set_store_effects_setup(struct device *dev, |
| 646 | struct device_attribute *attr, |
| 647 | const char *buf, size_t count) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 648 | { |
| 649 | return pod_send_store_command(dev, buf, count, 0x0080, 0x0080); |
| 650 | } |
| 651 | |
| 652 | /* |
| 653 | "write" request on "store_amp_setup" special file. |
| 654 | */ |
Greg Kroah-Hartman | 77491e5 | 2009-02-27 20:25:43 -0800 | [diff] [blame] | 655 | static ssize_t pod_set_store_amp_setup(struct device *dev, |
| 656 | struct device_attribute *attr, |
| 657 | const char *buf, size_t count) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 658 | { |
| 659 | return pod_send_store_command(dev, buf, count, 0x0040, 0x0100); |
| 660 | } |
| 661 | |
| 662 | /* |
| 663 | "write" request on "retrieve_channel" special file. |
| 664 | */ |
Greg Kroah-Hartman | 77491e5 | 2009-02-27 20:25:43 -0800 | [diff] [blame] | 665 | static ssize_t pod_set_retrieve_channel(struct device *dev, |
| 666 | struct device_attribute *attr, |
| 667 | const char *buf, size_t count) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 668 | { |
| 669 | return pod_send_retrieve_command(dev, buf, count, 0x0000, 0x00c0); |
| 670 | } |
| 671 | |
| 672 | /* |
| 673 | "write" request on "retrieve_effects_setup" special file. |
| 674 | */ |
Greg Kroah-Hartman | 77491e5 | 2009-02-27 20:25:43 -0800 | [diff] [blame] | 675 | static ssize_t pod_set_retrieve_effects_setup(struct device *dev, |
| 676 | struct device_attribute *attr, |
| 677 | const char *buf, size_t count) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 678 | { |
| 679 | return pod_send_retrieve_command(dev, buf, count, 0x0080, 0x0080); |
| 680 | } |
| 681 | |
| 682 | /* |
| 683 | "write" request on "retrieve_amp_setup" special file. |
| 684 | */ |
Greg Kroah-Hartman | 77491e5 | 2009-02-27 20:25:43 -0800 | [diff] [blame] | 685 | static ssize_t pod_set_retrieve_amp_setup(struct device *dev, |
| 686 | struct device_attribute *attr, |
| 687 | const char *buf, size_t count) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 688 | { |
| 689 | return pod_send_retrieve_command(dev, buf, count, 0x0040, 0x0100); |
| 690 | } |
| 691 | |
| 692 | /* |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 693 | "read" request on "midi_postprocess" special file. |
| 694 | */ |
Greg Kroah-Hartman | 77491e5 | 2009-02-27 20:25:43 -0800 | [diff] [blame] | 695 | static ssize_t pod_get_midi_postprocess(struct device *dev, |
| 696 | struct device_attribute *attr, |
| 697 | char *buf) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 698 | { |
| 699 | struct usb_interface *interface = to_usb_interface(dev); |
| 700 | struct usb_line6_pod *pod = usb_get_intfdata(interface); |
| 701 | return sprintf(buf, "%d\n", pod->midi_postprocess); |
| 702 | } |
| 703 | |
| 704 | /* |
| 705 | "write" request on "midi_postprocess" special file. |
| 706 | */ |
Greg Kroah-Hartman | 77491e5 | 2009-02-27 20:25:43 -0800 | [diff] [blame] | 707 | static ssize_t pod_set_midi_postprocess(struct device *dev, |
| 708 | struct device_attribute *attr, |
| 709 | const char *buf, size_t count) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 710 | { |
| 711 | struct usb_interface *interface = to_usb_interface(dev); |
| 712 | struct usb_line6_pod *pod = usb_get_intfdata(interface); |
Johannes Thumshirn | 0650178 | 2012-06-27 21:26:03 +0200 | [diff] [blame] | 713 | u8 value; |
Shawn Bohrer | 7e4d5c1 | 2009-11-15 22:18:01 -0600 | [diff] [blame] | 714 | int ret; |
| 715 | |
Johannes Thumshirn | 0650178 | 2012-06-27 21:26:03 +0200 | [diff] [blame] | 716 | ret = kstrtou8(buf, 10, &value); |
Shawn Bohrer | 7e4d5c1 | 2009-11-15 22:18:01 -0600 | [diff] [blame] | 717 | if (ret) |
| 718 | return ret; |
| 719 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 720 | pod->midi_postprocess = value ? 1 : 0; |
| 721 | return count; |
| 722 | } |
| 723 | |
| 724 | /* |
| 725 | "read" request on "serial_number" special file. |
| 726 | */ |
Greg Kroah-Hartman | 77491e5 | 2009-02-27 20:25:43 -0800 | [diff] [blame] | 727 | static ssize_t pod_get_serial_number(struct device *dev, |
| 728 | struct device_attribute *attr, char *buf) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 729 | { |
| 730 | struct usb_interface *interface = to_usb_interface(dev); |
| 731 | struct usb_line6_pod *pod = usb_get_intfdata(interface); |
| 732 | return sprintf(buf, "%d\n", pod->serial_number); |
| 733 | } |
| 734 | |
| 735 | /* |
| 736 | "read" request on "firmware_version" special file. |
| 737 | */ |
Greg Kroah-Hartman | 77491e5 | 2009-02-27 20:25:43 -0800 | [diff] [blame] | 738 | static ssize_t pod_get_firmware_version(struct device *dev, |
| 739 | struct device_attribute *attr, |
| 740 | char *buf) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 741 | { |
| 742 | struct usb_interface *interface = to_usb_interface(dev); |
| 743 | struct usb_line6_pod *pod = usb_get_intfdata(interface); |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 744 | return sprintf(buf, "%d.%02d\n", pod->firmware_version / 100, |
| 745 | pod->firmware_version % 100); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | /* |
| 749 | "read" request on "device_id" special file. |
| 750 | */ |
Greg Kroah-Hartman | 77491e5 | 2009-02-27 20:25:43 -0800 | [diff] [blame] | 751 | static ssize_t pod_get_device_id(struct device *dev, |
| 752 | struct device_attribute *attr, char *buf) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 753 | { |
| 754 | struct usb_interface *interface = to_usb_interface(dev); |
| 755 | struct usb_line6_pod *pod = usb_get_intfdata(interface); |
| 756 | return sprintf(buf, "%d\n", pod->device_id); |
| 757 | } |
| 758 | |
| 759 | /* |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 760 | POD startup procedure. |
| 761 | This is a sequence of functions with special requirements (e.g., must |
| 762 | not run immediately after initialization, must not run in interrupt |
| 763 | context). After the last one has finished, the device is ready to use. |
| 764 | */ |
| 765 | |
| 766 | static void pod_startup1(struct usb_line6_pod *pod) |
| 767 | { |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 768 | CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_INIT); |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 769 | |
| 770 | /* delay startup procedure: */ |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 771 | line6_start_timer(&pod->startup_timer, POD_STARTUP_DELAY, pod_startup2, |
| 772 | (unsigned long)pod); |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | static void pod_startup2(unsigned long data) |
| 776 | { |
| 777 | struct usb_line6_pod *pod = (struct usb_line6_pod *)data; |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 778 | |
| 779 | /* schedule another startup procedure until startup is complete: */ |
| 780 | if (pod->startup_progress >= POD_STARTUP_LAST) |
| 781 | return; |
| 782 | |
| 783 | pod->startup_progress = POD_STARTUP_DUMPREQ; |
| 784 | line6_start_timer(&pod->startup_timer, POD_STARTUP_DELAY, pod_startup2, |
| 785 | (unsigned long)pod); |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 786 | |
| 787 | /* current channel dump: */ |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 788 | line6_dump_request_async(&pod->dumpreq, &pod->line6, 0, |
| 789 | LINE6_DUMP_CURRENT); |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | static void pod_startup3(struct usb_line6_pod *pod) |
| 793 | { |
| 794 | struct usb_line6 *line6 = &pod->line6; |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 795 | CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_VERSIONREQ); |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 796 | |
| 797 | /* request firmware version: */ |
| 798 | line6_version_request_async(line6); |
| 799 | } |
| 800 | |
| 801 | static void pod_startup4(struct usb_line6_pod *pod) |
| 802 | { |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 803 | CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_WORKQUEUE); |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 804 | |
| 805 | /* schedule work for global work queue: */ |
| 806 | schedule_work(&pod->startup_work); |
| 807 | } |
| 808 | |
| 809 | static void pod_startup5(struct work_struct *work) |
| 810 | { |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 811 | struct usb_line6_pod *pod = |
| 812 | container_of(work, struct usb_line6_pod, startup_work); |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 813 | struct usb_line6 *line6 = &pod->line6; |
| 814 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 815 | CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_SETUP); |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 816 | |
| 817 | /* serial number: */ |
| 818 | line6_read_serial_number(&pod->line6, &pod->serial_number); |
| 819 | |
| 820 | /* ALSA audio interface: */ |
| 821 | line6_register_audio(line6); |
| 822 | |
| 823 | /* device files: */ |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 824 | line6_pod_create_files(pod->firmware_version, |
| 825 | line6->properties->device_bit, line6->ifcdev); |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 826 | } |
| 827 | |
| 828 | #define POD_GET_SYSTEM_PARAM(code, sign) \ |
Greg Kroah-Hartman | 77491e5 | 2009-02-27 20:25:43 -0800 | [diff] [blame] | 829 | static ssize_t pod_get_ ## code(struct device *dev, \ |
| 830 | struct device_attribute *attr, char *buf) \ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 831 | { \ |
| 832 | struct usb_interface *interface = to_usb_interface(dev); \ |
| 833 | struct usb_line6_pod *pod = usb_get_intfdata(interface); \ |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 834 | return pod_get_system_param_string(pod, buf, POD_ ## code, \ |
| 835 | &pod->code, sign); \ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 836 | } |
| 837 | |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 838 | #define POD_GET_SET_SYSTEM_PARAM(code, mask, sign) \ |
| 839 | POD_GET_SYSTEM_PARAM(code, sign) \ |
Greg Kroah-Hartman | 77491e5 | 2009-02-27 20:25:43 -0800 | [diff] [blame] | 840 | static ssize_t pod_set_ ## code(struct device *dev, \ |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 841 | struct device_attribute *attr, \ |
| 842 | const char *buf, size_t count) \ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 843 | { \ |
| 844 | struct usb_interface *interface = to_usb_interface(dev); \ |
| 845 | struct usb_line6_pod *pod = usb_get_intfdata(interface); \ |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 846 | return pod_set_system_param_string(pod, buf, count, POD_ ## code, mask); \ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 847 | } |
| 848 | |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 849 | POD_GET_SET_SYSTEM_PARAM(routing, 0x0003, 0); |
| 850 | POD_GET_SET_SYSTEM_PARAM(tuner_mute, 0x0001, 0); |
| 851 | POD_GET_SET_SYSTEM_PARAM(tuner_freq, 0xffff, 0); |
| 852 | POD_GET_SYSTEM_PARAM(tuner_note, 1); |
| 853 | POD_GET_SYSTEM_PARAM(tuner_pitch, 1); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 854 | |
| 855 | #undef GET_SET_SYSTEM_PARAM |
| 856 | #undef GET_SYSTEM_PARAM |
| 857 | |
| 858 | /* POD special files: */ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 859 | 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] | 860 | static DEVICE_ATTR(finish, S_IWUSR, line6_nop_read, pod_set_finish); |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 861 | static DEVICE_ATTR(firmware_version, S_IRUGO, pod_get_firmware_version, |
| 862 | line6_nop_write); |
Greg Kroah-Hartman | a3a972a | 2010-11-18 11:21:04 -0800 | [diff] [blame] | 863 | static DEVICE_ATTR(midi_postprocess, S_IWUSR | S_IRUGO, |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 864 | pod_get_midi_postprocess, pod_set_midi_postprocess); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 865 | static DEVICE_ATTR(name, S_IRUGO, pod_get_name, line6_nop_write); |
| 866 | 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] | 867 | static DEVICE_ATTR(retrieve_amp_setup, S_IWUSR, line6_nop_read, |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 868 | pod_set_retrieve_amp_setup); |
Greg Kroah-Hartman | a3a972a | 2010-11-18 11:21:04 -0800 | [diff] [blame] | 869 | static DEVICE_ATTR(retrieve_channel, S_IWUSR, line6_nop_read, |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 870 | pod_set_retrieve_channel); |
Greg Kroah-Hartman | a3a972a | 2010-11-18 11:21:04 -0800 | [diff] [blame] | 871 | static DEVICE_ATTR(retrieve_effects_setup, S_IWUSR, line6_nop_read, |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 872 | pod_set_retrieve_effects_setup); |
Greg Kroah-Hartman | a3a972a | 2010-11-18 11:21:04 -0800 | [diff] [blame] | 873 | static DEVICE_ATTR(routing, S_IWUSR | S_IRUGO, pod_get_routing, |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 874 | pod_set_routing); |
| 875 | static DEVICE_ATTR(serial_number, S_IRUGO, pod_get_serial_number, |
| 876 | line6_nop_write); |
Greg Kroah-Hartman | a3a972a | 2010-11-18 11:21:04 -0800 | [diff] [blame] | 877 | static DEVICE_ATTR(store_amp_setup, S_IWUSR, line6_nop_read, |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 878 | pod_set_store_amp_setup); |
Greg Kroah-Hartman | a3a972a | 2010-11-18 11:21:04 -0800 | [diff] [blame] | 879 | static DEVICE_ATTR(store_channel, S_IWUSR, line6_nop_read, |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 880 | pod_set_store_channel); |
Greg Kroah-Hartman | a3a972a | 2010-11-18 11:21:04 -0800 | [diff] [blame] | 881 | static DEVICE_ATTR(store_effects_setup, S_IWUSR, line6_nop_read, |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 882 | pod_set_store_effects_setup); |
Greg Kroah-Hartman | a3a972a | 2010-11-18 11:21:04 -0800 | [diff] [blame] | 883 | 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] | 884 | pod_set_tuner_freq); |
Greg Kroah-Hartman | a3a972a | 2010-11-18 11:21:04 -0800 | [diff] [blame] | 885 | 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] | 886 | pod_set_tuner_mute); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 887 | static DEVICE_ATTR(tuner_note, S_IRUGO, pod_get_tuner_note, line6_nop_write); |
| 888 | static DEVICE_ATTR(tuner_pitch, S_IRUGO, pod_get_tuner_pitch, line6_nop_write); |
| 889 | |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 890 | #ifdef CONFIG_LINE6_USB_RAW |
Greg Kroah-Hartman | a3a972a | 2010-11-18 11:21:04 -0800 | [diff] [blame] | 891 | static DEVICE_ATTR(raw, S_IWUSR, line6_nop_read, line6_set_raw); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 892 | #endif |
| 893 | |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 894 | /* control info callback */ |
| 895 | static int snd_pod_control_monitor_info(struct snd_kcontrol *kcontrol, |
| 896 | struct snd_ctl_elem_info *uinfo) |
| 897 | { |
| 898 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 899 | uinfo->count = 1; |
| 900 | uinfo->value.integer.min = 0; |
| 901 | uinfo->value.integer.max = 65535; |
| 902 | return 0; |
| 903 | } |
| 904 | |
| 905 | /* control get callback */ |
| 906 | static int snd_pod_control_monitor_get(struct snd_kcontrol *kcontrol, |
| 907 | struct snd_ctl_elem_value *ucontrol) |
| 908 | { |
| 909 | struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol); |
| 910 | struct usb_line6_pod *pod = (struct usb_line6_pod *)line6pcm->line6; |
Stefan Hajnoczi | 2c35dc2 | 2012-11-22 20:48:47 +0100 | [diff] [blame^] | 911 | ucontrol->value.integer.value[0] = pod->monitor_level; |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 912 | return 0; |
| 913 | } |
| 914 | |
| 915 | /* control put callback */ |
| 916 | static int snd_pod_control_monitor_put(struct snd_kcontrol *kcontrol, |
| 917 | struct snd_ctl_elem_value *ucontrol) |
| 918 | { |
| 919 | struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol); |
| 920 | struct usb_line6_pod *pod = (struct usb_line6_pod *)line6pcm->line6; |
| 921 | |
Stefan Hajnoczi | 2c35dc2 | 2012-11-22 20:48:47 +0100 | [diff] [blame^] | 922 | if (ucontrol->value.integer.value[0] == pod->monitor_level) |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 923 | return 0; |
| 924 | |
Stefan Hajnoczi | 2c35dc2 | 2012-11-22 20:48:47 +0100 | [diff] [blame^] | 925 | pod->monitor_level = ucontrol->value.integer.value[0]; |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 926 | pod_set_system_param_int(pod, ucontrol->value.integer.value[0], |
| 927 | POD_monitor_level); |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 928 | return 1; |
| 929 | } |
| 930 | |
| 931 | /* control definition */ |
| 932 | static struct snd_kcontrol_new pod_control_monitor = { |
| 933 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 934 | .name = "Monitor Playback Volume", |
| 935 | .index = 0, |
| 936 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, |
| 937 | .info = snd_pod_control_monitor_info, |
| 938 | .get = snd_pod_control_monitor_get, |
| 939 | .put = snd_pod_control_monitor_put |
| 940 | }; |
| 941 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 942 | /* |
| 943 | POD destructor. |
| 944 | */ |
| 945 | static void pod_destruct(struct usb_interface *interface) |
| 946 | { |
| 947 | struct usb_line6_pod *pod = usb_get_intfdata(interface); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 948 | |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 949 | if (pod == NULL) |
| 950 | return; |
Stefan Hajnoczi | 188e664 | 2011-12-10 02:12:30 +0100 | [diff] [blame] | 951 | line6_cleanup_audio(&pod->line6); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 952 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 953 | del_timer(&pod->startup_timer); |
| 954 | cancel_work_sync(&pod->startup_work); |
| 955 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 956 | /* free dump request data: */ |
| 957 | line6_dumpreq_destruct(&pod->dumpreq); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 958 | } |
| 959 | |
| 960 | /* |
| 961 | Create sysfs entries. |
| 962 | */ |
Greg Kroah-Hartman | b702ed25 | 2009-02-27 20:45:03 -0800 | [diff] [blame] | 963 | static int pod_create_files2(struct device *dev) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 964 | { |
| 965 | int err; |
| 966 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 967 | CHECK_RETURN(device_create_file(dev, &dev_attr_device_id)); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 968 | CHECK_RETURN(device_create_file(dev, &dev_attr_finish)); |
| 969 | CHECK_RETURN(device_create_file(dev, &dev_attr_firmware_version)); |
| 970 | CHECK_RETURN(device_create_file(dev, &dev_attr_midi_postprocess)); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 971 | CHECK_RETURN(device_create_file(dev, &dev_attr_name)); |
| 972 | CHECK_RETURN(device_create_file(dev, &dev_attr_name_buf)); |
| 973 | CHECK_RETURN(device_create_file(dev, &dev_attr_retrieve_amp_setup)); |
| 974 | CHECK_RETURN(device_create_file(dev, &dev_attr_retrieve_channel)); |
| 975 | CHECK_RETURN(device_create_file(dev, &dev_attr_retrieve_effects_setup)); |
| 976 | CHECK_RETURN(device_create_file(dev, &dev_attr_routing)); |
| 977 | CHECK_RETURN(device_create_file(dev, &dev_attr_serial_number)); |
| 978 | CHECK_RETURN(device_create_file(dev, &dev_attr_store_amp_setup)); |
| 979 | CHECK_RETURN(device_create_file(dev, &dev_attr_store_channel)); |
| 980 | CHECK_RETURN(device_create_file(dev, &dev_attr_store_effects_setup)); |
| 981 | CHECK_RETURN(device_create_file(dev, &dev_attr_tuner_freq)); |
| 982 | CHECK_RETURN(device_create_file(dev, &dev_attr_tuner_mute)); |
| 983 | CHECK_RETURN(device_create_file(dev, &dev_attr_tuner_note)); |
| 984 | CHECK_RETURN(device_create_file(dev, &dev_attr_tuner_pitch)); |
| 985 | |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 986 | #ifdef CONFIG_LINE6_USB_RAW |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 987 | CHECK_RETURN(device_create_file(dev, &dev_attr_raw)); |
| 988 | #endif |
| 989 | |
| 990 | return 0; |
| 991 | } |
| 992 | |
| 993 | /* |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 994 | Try to init POD device. |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 995 | */ |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 996 | static int pod_try_init(struct usb_interface *interface, |
| 997 | struct usb_line6_pod *pod) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 998 | { |
| 999 | int err; |
| 1000 | struct usb_line6 *line6 = &pod->line6; |
| 1001 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 1002 | init_timer(&pod->startup_timer); |
| 1003 | INIT_WORK(&pod->startup_work, pod_startup5); |
| 1004 | |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 1005 | if ((interface == NULL) || (pod == NULL)) |
| 1006 | return -ENODEV; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1007 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1008 | /* initialize wait queues: */ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1009 | init_waitqueue_head(&pod->routing.wait); |
| 1010 | init_waitqueue_head(&pod->tuner_mute.wait); |
| 1011 | init_waitqueue_head(&pod->tuner_freq.wait); |
| 1012 | init_waitqueue_head(&pod->tuner_note.wait); |
| 1013 | init_waitqueue_head(&pod->tuner_pitch.wait); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1014 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1015 | /* initialize USB buffers: */ |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 1016 | err = line6_dumpreq_init(&pod->dumpreq, pod_request_channel, |
| 1017 | sizeof(pod_request_channel)); |
| 1018 | if (err < 0) { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1019 | dev_err(&interface->dev, "Out of memory\n"); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1020 | return -ENOMEM; |
| 1021 | } |
| 1022 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1023 | /* create sysfs entries: */ |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 1024 | err = pod_create_files2(&interface->dev); |
Greg Kroah-Hartman | 027360c | 2010-09-21 16:58:00 -0700 | [diff] [blame] | 1025 | if (err < 0) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1026 | return err; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1027 | |
| 1028 | /* initialize audio system: */ |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 1029 | err = line6_init_audio(line6); |
Greg Kroah-Hartman | 027360c | 2010-09-21 16:58:00 -0700 | [diff] [blame] | 1030 | if (err < 0) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1031 | return err; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1032 | |
| 1033 | /* initialize MIDI subsystem: */ |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 1034 | err = line6_init_midi(line6); |
Greg Kroah-Hartman | 027360c | 2010-09-21 16:58:00 -0700 | [diff] [blame] | 1035 | if (err < 0) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1036 | return err; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1037 | |
| 1038 | /* initialize PCM subsystem: */ |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 1039 | err = line6_init_pcm(line6, &pod_pcm_properties); |
Greg Kroah-Hartman | 027360c | 2010-09-21 16:58:00 -0700 | [diff] [blame] | 1040 | if (err < 0) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1041 | return err; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1042 | |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 1043 | /* register monitor control: */ |
Greg Kroah-Hartman | 027360c | 2010-09-21 16:58:00 -0700 | [diff] [blame] | 1044 | err = snd_ctl_add(line6->card, |
| 1045 | snd_ctl_new1(&pod_control_monitor, line6->line6pcm)); |
| 1046 | if (err < 0) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1047 | return err; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1048 | |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 1049 | /* |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 1050 | When the sound card is registered at this point, the PODxt Live |
| 1051 | displays "Invalid Code Error 07", so we do it later in the event |
| 1052 | handler. |
| 1053 | */ |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 1054 | |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 1055 | if (pod->line6.properties->capabilities & LINE6_BIT_CONTROL) { |
Stefan Hajnoczi | 2c35dc2 | 2012-11-22 20:48:47 +0100 | [diff] [blame^] | 1056 | pod->monitor_level = POD_system_invalid; |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 1057 | |
| 1058 | /* initiate startup procedure: */ |
| 1059 | pod_startup1(pod); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1060 | } |
| 1061 | |
| 1062 | return 0; |
| 1063 | } |
| 1064 | |
| 1065 | /* |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 1066 | Init POD device (and clean up in case of failure). |
| 1067 | */ |
| 1068 | int line6_pod_init(struct usb_interface *interface, struct usb_line6_pod *pod) |
| 1069 | { |
| 1070 | int err = pod_try_init(interface, pod); |
| 1071 | |
Greg Kroah-Hartman | 027360c | 2010-09-21 16:58:00 -0700 | [diff] [blame] | 1072 | if (err < 0) |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 1073 | pod_destruct(interface); |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 1074 | |
| 1075 | return err; |
| 1076 | } |
| 1077 | |
| 1078 | /* |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1079 | POD device disconnected. |
| 1080 | */ |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 1081 | void line6_pod_disconnect(struct usb_interface *interface) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1082 | { |
| 1083 | struct usb_line6_pod *pod; |
| 1084 | |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 1085 | if (interface == NULL) |
| 1086 | return; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1087 | pod = usb_get_intfdata(interface); |
| 1088 | |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 1089 | if (pod != NULL) { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1090 | struct snd_line6_pcm *line6pcm = pod->line6.line6pcm; |
| 1091 | struct device *dev = &interface->dev; |
| 1092 | |
Greg Kroah-Hartman | 027360c | 2010-09-21 16:58:00 -0700 | [diff] [blame] | 1093 | if (line6pcm != NULL) |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 1094 | line6_pcm_disconnect(line6pcm); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1095 | |
Greg Kroah-Hartman | 0fdef36 | 2009-02-27 22:41:29 -0800 | [diff] [blame] | 1096 | if (dev != NULL) { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1097 | /* remove sysfs entries: */ |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 1098 | line6_pod_remove_files(pod->firmware_version, |
| 1099 | pod->line6. |
| 1100 | properties->device_bit, dev); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1101 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1102 | device_remove_file(dev, &dev_attr_device_id); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1103 | device_remove_file(dev, &dev_attr_finish); |
| 1104 | device_remove_file(dev, &dev_attr_firmware_version); |
| 1105 | device_remove_file(dev, &dev_attr_midi_postprocess); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1106 | device_remove_file(dev, &dev_attr_name); |
| 1107 | device_remove_file(dev, &dev_attr_name_buf); |
| 1108 | device_remove_file(dev, &dev_attr_retrieve_amp_setup); |
| 1109 | device_remove_file(dev, &dev_attr_retrieve_channel); |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 1110 | device_remove_file(dev, |
| 1111 | &dev_attr_retrieve_effects_setup); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1112 | device_remove_file(dev, &dev_attr_routing); |
| 1113 | device_remove_file(dev, &dev_attr_serial_number); |
| 1114 | device_remove_file(dev, &dev_attr_store_amp_setup); |
| 1115 | device_remove_file(dev, &dev_attr_store_channel); |
| 1116 | device_remove_file(dev, &dev_attr_store_effects_setup); |
| 1117 | device_remove_file(dev, &dev_attr_tuner_freq); |
| 1118 | device_remove_file(dev, &dev_attr_tuner_mute); |
| 1119 | device_remove_file(dev, &dev_attr_tuner_note); |
| 1120 | device_remove_file(dev, &dev_attr_tuner_pitch); |
| 1121 | |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 1122 | #ifdef CONFIG_LINE6_USB_RAW |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1123 | device_remove_file(dev, &dev_attr_raw); |
| 1124 | #endif |
| 1125 | } |
| 1126 | } |
| 1127 | |
| 1128 | pod_destruct(interface); |
| 1129 | } |