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