Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2006,2007 Daniel Mack, Tim Ruetz |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | */ |
| 18 | |
Daniel Mack | f1f6b8f | 2013-03-03 20:46:22 +0100 | [diff] [blame] | 19 | #include <linux/device.h> |
Tejun Heo | 7b7b904 | 2010-03-30 02:52:29 +0900 | [diff] [blame] | 20 | #include <linux/gfp.h> |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 21 | #include <linux/init.h> |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 22 | #include <linux/usb.h> |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 23 | #include <linux/usb/input.h> |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 24 | #include <sound/core.h> |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 25 | #include <sound/pcm.h> |
Daniel Mack | 936e7d0 | 2009-04-01 19:05:39 +0200 | [diff] [blame] | 26 | |
| 27 | #include "device.h" |
| 28 | #include "input.h" |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 29 | |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 30 | static unsigned short keycode_ak1[] = { KEY_C, KEY_B, KEY_A }; |
| 31 | static unsigned short keycode_rk2[] = { KEY_1, KEY_2, KEY_3, KEY_4, |
| 32 | KEY_5, KEY_6, KEY_7 }; |
| 33 | static unsigned short keycode_rk3[] = { KEY_1, KEY_2, KEY_3, KEY_4, |
Daniel Mack | f438948 | 2011-08-06 09:13:08 +0200 | [diff] [blame] | 34 | KEY_5, KEY_6, KEY_7, KEY_8, KEY_9 }; |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 35 | |
Daniel Mack | 8e3cd08 | 2007-11-22 11:40:04 +0100 | [diff] [blame] | 36 | static unsigned short keycode_kore[] = { |
| 37 | KEY_FN_F1, /* "menu" */ |
| 38 | KEY_FN_F7, /* "lcd backlight */ |
| 39 | KEY_FN_F2, /* "control" */ |
| 40 | KEY_FN_F3, /* "enter" */ |
| 41 | KEY_FN_F4, /* "view" */ |
| 42 | KEY_FN_F5, /* "esc" */ |
| 43 | KEY_FN_F6, /* "sound" */ |
| 44 | KEY_FN_F8, /* array spacer, never triggered. */ |
| 45 | KEY_RIGHT, |
| 46 | KEY_DOWN, |
| 47 | KEY_UP, |
| 48 | KEY_LEFT, |
| 49 | KEY_SOUND, /* "listen" */ |
| 50 | KEY_RECORD, |
| 51 | KEY_PLAYPAUSE, |
| 52 | KEY_STOP, |
| 53 | BTN_4, /* 8 softkeys */ |
| 54 | BTN_3, |
| 55 | BTN_2, |
| 56 | BTN_1, |
| 57 | BTN_8, |
| 58 | BTN_7, |
| 59 | BTN_6, |
| 60 | BTN_5, |
| 61 | KEY_BRL_DOT4, /* touch sensitive knobs */ |
| 62 | KEY_BRL_DOT3, |
| 63 | KEY_BRL_DOT2, |
| 64 | KEY_BRL_DOT1, |
| 65 | KEY_BRL_DOT8, |
| 66 | KEY_BRL_DOT7, |
| 67 | KEY_BRL_DOT6, |
| 68 | KEY_BRL_DOT5 |
| 69 | }; |
| 70 | |
William Light | e653510 | 2011-10-10 15:54:23 +0000 | [diff] [blame] | 71 | #define MASCHINE_BUTTONS (42) |
| 72 | #define MASCHINE_BUTTON(X) ((X) + BTN_MISC) |
| 73 | #define MASCHINE_PADS (16) |
| 74 | #define MASCHINE_PAD(X) ((X) + ABS_PRESSURE) |
| 75 | |
| 76 | static unsigned short keycode_maschine[] = { |
| 77 | MASCHINE_BUTTON(40), /* mute */ |
| 78 | MASCHINE_BUTTON(39), /* solo */ |
| 79 | MASCHINE_BUTTON(38), /* select */ |
| 80 | MASCHINE_BUTTON(37), /* duplicate */ |
| 81 | MASCHINE_BUTTON(36), /* navigate */ |
| 82 | MASCHINE_BUTTON(35), /* pad mode */ |
| 83 | MASCHINE_BUTTON(34), /* pattern */ |
| 84 | MASCHINE_BUTTON(33), /* scene */ |
| 85 | KEY_RESERVED, /* spacer */ |
| 86 | |
| 87 | MASCHINE_BUTTON(30), /* rec */ |
| 88 | MASCHINE_BUTTON(31), /* erase */ |
| 89 | MASCHINE_BUTTON(32), /* shift */ |
| 90 | MASCHINE_BUTTON(28), /* grid */ |
| 91 | MASCHINE_BUTTON(27), /* > */ |
| 92 | MASCHINE_BUTTON(26), /* < */ |
| 93 | MASCHINE_BUTTON(25), /* restart */ |
| 94 | |
| 95 | MASCHINE_BUTTON(21), /* E */ |
| 96 | MASCHINE_BUTTON(22), /* F */ |
| 97 | MASCHINE_BUTTON(23), /* G */ |
| 98 | MASCHINE_BUTTON(24), /* H */ |
| 99 | MASCHINE_BUTTON(20), /* D */ |
| 100 | MASCHINE_BUTTON(19), /* C */ |
| 101 | MASCHINE_BUTTON(18), /* B */ |
| 102 | MASCHINE_BUTTON(17), /* A */ |
| 103 | |
| 104 | MASCHINE_BUTTON(0), /* control */ |
| 105 | MASCHINE_BUTTON(2), /* browse */ |
| 106 | MASCHINE_BUTTON(4), /* < */ |
| 107 | MASCHINE_BUTTON(6), /* snap */ |
| 108 | MASCHINE_BUTTON(7), /* autowrite */ |
| 109 | MASCHINE_BUTTON(5), /* > */ |
| 110 | MASCHINE_BUTTON(3), /* sampling */ |
| 111 | MASCHINE_BUTTON(1), /* step */ |
| 112 | |
| 113 | MASCHINE_BUTTON(15), /* 8 softkeys */ |
| 114 | MASCHINE_BUTTON(14), |
| 115 | MASCHINE_BUTTON(13), |
| 116 | MASCHINE_BUTTON(12), |
| 117 | MASCHINE_BUTTON(11), |
| 118 | MASCHINE_BUTTON(10), |
| 119 | MASCHINE_BUTTON(9), |
| 120 | MASCHINE_BUTTON(8), |
| 121 | |
| 122 | MASCHINE_BUTTON(16), /* note repeat */ |
| 123 | MASCHINE_BUTTON(29) /* play */ |
| 124 | }; |
| 125 | |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 126 | #define KONTROLX1_INPUTS (40) |
| 127 | #define KONTROLS4_BUTTONS (12 * 8) |
| 128 | #define KONTROLS4_AXIS (46) |
| 129 | |
| 130 | #define KONTROLS4_BUTTON(X) ((X) + BTN_MISC) |
| 131 | #define KONTROLS4_ABS(X) ((X) + ABS_HAT0X) |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 132 | |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 133 | #define DEG90 (range / 2) |
| 134 | #define DEG180 (range) |
| 135 | #define DEG270 (DEG90 + DEG180) |
| 136 | #define DEG360 (DEG180 * 2) |
| 137 | #define HIGH_PEAK (268) |
| 138 | #define LOW_PEAK (-7) |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 139 | |
| 140 | /* some of these devices have endless rotation potentiometers |
| 141 | * built in which use two tapers, 90 degrees phase shifted. |
| 142 | * this algorithm decodes them to one single value, ranging |
| 143 | * from 0 to 999 */ |
| 144 | static unsigned int decode_erp(unsigned char a, unsigned char b) |
| 145 | { |
| 146 | int weight_a, weight_b; |
| 147 | int pos_a, pos_b; |
| 148 | int ret; |
| 149 | int range = HIGH_PEAK - LOW_PEAK; |
| 150 | int mid_value = (HIGH_PEAK + LOW_PEAK) / 2; |
| 151 | |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 152 | weight_b = abs(mid_value - a) - (range / 2 - 100) / 2; |
| 153 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 154 | if (weight_b < 0) |
| 155 | weight_b = 0; |
| 156 | |
| 157 | if (weight_b > 100) |
| 158 | weight_b = 100; |
| 159 | |
| 160 | weight_a = 100 - weight_b; |
| 161 | |
| 162 | if (a < mid_value) { |
| 163 | /* 0..90 and 270..360 degrees */ |
| 164 | pos_b = b - LOW_PEAK + DEG270; |
| 165 | if (pos_b >= DEG360) |
| 166 | pos_b -= DEG360; |
| 167 | } else |
| 168 | /* 90..270 degrees */ |
| 169 | pos_b = HIGH_PEAK - b + DEG90; |
| 170 | |
| 171 | |
| 172 | if (b > mid_value) |
| 173 | /* 0..180 degrees */ |
| 174 | pos_a = a - LOW_PEAK; |
| 175 | else |
| 176 | /* 180..360 degrees */ |
| 177 | pos_a = HIGH_PEAK - a + DEG180; |
| 178 | |
| 179 | /* interpolate both slider values, depending on weight factors */ |
| 180 | /* 0..99 x DEG360 */ |
| 181 | ret = pos_a * weight_a + pos_b * weight_b; |
| 182 | |
| 183 | /* normalize to 0..999 */ |
| 184 | ret *= 10; |
| 185 | ret /= DEG360; |
| 186 | |
| 187 | if (ret < 0) |
| 188 | ret += 1000; |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 189 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 190 | if (ret >= 1000) |
| 191 | ret -= 1000; |
| 192 | |
| 193 | return ret; |
| 194 | } |
| 195 | |
| 196 | #undef DEG90 |
| 197 | #undef DEG180 |
| 198 | #undef DEG270 |
| 199 | #undef DEG360 |
| 200 | #undef HIGH_PEAK |
| 201 | #undef LOW_PEAK |
| 202 | |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 203 | static inline void snd_caiaq_input_report_abs(struct snd_usb_caiaqdev *cdev, |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 204 | int axis, const unsigned char *buf, |
| 205 | int offset) |
| 206 | { |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 207 | input_report_abs(cdev->input_dev, axis, |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 208 | (buf[offset * 2] << 8) | buf[offset * 2 + 1]); |
| 209 | } |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 210 | |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 211 | static void snd_caiaq_input_read_analog(struct snd_usb_caiaqdev *cdev, |
Daniel Mack | ad1e34b | 2007-09-17 14:45:14 +0200 | [diff] [blame] | 212 | const unsigned char *buf, |
| 213 | unsigned int len) |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 214 | { |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 215 | struct input_dev *input_dev = cdev->input_dev; |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 216 | |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 217 | switch (cdev->chip.usb_id) { |
Daniel Mack | 8e3cd08 | 2007-11-22 11:40:04 +0100 | [diff] [blame] | 218 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL2): |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 219 | snd_caiaq_input_report_abs(cdev, ABS_X, buf, 2); |
| 220 | snd_caiaq_input_report_abs(cdev, ABS_Y, buf, 0); |
| 221 | snd_caiaq_input_report_abs(cdev, ABS_Z, buf, 1); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 222 | break; |
Daniel Mack | 8e3cd08 | 2007-11-22 11:40:04 +0100 | [diff] [blame] | 223 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL3): |
Daniel Mack | 8e3cd08 | 2007-11-22 11:40:04 +0100 | [diff] [blame] | 224 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER): |
Daniel Mack | 7829d0e | 2007-11-26 09:00:56 +0100 | [diff] [blame] | 225 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER2): |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 226 | snd_caiaq_input_report_abs(cdev, ABS_X, buf, 0); |
| 227 | snd_caiaq_input_report_abs(cdev, ABS_Y, buf, 1); |
| 228 | snd_caiaq_input_report_abs(cdev, ABS_Z, buf, 2); |
Daniel Mack | ad1e34b | 2007-09-17 14:45:14 +0200 | [diff] [blame] | 229 | break; |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 230 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1): |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 231 | snd_caiaq_input_report_abs(cdev, ABS_HAT0X, buf, 4); |
| 232 | snd_caiaq_input_report_abs(cdev, ABS_HAT0Y, buf, 2); |
| 233 | snd_caiaq_input_report_abs(cdev, ABS_HAT1X, buf, 6); |
| 234 | snd_caiaq_input_report_abs(cdev, ABS_HAT1Y, buf, 1); |
| 235 | snd_caiaq_input_report_abs(cdev, ABS_HAT2X, buf, 7); |
| 236 | snd_caiaq_input_report_abs(cdev, ABS_HAT2Y, buf, 0); |
| 237 | snd_caiaq_input_report_abs(cdev, ABS_HAT3X, buf, 5); |
| 238 | snd_caiaq_input_report_abs(cdev, ABS_HAT3Y, buf, 3); |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 239 | break; |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 240 | } |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 241 | |
| 242 | input_sync(input_dev); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 243 | } |
| 244 | |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 245 | static void snd_caiaq_input_read_erp(struct snd_usb_caiaqdev *cdev, |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 246 | const char *buf, unsigned int len) |
| 247 | { |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 248 | struct input_dev *input_dev = cdev->input_dev; |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 249 | int i; |
| 250 | |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 251 | switch (cdev->chip.usb_id) { |
Daniel Mack | 8e3cd08 | 2007-11-22 11:40:04 +0100 | [diff] [blame] | 252 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AK1): |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 253 | i = decode_erp(buf[0], buf[1]); |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 254 | input_report_abs(input_dev, ABS_X, i); |
| 255 | input_sync(input_dev); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 256 | break; |
Daniel Mack | 8e3cd08 | 2007-11-22 11:40:04 +0100 | [diff] [blame] | 257 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER): |
Daniel Mack | 7829d0e | 2007-11-26 09:00:56 +0100 | [diff] [blame] | 258 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER2): |
Daniel Mack | 8e3cd08 | 2007-11-22 11:40:04 +0100 | [diff] [blame] | 259 | i = decode_erp(buf[7], buf[5]); |
| 260 | input_report_abs(input_dev, ABS_HAT0X, i); |
| 261 | i = decode_erp(buf[12], buf[14]); |
| 262 | input_report_abs(input_dev, ABS_HAT0Y, i); |
| 263 | i = decode_erp(buf[15], buf[13]); |
| 264 | input_report_abs(input_dev, ABS_HAT1X, i); |
| 265 | i = decode_erp(buf[0], buf[2]); |
| 266 | input_report_abs(input_dev, ABS_HAT1Y, i); |
| 267 | i = decode_erp(buf[3], buf[1]); |
| 268 | input_report_abs(input_dev, ABS_HAT2X, i); |
| 269 | i = decode_erp(buf[8], buf[10]); |
| 270 | input_report_abs(input_dev, ABS_HAT2Y, i); |
| 271 | i = decode_erp(buf[11], buf[9]); |
| 272 | input_report_abs(input_dev, ABS_HAT3X, i); |
| 273 | i = decode_erp(buf[4], buf[6]); |
| 274 | input_report_abs(input_dev, ABS_HAT3Y, i); |
| 275 | input_sync(input_dev); |
| 276 | break; |
William Light | e653510 | 2011-10-10 15:54:23 +0000 | [diff] [blame] | 277 | |
| 278 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_MASCHINECONTROLLER): |
| 279 | /* 4 under the left screen */ |
| 280 | input_report_abs(input_dev, ABS_HAT0X, decode_erp(buf[21], buf[20])); |
| 281 | input_report_abs(input_dev, ABS_HAT0Y, decode_erp(buf[15], buf[14])); |
| 282 | input_report_abs(input_dev, ABS_HAT1X, decode_erp(buf[9], buf[8])); |
| 283 | input_report_abs(input_dev, ABS_HAT1Y, decode_erp(buf[3], buf[2])); |
| 284 | |
| 285 | /* 4 under the right screen */ |
| 286 | input_report_abs(input_dev, ABS_HAT2X, decode_erp(buf[19], buf[18])); |
| 287 | input_report_abs(input_dev, ABS_HAT2Y, decode_erp(buf[13], buf[12])); |
| 288 | input_report_abs(input_dev, ABS_HAT3X, decode_erp(buf[7], buf[6])); |
| 289 | input_report_abs(input_dev, ABS_HAT3Y, decode_erp(buf[1], buf[0])); |
| 290 | |
| 291 | /* volume */ |
| 292 | input_report_abs(input_dev, ABS_RX, decode_erp(buf[17], buf[16])); |
| 293 | /* tempo */ |
| 294 | input_report_abs(input_dev, ABS_RY, decode_erp(buf[11], buf[10])); |
| 295 | /* swing */ |
| 296 | input_report_abs(input_dev, ABS_RZ, decode_erp(buf[5], buf[4])); |
| 297 | |
| 298 | input_sync(input_dev); |
| 299 | break; |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 300 | } |
| 301 | } |
| 302 | |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 303 | static void snd_caiaq_input_read_io(struct snd_usb_caiaqdev *cdev, |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 304 | unsigned char *buf, unsigned int len) |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 305 | { |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 306 | struct input_dev *input_dev = cdev->input_dev; |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 307 | unsigned short *keycode = input_dev->keycode; |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 308 | int i; |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 309 | |
| 310 | if (!keycode) |
| 311 | return; |
| 312 | |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 313 | if (input_dev->id.product == USB_PID_RIGKONTROL2) |
| 314 | for (i = 0; i < len; i++) |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 315 | buf[i] = ~buf[i]; |
| 316 | |
Daniel Mack | 8e3cd08 | 2007-11-22 11:40:04 +0100 | [diff] [blame] | 317 | for (i = 0; i < input_dev->keycodemax && i < len * 8; i++) |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 318 | input_report_key(input_dev, keycode[i], |
| 319 | buf[i / 8] & (1 << (i % 8))); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 320 | |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 321 | switch (cdev->chip.usb_id) { |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 322 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER): |
| 323 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER2): |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 324 | input_report_abs(cdev->input_dev, ABS_MISC, 255 - buf[4]); |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 325 | break; |
| 326 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1): |
| 327 | /* rotary encoders */ |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 328 | input_report_abs(cdev->input_dev, ABS_X, buf[5] & 0xf); |
| 329 | input_report_abs(cdev->input_dev, ABS_Y, buf[5] >> 4); |
| 330 | input_report_abs(cdev->input_dev, ABS_Z, buf[6] & 0xf); |
| 331 | input_report_abs(cdev->input_dev, ABS_MISC, buf[6] >> 4); |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 332 | break; |
| 333 | } |
Daniel Mack | 8e3cd08 | 2007-11-22 11:40:04 +0100 | [diff] [blame] | 334 | |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 335 | input_sync(input_dev); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 336 | } |
| 337 | |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 338 | #define TKS4_MSGBLOCK_SIZE 16 |
| 339 | |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 340 | static void snd_usb_caiaq_tks4_dispatch(struct snd_usb_caiaqdev *cdev, |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 341 | const unsigned char *buf, |
| 342 | unsigned int len) |
| 343 | { |
Daniel Mack | f1f6b8f | 2013-03-03 20:46:22 +0100 | [diff] [blame] | 344 | struct device *dev = caiaqdev_to_dev(cdev); |
| 345 | |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 346 | while (len) { |
| 347 | unsigned int i, block_id = (buf[0] << 8) | buf[1]; |
| 348 | |
| 349 | switch (block_id) { |
| 350 | case 0: |
| 351 | /* buttons */ |
| 352 | for (i = 0; i < KONTROLS4_BUTTONS; i++) |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 353 | input_report_key(cdev->input_dev, KONTROLS4_BUTTON(i), |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 354 | (buf[4 + (i / 8)] >> (i % 8)) & 1); |
| 355 | break; |
| 356 | |
| 357 | case 1: |
| 358 | /* left wheel */ |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 359 | input_report_abs(cdev->input_dev, KONTROLS4_ABS(36), buf[9] | ((buf[8] & 0x3) << 8)); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 360 | /* right wheel */ |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 361 | input_report_abs(cdev->input_dev, KONTROLS4_ABS(37), buf[13] | ((buf[12] & 0x3) << 8)); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 362 | |
| 363 | /* rotary encoders */ |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 364 | input_report_abs(cdev->input_dev, KONTROLS4_ABS(38), buf[3] & 0xf); |
| 365 | input_report_abs(cdev->input_dev, KONTROLS4_ABS(39), buf[4] >> 4); |
| 366 | input_report_abs(cdev->input_dev, KONTROLS4_ABS(40), buf[4] & 0xf); |
| 367 | input_report_abs(cdev->input_dev, KONTROLS4_ABS(41), buf[5] >> 4); |
| 368 | input_report_abs(cdev->input_dev, KONTROLS4_ABS(42), buf[5] & 0xf); |
| 369 | input_report_abs(cdev->input_dev, KONTROLS4_ABS(43), buf[6] >> 4); |
| 370 | input_report_abs(cdev->input_dev, KONTROLS4_ABS(44), buf[6] & 0xf); |
| 371 | input_report_abs(cdev->input_dev, KONTROLS4_ABS(45), buf[7] >> 4); |
| 372 | input_report_abs(cdev->input_dev, KONTROLS4_ABS(46), buf[7] & 0xf); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 373 | |
| 374 | break; |
| 375 | case 2: |
| 376 | /* Volume Fader Channel D */ |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 377 | snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(0), buf, 1); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 378 | /* Volume Fader Channel B */ |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 379 | snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(1), buf, 2); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 380 | /* Volume Fader Channel A */ |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 381 | snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(2), buf, 3); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 382 | /* Volume Fader Channel C */ |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 383 | snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(3), buf, 4); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 384 | /* Loop Volume */ |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 385 | snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(4), buf, 6); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 386 | /* Crossfader */ |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 387 | snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(7), buf, 7); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 388 | |
| 389 | break; |
| 390 | |
| 391 | case 3: |
| 392 | /* Tempo Fader R */ |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 393 | snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(6), buf, 3); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 394 | /* Tempo Fader L */ |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 395 | snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(5), buf, 4); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 396 | /* Mic Volume */ |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 397 | snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(8), buf, 6); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 398 | /* Cue Mix */ |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 399 | snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(9), buf, 7); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 400 | |
| 401 | break; |
| 402 | |
| 403 | case 4: |
| 404 | /* Wheel distance sensor L */ |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 405 | snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(10), buf, 1); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 406 | /* Wheel distance sensor R */ |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 407 | snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(11), buf, 2); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 408 | /* Channel D EQ - Filter */ |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 409 | snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(12), buf, 3); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 410 | /* Channel D EQ - Low */ |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 411 | snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(13), buf, 4); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 412 | /* Channel D EQ - Mid */ |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 413 | snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(14), buf, 5); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 414 | /* Channel D EQ - Hi */ |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 415 | snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(15), buf, 6); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 416 | /* FX2 - dry/wet */ |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 417 | snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(16), buf, 7); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 418 | |
| 419 | break; |
| 420 | |
| 421 | case 5: |
| 422 | /* FX2 - 1 */ |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 423 | snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(17), buf, 1); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 424 | /* FX2 - 2 */ |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 425 | snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(18), buf, 2); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 426 | /* FX2 - 3 */ |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 427 | snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(19), buf, 3); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 428 | /* Channel B EQ - Filter */ |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 429 | snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(20), buf, 4); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 430 | /* Channel B EQ - Low */ |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 431 | snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(21), buf, 5); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 432 | /* Channel B EQ - Mid */ |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 433 | snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(22), buf, 6); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 434 | /* Channel B EQ - Hi */ |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 435 | snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(23), buf, 7); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 436 | |
| 437 | break; |
| 438 | |
| 439 | case 6: |
| 440 | /* Channel A EQ - Filter */ |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 441 | snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(24), buf, 1); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 442 | /* Channel A EQ - Low */ |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 443 | snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(25), buf, 2); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 444 | /* Channel A EQ - Mid */ |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 445 | snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(26), buf, 3); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 446 | /* Channel A EQ - Hi */ |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 447 | snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(27), buf, 4); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 448 | /* Channel C EQ - Filter */ |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 449 | snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(28), buf, 5); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 450 | /* Channel C EQ - Low */ |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 451 | snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(29), buf, 6); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 452 | /* Channel C EQ - Mid */ |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 453 | snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(30), buf, 7); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 454 | |
| 455 | break; |
| 456 | |
| 457 | case 7: |
| 458 | /* Channel C EQ - Hi */ |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 459 | snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(31), buf, 1); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 460 | /* FX1 - wet/dry */ |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 461 | snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(32), buf, 2); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 462 | /* FX1 - 1 */ |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 463 | snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(33), buf, 3); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 464 | /* FX1 - 2 */ |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 465 | snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(34), buf, 4); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 466 | /* FX1 - 3 */ |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 467 | snd_caiaq_input_report_abs(cdev, KONTROLS4_ABS(35), buf, 5); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 468 | |
| 469 | break; |
| 470 | |
| 471 | default: |
Daniel Mack | f1f6b8f | 2013-03-03 20:46:22 +0100 | [diff] [blame] | 472 | dev_dbg(dev, "%s(): bogus block (id %d)\n", |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 473 | __func__, block_id); |
| 474 | return; |
| 475 | } |
| 476 | |
| 477 | len -= TKS4_MSGBLOCK_SIZE; |
| 478 | buf += TKS4_MSGBLOCK_SIZE; |
| 479 | } |
| 480 | |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 481 | input_sync(cdev->input_dev); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 482 | } |
| 483 | |
William Light | e653510 | 2011-10-10 15:54:23 +0000 | [diff] [blame] | 484 | #define MASCHINE_MSGBLOCK_SIZE 2 |
| 485 | |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 486 | static void snd_usb_caiaq_maschine_dispatch(struct snd_usb_caiaqdev *cdev, |
William Light | e653510 | 2011-10-10 15:54:23 +0000 | [diff] [blame] | 487 | const unsigned char *buf, |
| 488 | unsigned int len) |
| 489 | { |
| 490 | unsigned int i, pad_id; |
Eldad Zack | 4ca231b | 2013-04-29 21:15:46 +0200 | [diff] [blame] | 491 | __le16 *pressure = (__le16 *) buf; |
William Light | e653510 | 2011-10-10 15:54:23 +0000 | [diff] [blame] | 492 | |
| 493 | for (i = 0; i < MASCHINE_PADS; i++) { |
Eldad Zack | 4ca231b | 2013-04-29 21:15:46 +0200 | [diff] [blame] | 494 | pad_id = le16_to_cpu(*pressure) >> 12; |
| 495 | input_report_abs(cdev->input_dev, MASCHINE_PAD(pad_id), |
| 496 | le16_to_cpu(*pressure) & 0xfff); |
| 497 | pressure++; |
William Light | e653510 | 2011-10-10 15:54:23 +0000 | [diff] [blame] | 498 | } |
| 499 | |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 500 | input_sync(cdev->input_dev); |
William Light | e653510 | 2011-10-10 15:54:23 +0000 | [diff] [blame] | 501 | } |
| 502 | |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 503 | static void snd_usb_caiaq_ep4_reply_dispatch(struct urb *urb) |
| 504 | { |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 505 | struct snd_usb_caiaqdev *cdev = urb->context; |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 506 | unsigned char *buf = urb->transfer_buffer; |
Daniel Mack | 2dad940 | 2013-03-04 12:50:05 +0100 | [diff] [blame] | 507 | struct device *dev = &urb->dev->dev; |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 508 | int ret; |
| 509 | |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 510 | if (urb->status || !cdev || urb != cdev->ep4_in_urb) |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 511 | return; |
| 512 | |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 513 | switch (cdev->chip.usb_id) { |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 514 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1): |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 515 | if (urb->actual_length < 24) |
| 516 | goto requeue; |
| 517 | |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 518 | if (buf[0] & 0x3) |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 519 | snd_caiaq_input_read_io(cdev, buf + 1, 7); |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 520 | |
| 521 | if (buf[0] & 0x4) |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 522 | snd_caiaq_input_read_analog(cdev, buf + 8, 16); |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 523 | |
| 524 | break; |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 525 | |
| 526 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4): |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 527 | snd_usb_caiaq_tks4_dispatch(cdev, buf, urb->actual_length); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 528 | break; |
William Light | e653510 | 2011-10-10 15:54:23 +0000 | [diff] [blame] | 529 | |
| 530 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_MASCHINECONTROLLER): |
| 531 | if (urb->actual_length < (MASCHINE_PADS * MASCHINE_MSGBLOCK_SIZE)) |
| 532 | goto requeue; |
| 533 | |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 534 | snd_usb_caiaq_maschine_dispatch(cdev, buf, urb->actual_length); |
William Light | e653510 | 2011-10-10 15:54:23 +0000 | [diff] [blame] | 535 | break; |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | requeue: |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 539 | cdev->ep4_in_urb->actual_length = 0; |
| 540 | ret = usb_submit_urb(cdev->ep4_in_urb, GFP_ATOMIC); |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 541 | if (ret < 0) |
Daniel Mack | f1f6b8f | 2013-03-03 20:46:22 +0100 | [diff] [blame] | 542 | dev_err(dev, "unable to submit urb. OOM!?\n"); |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | static int snd_usb_caiaq_input_open(struct input_dev *idev) |
| 546 | { |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 547 | struct snd_usb_caiaqdev *cdev = input_get_drvdata(idev); |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 548 | |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 549 | if (!cdev) |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 550 | return -EINVAL; |
| 551 | |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 552 | switch (cdev->chip.usb_id) { |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 553 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1): |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 554 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4): |
William Light | e653510 | 2011-10-10 15:54:23 +0000 | [diff] [blame] | 555 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_MASCHINECONTROLLER): |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 556 | if (usb_submit_urb(cdev->ep4_in_urb, GFP_KERNEL) != 0) |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 557 | return -EIO; |
| 558 | break; |
| 559 | } |
| 560 | |
| 561 | return 0; |
| 562 | } |
| 563 | |
| 564 | static void snd_usb_caiaq_input_close(struct input_dev *idev) |
| 565 | { |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 566 | struct snd_usb_caiaqdev *cdev = input_get_drvdata(idev); |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 567 | |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 568 | if (!cdev) |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 569 | return; |
| 570 | |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 571 | switch (cdev->chip.usb_id) { |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 572 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1): |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 573 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4): |
William Light | e653510 | 2011-10-10 15:54:23 +0000 | [diff] [blame] | 574 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_MASCHINECONTROLLER): |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 575 | usb_kill_urb(cdev->ep4_in_urb); |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 576 | break; |
| 577 | } |
| 578 | } |
| 579 | |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 580 | void snd_usb_caiaq_input_dispatch(struct snd_usb_caiaqdev *cdev, |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 581 | char *buf, |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 582 | unsigned int len) |
| 583 | { |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 584 | if (!cdev->input_dev || len < 1) |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 585 | return; |
| 586 | |
| 587 | switch (buf[0]) { |
| 588 | case EP1_CMD_READ_ANALOG: |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 589 | snd_caiaq_input_read_analog(cdev, buf + 1, len - 1); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 590 | break; |
| 591 | case EP1_CMD_READ_ERP: |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 592 | snd_caiaq_input_read_erp(cdev, buf + 1, len - 1); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 593 | break; |
| 594 | case EP1_CMD_READ_IO: |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 595 | snd_caiaq_input_read_io(cdev, buf + 1, len - 1); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 596 | break; |
| 597 | } |
| 598 | } |
| 599 | |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 600 | int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev *cdev) |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 601 | { |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 602 | struct usb_device *usb_dev = cdev->chip.dev; |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 603 | struct input_dev *input; |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 604 | int i, ret = 0; |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 605 | |
| 606 | input = input_allocate_device(); |
| 607 | if (!input) |
| 608 | return -ENOMEM; |
| 609 | |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 610 | usb_make_path(usb_dev, cdev->phys, sizeof(cdev->phys)); |
| 611 | strlcat(cdev->phys, "/input0", sizeof(cdev->phys)); |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 612 | |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 613 | input->name = cdev->product_name; |
| 614 | input->phys = cdev->phys; |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 615 | usb_to_input_id(usb_dev, &input->id); |
| 616 | input->dev.parent = &usb_dev->dev; |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 617 | |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 618 | input_set_drvdata(input, cdev); |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 619 | |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 620 | switch (cdev->chip.usb_id) { |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 621 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL2): |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 622 | input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); |
| 623 | input->absbit[0] = BIT_MASK(ABS_X) | BIT_MASK(ABS_Y) | |
| 624 | BIT_MASK(ABS_Z); |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 625 | BUILD_BUG_ON(sizeof(cdev->keycode) < sizeof(keycode_rk2)); |
| 626 | memcpy(cdev->keycode, keycode_rk2, sizeof(keycode_rk2)); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 627 | input->keycodemax = ARRAY_SIZE(keycode_rk2); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 628 | input_set_abs_params(input, ABS_X, 0, 4096, 0, 10); |
| 629 | input_set_abs_params(input, ABS_Y, 0, 4096, 0, 10); |
| 630 | input_set_abs_params(input, ABS_Z, 0, 4096, 0, 10); |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 631 | snd_usb_caiaq_set_auto_msg(cdev, 1, 10, 0); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 632 | break; |
Daniel Mack | ad1e34b | 2007-09-17 14:45:14 +0200 | [diff] [blame] | 633 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL3): |
Daniel Mack | 8e3cd08 | 2007-11-22 11:40:04 +0100 | [diff] [blame] | 634 | input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); |
| 635 | input->absbit[0] = BIT_MASK(ABS_X) | BIT_MASK(ABS_Y) | |
| 636 | BIT_MASK(ABS_Z); |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 637 | BUILD_BUG_ON(sizeof(cdev->keycode) < sizeof(keycode_rk3)); |
| 638 | memcpy(cdev->keycode, keycode_rk3, sizeof(keycode_rk3)); |
Daniel Mack | ad1e34b | 2007-09-17 14:45:14 +0200 | [diff] [blame] | 639 | input->keycodemax = ARRAY_SIZE(keycode_rk3); |
Daniel Mack | ad1e34b | 2007-09-17 14:45:14 +0200 | [diff] [blame] | 640 | input_set_abs_params(input, ABS_X, 0, 1024, 0, 10); |
| 641 | input_set_abs_params(input, ABS_Y, 0, 1024, 0, 10); |
| 642 | input_set_abs_params(input, ABS_Z, 0, 1024, 0, 10); |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 643 | snd_usb_caiaq_set_auto_msg(cdev, 1, 10, 0); |
Daniel Mack | ad1e34b | 2007-09-17 14:45:14 +0200 | [diff] [blame] | 644 | break; |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 645 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AK1): |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 646 | input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); |
| 647 | input->absbit[0] = BIT_MASK(ABS_X); |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 648 | BUILD_BUG_ON(sizeof(cdev->keycode) < sizeof(keycode_ak1)); |
| 649 | memcpy(cdev->keycode, keycode_ak1, sizeof(keycode_ak1)); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 650 | input->keycodemax = ARRAY_SIZE(keycode_ak1); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 651 | input_set_abs_params(input, ABS_X, 0, 999, 0, 10); |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 652 | snd_usb_caiaq_set_auto_msg(cdev, 1, 0, 5); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 653 | break; |
Daniel Mack | 8e3cd08 | 2007-11-22 11:40:04 +0100 | [diff] [blame] | 654 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER): |
Daniel Mack | 7829d0e | 2007-11-26 09:00:56 +0100 | [diff] [blame] | 655 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER2): |
Daniel Mack | 8e3cd08 | 2007-11-22 11:40:04 +0100 | [diff] [blame] | 656 | input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); |
| 657 | input->absbit[0] = BIT_MASK(ABS_HAT0X) | BIT_MASK(ABS_HAT0Y) | |
| 658 | BIT_MASK(ABS_HAT1X) | BIT_MASK(ABS_HAT1Y) | |
| 659 | BIT_MASK(ABS_HAT2X) | BIT_MASK(ABS_HAT2Y) | |
| 660 | BIT_MASK(ABS_HAT3X) | BIT_MASK(ABS_HAT3Y) | |
| 661 | BIT_MASK(ABS_X) | BIT_MASK(ABS_Y) | |
| 662 | BIT_MASK(ABS_Z); |
| 663 | input->absbit[BIT_WORD(ABS_MISC)] |= BIT_MASK(ABS_MISC); |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 664 | BUILD_BUG_ON(sizeof(cdev->keycode) < sizeof(keycode_kore)); |
| 665 | memcpy(cdev->keycode, keycode_kore, sizeof(keycode_kore)); |
Daniel Mack | 8e3cd08 | 2007-11-22 11:40:04 +0100 | [diff] [blame] | 666 | input->keycodemax = ARRAY_SIZE(keycode_kore); |
| 667 | input_set_abs_params(input, ABS_HAT0X, 0, 999, 0, 10); |
| 668 | input_set_abs_params(input, ABS_HAT0Y, 0, 999, 0, 10); |
| 669 | input_set_abs_params(input, ABS_HAT1X, 0, 999, 0, 10); |
| 670 | input_set_abs_params(input, ABS_HAT1Y, 0, 999, 0, 10); |
| 671 | input_set_abs_params(input, ABS_HAT2X, 0, 999, 0, 10); |
| 672 | input_set_abs_params(input, ABS_HAT2Y, 0, 999, 0, 10); |
| 673 | input_set_abs_params(input, ABS_HAT3X, 0, 999, 0, 10); |
| 674 | input_set_abs_params(input, ABS_HAT3Y, 0, 999, 0, 10); |
| 675 | input_set_abs_params(input, ABS_X, 0, 4096, 0, 10); |
| 676 | input_set_abs_params(input, ABS_Y, 0, 4096, 0, 10); |
| 677 | input_set_abs_params(input, ABS_Z, 0, 4096, 0, 10); |
| 678 | input_set_abs_params(input, ABS_MISC, 0, 255, 0, 1); |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 679 | snd_usb_caiaq_set_auto_msg(cdev, 1, 10, 5); |
Daniel Mack | 8e3cd08 | 2007-11-22 11:40:04 +0100 | [diff] [blame] | 680 | break; |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 681 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1): |
| 682 | input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); |
| 683 | input->absbit[0] = BIT_MASK(ABS_HAT0X) | BIT_MASK(ABS_HAT0Y) | |
| 684 | BIT_MASK(ABS_HAT1X) | BIT_MASK(ABS_HAT1Y) | |
| 685 | BIT_MASK(ABS_HAT2X) | BIT_MASK(ABS_HAT2Y) | |
| 686 | BIT_MASK(ABS_HAT3X) | BIT_MASK(ABS_HAT3Y) | |
| 687 | BIT_MASK(ABS_X) | BIT_MASK(ABS_Y) | |
| 688 | BIT_MASK(ABS_Z); |
| 689 | input->absbit[BIT_WORD(ABS_MISC)] |= BIT_MASK(ABS_MISC); |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 690 | BUILD_BUG_ON(sizeof(cdev->keycode) < KONTROLX1_INPUTS); |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 691 | for (i = 0; i < KONTROLX1_INPUTS; i++) |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 692 | cdev->keycode[i] = BTN_MISC + i; |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 693 | input->keycodemax = KONTROLX1_INPUTS; |
| 694 | |
| 695 | /* analog potentiometers */ |
| 696 | input_set_abs_params(input, ABS_HAT0X, 0, 4096, 0, 10); |
| 697 | input_set_abs_params(input, ABS_HAT0Y, 0, 4096, 0, 10); |
| 698 | input_set_abs_params(input, ABS_HAT1X, 0, 4096, 0, 10); |
| 699 | input_set_abs_params(input, ABS_HAT1Y, 0, 4096, 0, 10); |
| 700 | input_set_abs_params(input, ABS_HAT2X, 0, 4096, 0, 10); |
| 701 | input_set_abs_params(input, ABS_HAT2Y, 0, 4096, 0, 10); |
| 702 | input_set_abs_params(input, ABS_HAT3X, 0, 4096, 0, 10); |
| 703 | input_set_abs_params(input, ABS_HAT3Y, 0, 4096, 0, 10); |
| 704 | |
| 705 | /* rotary encoders */ |
| 706 | input_set_abs_params(input, ABS_X, 0, 0xf, 0, 1); |
| 707 | input_set_abs_params(input, ABS_Y, 0, 0xf, 0, 1); |
| 708 | input_set_abs_params(input, ABS_Z, 0, 0xf, 0, 1); |
| 709 | input_set_abs_params(input, ABS_MISC, 0, 0xf, 0, 1); |
| 710 | |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 711 | cdev->ep4_in_urb = usb_alloc_urb(0, GFP_KERNEL); |
| 712 | if (!cdev->ep4_in_urb) { |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 713 | ret = -ENOMEM; |
| 714 | goto exit_free_idev; |
| 715 | } |
| 716 | |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 717 | usb_fill_bulk_urb(cdev->ep4_in_urb, usb_dev, |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 718 | usb_rcvbulkpipe(usb_dev, 0x4), |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 719 | cdev->ep4_in_buf, EP4_BUFSIZE, |
| 720 | snd_usb_caiaq_ep4_reply_dispatch, cdev); |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 721 | |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 722 | snd_usb_caiaq_set_auto_msg(cdev, 1, 10, 5); |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 723 | |
| 724 | break; |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 725 | |
| 726 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4): |
| 727 | input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 728 | BUILD_BUG_ON(sizeof(cdev->keycode) < KONTROLS4_BUTTONS); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 729 | for (i = 0; i < KONTROLS4_BUTTONS; i++) |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 730 | cdev->keycode[i] = KONTROLS4_BUTTON(i); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 731 | input->keycodemax = KONTROLS4_BUTTONS; |
| 732 | |
| 733 | for (i = 0; i < KONTROLS4_AXIS; i++) { |
| 734 | int axis = KONTROLS4_ABS(i); |
| 735 | input->absbit[BIT_WORD(axis)] |= BIT_MASK(axis); |
| 736 | } |
| 737 | |
| 738 | /* 36 analog potentiometers and faders */ |
| 739 | for (i = 0; i < 36; i++) |
| 740 | input_set_abs_params(input, KONTROLS4_ABS(i), 0, 0xfff, 0, 10); |
| 741 | |
| 742 | /* 2 encoder wheels */ |
| 743 | input_set_abs_params(input, KONTROLS4_ABS(36), 0, 0x3ff, 0, 1); |
| 744 | input_set_abs_params(input, KONTROLS4_ABS(37), 0, 0x3ff, 0, 1); |
| 745 | |
| 746 | /* 9 rotary encoders */ |
| 747 | for (i = 0; i < 9; i++) |
| 748 | input_set_abs_params(input, KONTROLS4_ABS(38+i), 0, 0xf, 0, 1); |
| 749 | |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 750 | cdev->ep4_in_urb = usb_alloc_urb(0, GFP_KERNEL); |
| 751 | if (!cdev->ep4_in_urb) { |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 752 | ret = -ENOMEM; |
| 753 | goto exit_free_idev; |
| 754 | } |
| 755 | |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 756 | usb_fill_bulk_urb(cdev->ep4_in_urb, usb_dev, |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 757 | usb_rcvbulkpipe(usb_dev, 0x4), |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 758 | cdev->ep4_in_buf, EP4_BUFSIZE, |
| 759 | snd_usb_caiaq_ep4_reply_dispatch, cdev); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 760 | |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 761 | snd_usb_caiaq_set_auto_msg(cdev, 1, 10, 5); |
Daniel Mack | 15c5ab6 | 2010-09-10 17:04:57 +0800 | [diff] [blame] | 762 | |
| 763 | break; |
| 764 | |
William Light | e653510 | 2011-10-10 15:54:23 +0000 | [diff] [blame] | 765 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_MASCHINECONTROLLER): |
| 766 | input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); |
| 767 | input->absbit[0] = BIT_MASK(ABS_HAT0X) | BIT_MASK(ABS_HAT0Y) | |
| 768 | BIT_MASK(ABS_HAT1X) | BIT_MASK(ABS_HAT1Y) | |
| 769 | BIT_MASK(ABS_HAT2X) | BIT_MASK(ABS_HAT2Y) | |
| 770 | BIT_MASK(ABS_HAT3X) | BIT_MASK(ABS_HAT3Y) | |
| 771 | BIT_MASK(ABS_RX) | BIT_MASK(ABS_RY) | |
| 772 | BIT_MASK(ABS_RZ); |
| 773 | |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 774 | BUILD_BUG_ON(sizeof(cdev->keycode) < sizeof(keycode_maschine)); |
| 775 | memcpy(cdev->keycode, keycode_maschine, sizeof(keycode_maschine)); |
William Light | e653510 | 2011-10-10 15:54:23 +0000 | [diff] [blame] | 776 | input->keycodemax = ARRAY_SIZE(keycode_maschine); |
| 777 | |
| 778 | for (i = 0; i < MASCHINE_PADS; i++) { |
| 779 | input->absbit[0] |= MASCHINE_PAD(i); |
| 780 | input_set_abs_params(input, MASCHINE_PAD(i), 0, 0xfff, 5, 10); |
| 781 | } |
| 782 | |
| 783 | input_set_abs_params(input, ABS_HAT0X, 0, 999, 0, 10); |
| 784 | input_set_abs_params(input, ABS_HAT0Y, 0, 999, 0, 10); |
| 785 | input_set_abs_params(input, ABS_HAT1X, 0, 999, 0, 10); |
| 786 | input_set_abs_params(input, ABS_HAT1Y, 0, 999, 0, 10); |
| 787 | input_set_abs_params(input, ABS_HAT2X, 0, 999, 0, 10); |
| 788 | input_set_abs_params(input, ABS_HAT2Y, 0, 999, 0, 10); |
| 789 | input_set_abs_params(input, ABS_HAT3X, 0, 999, 0, 10); |
| 790 | input_set_abs_params(input, ABS_HAT3Y, 0, 999, 0, 10); |
| 791 | input_set_abs_params(input, ABS_RX, 0, 999, 0, 10); |
| 792 | input_set_abs_params(input, ABS_RY, 0, 999, 0, 10); |
| 793 | input_set_abs_params(input, ABS_RZ, 0, 999, 0, 10); |
| 794 | |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 795 | cdev->ep4_in_urb = usb_alloc_urb(0, GFP_KERNEL); |
| 796 | if (!cdev->ep4_in_urb) { |
William Light | e653510 | 2011-10-10 15:54:23 +0000 | [diff] [blame] | 797 | ret = -ENOMEM; |
| 798 | goto exit_free_idev; |
| 799 | } |
| 800 | |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 801 | usb_fill_bulk_urb(cdev->ep4_in_urb, usb_dev, |
William Light | e653510 | 2011-10-10 15:54:23 +0000 | [diff] [blame] | 802 | usb_rcvbulkpipe(usb_dev, 0x4), |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 803 | cdev->ep4_in_buf, EP4_BUFSIZE, |
| 804 | snd_usb_caiaq_ep4_reply_dispatch, cdev); |
William Light | e653510 | 2011-10-10 15:54:23 +0000 | [diff] [blame] | 805 | |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 806 | snd_usb_caiaq_set_auto_msg(cdev, 1, 10, 5); |
William Light | e653510 | 2011-10-10 15:54:23 +0000 | [diff] [blame] | 807 | break; |
| 808 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 809 | default: |
| 810 | /* no input methods supported on this device */ |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 811 | goto exit_free_idev; |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 812 | } |
| 813 | |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 814 | input->open = snd_usb_caiaq_input_open; |
| 815 | input->close = snd_usb_caiaq_input_close; |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 816 | input->keycode = cdev->keycode; |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 817 | input->keycodesize = sizeof(unsigned short); |
| 818 | for (i = 0; i < input->keycodemax; i++) |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 819 | __set_bit(cdev->keycode[i], input->keybit); |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 820 | |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 821 | cdev->input_dev = input; |
William Light | 3d37fbe | 2011-10-10 15:54:22 +0000 | [diff] [blame] | 822 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 823 | ret = input_register_device(input); |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 824 | if (ret < 0) |
| 825 | goto exit_free_idev; |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 826 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 827 | return 0; |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 828 | |
| 829 | exit_free_idev: |
| 830 | input_free_device(input); |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 831 | cdev->input_dev = NULL; |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 832 | return ret; |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 833 | } |
| 834 | |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 835 | void snd_usb_caiaq_input_free(struct snd_usb_caiaqdev *cdev) |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 836 | { |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 837 | if (!cdev || !cdev->input_dev) |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 838 | return; |
| 839 | |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 840 | usb_kill_urb(cdev->ep4_in_urb); |
| 841 | usb_free_urb(cdev->ep4_in_urb); |
| 842 | cdev->ep4_in_urb = NULL; |
Daniel Mack | 6da7a2a | 2010-03-22 13:13:37 +0100 | [diff] [blame] | 843 | |
Daniel Mack | 1c8470c | 2013-03-03 20:46:21 +0100 | [diff] [blame] | 844 | input_unregister_device(cdev->input_dev); |
| 845 | cdev->input_dev = NULL; |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 846 | } |