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