diff options
Diffstat (limited to 'sound/usb/caiaq/input.c')
-rw-r--r-- | sound/usb/caiaq/input.c | 248 |
1 files changed, 222 insertions, 26 deletions
diff --git a/sound/usb/caiaq/input.c b/sound/usb/caiaq/input.c index dcb620796d9e..4432ef7a70a9 100644 --- a/sound/usb/caiaq/input.c +++ b/sound/usb/caiaq/input.c | |||
@@ -67,7 +67,12 @@ static unsigned short keycode_kore[] = { | |||
67 | KEY_BRL_DOT5 | 67 | KEY_BRL_DOT5 |
68 | }; | 68 | }; |
69 | 69 | ||
70 | #define KONTROLX1_INPUTS 40 | 70 | #define KONTROLX1_INPUTS (40) |
71 | #define KONTROLS4_BUTTONS (12 * 8) | ||
72 | #define KONTROLS4_AXIS (46) | ||
73 | |||
74 | #define KONTROLS4_BUTTON(X) ((X) + BTN_MISC) | ||
75 | #define KONTROLS4_ABS(X) ((X) + ABS_HAT0X) | ||
71 | 76 | ||
72 | #define DEG90 (range / 2) | 77 | #define DEG90 (range / 2) |
73 | #define DEG180 (range) | 78 | #define DEG180 (range) |
@@ -139,6 +144,13 @@ static unsigned int decode_erp(unsigned char a, unsigned char b) | |||
139 | #undef HIGH_PEAK | 144 | #undef HIGH_PEAK |
140 | #undef LOW_PEAK | 145 | #undef LOW_PEAK |
141 | 146 | ||
147 | static inline void snd_caiaq_input_report_abs(struct snd_usb_caiaqdev *dev, | ||
148 | int axis, const unsigned char *buf, | ||
149 | int offset) | ||
150 | { | ||
151 | input_report_abs(dev->input_dev, axis, | ||
152 | (buf[offset * 2] << 8) | buf[offset * 2 + 1]); | ||
153 | } | ||
142 | 154 | ||
143 | static void snd_caiaq_input_read_analog(struct snd_usb_caiaqdev *dev, | 155 | static void snd_caiaq_input_read_analog(struct snd_usb_caiaqdev *dev, |
144 | const unsigned char *buf, | 156 | const unsigned char *buf, |
@@ -148,36 +160,30 @@ static void snd_caiaq_input_read_analog(struct snd_usb_caiaqdev *dev, | |||
148 | 160 | ||
149 | switch (dev->chip.usb_id) { | 161 | switch (dev->chip.usb_id) { |
150 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL2): | 162 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL2): |
151 | input_report_abs(input_dev, ABS_X, (buf[4] << 8) | buf[5]); | 163 | snd_caiaq_input_report_abs(dev, ABS_X, buf, 2); |
152 | input_report_abs(input_dev, ABS_Y, (buf[0] << 8) | buf[1]); | 164 | snd_caiaq_input_report_abs(dev, ABS_Y, buf, 0); |
153 | input_report_abs(input_dev, ABS_Z, (buf[2] << 8) | buf[3]); | 165 | snd_caiaq_input_report_abs(dev, ABS_Z, buf, 1); |
154 | input_sync(input_dev); | ||
155 | break; | 166 | break; |
156 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL3): | 167 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL3): |
157 | input_report_abs(input_dev, ABS_X, (buf[0] << 8) | buf[1]); | ||
158 | input_report_abs(input_dev, ABS_Y, (buf[2] << 8) | buf[3]); | ||
159 | input_report_abs(input_dev, ABS_Z, (buf[4] << 8) | buf[5]); | ||
160 | input_sync(input_dev); | ||
161 | break; | ||
162 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER): | 168 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER): |
163 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER2): | 169 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER2): |
164 | input_report_abs(input_dev, ABS_X, (buf[0] << 8) | buf[1]); | 170 | snd_caiaq_input_report_abs(dev, ABS_X, buf, 0); |
165 | input_report_abs(input_dev, ABS_Y, (buf[2] << 8) | buf[3]); | 171 | snd_caiaq_input_report_abs(dev, ABS_Y, buf, 1); |
166 | input_report_abs(input_dev, ABS_Z, (buf[4] << 8) | buf[5]); | 172 | snd_caiaq_input_report_abs(dev, ABS_Z, buf, 2); |
167 | input_sync(input_dev); | ||
168 | break; | 173 | break; |
169 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1): | 174 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1): |
170 | input_report_abs(input_dev, ABS_HAT0X, (buf[8] << 8) | buf[9]); | 175 | snd_caiaq_input_report_abs(dev, ABS_HAT0X, buf, 4); |
171 | input_report_abs(input_dev, ABS_HAT0Y, (buf[4] << 8) | buf[5]); | 176 | snd_caiaq_input_report_abs(dev, ABS_HAT0Y, buf, 2); |
172 | input_report_abs(input_dev, ABS_HAT1X, (buf[12] << 8) | buf[13]); | 177 | snd_caiaq_input_report_abs(dev, ABS_HAT1X, buf, 6); |
173 | input_report_abs(input_dev, ABS_HAT1Y, (buf[2] << 8) | buf[3]); | 178 | snd_caiaq_input_report_abs(dev, ABS_HAT1Y, buf, 1); |
174 | input_report_abs(input_dev, ABS_HAT2X, (buf[14] << 8) | buf[15]); | 179 | snd_caiaq_input_report_abs(dev, ABS_HAT2X, buf, 7); |
175 | input_report_abs(input_dev, ABS_HAT2Y, (buf[0] << 8) | buf[1]); | 180 | snd_caiaq_input_report_abs(dev, ABS_HAT2Y, buf, 0); |
176 | input_report_abs(input_dev, ABS_HAT3X, (buf[10] << 8) | buf[11]); | 181 | snd_caiaq_input_report_abs(dev, ABS_HAT3X, buf, 5); |
177 | input_report_abs(input_dev, ABS_HAT3Y, (buf[6] << 8) | buf[7]); | 182 | snd_caiaq_input_report_abs(dev, ABS_HAT3Y, buf, 3); |
178 | input_sync(input_dev); | ||
179 | break; | 183 | break; |
180 | } | 184 | } |
185 | |||
186 | input_sync(input_dev); | ||
181 | } | 187 | } |
182 | 188 | ||
183 | static void snd_caiaq_input_read_erp(struct snd_usb_caiaqdev *dev, | 189 | static void snd_caiaq_input_read_erp(struct snd_usb_caiaqdev *dev, |
@@ -250,6 +256,150 @@ static void snd_caiaq_input_read_io(struct snd_usb_caiaqdev *dev, | |||
250 | input_sync(input_dev); | 256 | input_sync(input_dev); |
251 | } | 257 | } |
252 | 258 | ||
259 | #define TKS4_MSGBLOCK_SIZE 16 | ||
260 | |||
261 | static void snd_usb_caiaq_tks4_dispatch(struct snd_usb_caiaqdev *dev, | ||
262 | const unsigned char *buf, | ||
263 | unsigned int len) | ||
264 | { | ||
265 | while (len) { | ||
266 | unsigned int i, block_id = (buf[0] << 8) | buf[1]; | ||
267 | |||
268 | switch (block_id) { | ||
269 | case 0: | ||
270 | /* buttons */ | ||
271 | for (i = 0; i < KONTROLS4_BUTTONS; i++) | ||
272 | input_report_key(dev->input_dev, KONTROLS4_BUTTON(i), | ||
273 | (buf[4 + (i / 8)] >> (i % 8)) & 1); | ||
274 | break; | ||
275 | |||
276 | case 1: | ||
277 | /* left wheel */ | ||
278 | input_report_abs(dev->input_dev, KONTROLS4_ABS(36), buf[9] | ((buf[8] & 0x3) << 8)); | ||
279 | /* right wheel */ | ||
280 | input_report_abs(dev->input_dev, KONTROLS4_ABS(37), buf[13] | ((buf[12] & 0x3) << 8)); | ||
281 | |||
282 | /* rotary encoders */ | ||
283 | input_report_abs(dev->input_dev, KONTROLS4_ABS(38), buf[3] & 0xf); | ||
284 | input_report_abs(dev->input_dev, KONTROLS4_ABS(39), buf[4] >> 4); | ||
285 | input_report_abs(dev->input_dev, KONTROLS4_ABS(40), buf[4] & 0xf); | ||
286 | input_report_abs(dev->input_dev, KONTROLS4_ABS(41), buf[5] >> 4); | ||
287 | input_report_abs(dev->input_dev, KONTROLS4_ABS(42), buf[5] & 0xf); | ||
288 | input_report_abs(dev->input_dev, KONTROLS4_ABS(43), buf[6] >> 4); | ||
289 | input_report_abs(dev->input_dev, KONTROLS4_ABS(44), buf[6] & 0xf); | ||
290 | input_report_abs(dev->input_dev, KONTROLS4_ABS(45), buf[7] >> 4); | ||
291 | input_report_abs(dev->input_dev, KONTROLS4_ABS(46), buf[7] & 0xf); | ||
292 | |||
293 | break; | ||
294 | case 2: | ||
295 | /* Volume Fader Channel D */ | ||
296 | snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(0), buf, 1); | ||
297 | /* Volume Fader Channel B */ | ||
298 | snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(1), buf, 2); | ||
299 | /* Volume Fader Channel A */ | ||
300 | snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(2), buf, 3); | ||
301 | /* Volume Fader Channel C */ | ||
302 | snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(3), buf, 4); | ||
303 | /* Loop Volume */ | ||
304 | snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(4), buf, 6); | ||
305 | /* Crossfader */ | ||
306 | snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(7), buf, 7); | ||
307 | |||
308 | break; | ||
309 | |||
310 | case 3: | ||
311 | /* Tempo Fader R */ | ||
312 | snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(6), buf, 3); | ||
313 | /* Tempo Fader L */ | ||
314 | snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(5), buf, 4); | ||
315 | /* Mic Volume */ | ||
316 | snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(8), buf, 6); | ||
317 | /* Cue Mix */ | ||
318 | snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(9), buf, 7); | ||
319 | |||
320 | break; | ||
321 | |||
322 | case 4: | ||
323 | /* Wheel distance sensor L */ | ||
324 | snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(10), buf, 1); | ||
325 | /* Wheel distance sensor R */ | ||
326 | snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(11), buf, 2); | ||
327 | /* Channel D EQ - Filter */ | ||
328 | snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(12), buf, 3); | ||
329 | /* Channel D EQ - Low */ | ||
330 | snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(13), buf, 4); | ||
331 | /* Channel D EQ - Mid */ | ||
332 | snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(14), buf, 5); | ||
333 | /* Channel D EQ - Hi */ | ||
334 | snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(15), buf, 6); | ||
335 | /* FX2 - dry/wet */ | ||
336 | snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(16), buf, 7); | ||
337 | |||
338 | break; | ||
339 | |||
340 | case 5: | ||
341 | /* FX2 - 1 */ | ||
342 | snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(17), buf, 1); | ||
343 | /* FX2 - 2 */ | ||
344 | snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(18), buf, 2); | ||
345 | /* FX2 - 3 */ | ||
346 | snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(19), buf, 3); | ||
347 | /* Channel B EQ - Filter */ | ||
348 | snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(20), buf, 4); | ||
349 | /* Channel B EQ - Low */ | ||
350 | snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(21), buf, 5); | ||
351 | /* Channel B EQ - Mid */ | ||
352 | snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(22), buf, 6); | ||
353 | /* Channel B EQ - Hi */ | ||
354 | snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(23), buf, 7); | ||
355 | |||
356 | break; | ||
357 | |||
358 | case 6: | ||
359 | /* Channel A EQ - Filter */ | ||
360 | snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(24), buf, 1); | ||
361 | /* Channel A EQ - Low */ | ||
362 | snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(25), buf, 2); | ||
363 | /* Channel A EQ - Mid */ | ||
364 | snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(26), buf, 3); | ||
365 | /* Channel A EQ - Hi */ | ||
366 | snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(27), buf, 4); | ||
367 | /* Channel C EQ - Filter */ | ||
368 | snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(28), buf, 5); | ||
369 | /* Channel C EQ - Low */ | ||
370 | snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(29), buf, 6); | ||
371 | /* Channel C EQ - Mid */ | ||
372 | snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(30), buf, 7); | ||
373 | |||
374 | break; | ||
375 | |||
376 | case 7: | ||
377 | /* Channel C EQ - Hi */ | ||
378 | snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(31), buf, 1); | ||
379 | /* FX1 - wet/dry */ | ||
380 | snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(32), buf, 2); | ||
381 | /* FX1 - 1 */ | ||
382 | snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(33), buf, 3); | ||
383 | /* FX1 - 2 */ | ||
384 | snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(34), buf, 4); | ||
385 | /* FX1 - 3 */ | ||
386 | snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(35), buf, 5); | ||
387 | |||
388 | break; | ||
389 | |||
390 | default: | ||
391 | debug("%s(): bogus block (id %d)\n", | ||
392 | __func__, block_id); | ||
393 | return; | ||
394 | } | ||
395 | |||
396 | len -= TKS4_MSGBLOCK_SIZE; | ||
397 | buf += TKS4_MSGBLOCK_SIZE; | ||
398 | } | ||
399 | |||
400 | input_sync(dev->input_dev); | ||
401 | } | ||
402 | |||
253 | static void snd_usb_caiaq_ep4_reply_dispatch(struct urb *urb) | 403 | static void snd_usb_caiaq_ep4_reply_dispatch(struct urb *urb) |
254 | { | 404 | { |
255 | struct snd_usb_caiaqdev *dev = urb->context; | 405 | struct snd_usb_caiaqdev *dev = urb->context; |
@@ -259,11 +409,11 @@ static void snd_usb_caiaq_ep4_reply_dispatch(struct urb *urb) | |||
259 | if (urb->status || !dev || urb != dev->ep4_in_urb) | 409 | if (urb->status || !dev || urb != dev->ep4_in_urb) |
260 | return; | 410 | return; |
261 | 411 | ||
262 | if (urb->actual_length < 24) | ||
263 | goto requeue; | ||
264 | |||
265 | switch (dev->chip.usb_id) { | 412 | switch (dev->chip.usb_id) { |
266 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1): | 413 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1): |
414 | if (urb->actual_length < 24) | ||
415 | goto requeue; | ||
416 | |||
267 | if (buf[0] & 0x3) | 417 | if (buf[0] & 0x3) |
268 | snd_caiaq_input_read_io(dev, buf + 1, 7); | 418 | snd_caiaq_input_read_io(dev, buf + 1, 7); |
269 | 419 | ||
@@ -271,6 +421,10 @@ static void snd_usb_caiaq_ep4_reply_dispatch(struct urb *urb) | |||
271 | snd_caiaq_input_read_analog(dev, buf + 8, 16); | 421 | snd_caiaq_input_read_analog(dev, buf + 8, 16); |
272 | 422 | ||
273 | break; | 423 | break; |
424 | |||
425 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4): | ||
426 | snd_usb_caiaq_tks4_dispatch(dev, buf, urb->actual_length); | ||
427 | break; | ||
274 | } | 428 | } |
275 | 429 | ||
276 | requeue: | 430 | requeue: |
@@ -289,6 +443,7 @@ static int snd_usb_caiaq_input_open(struct input_dev *idev) | |||
289 | 443 | ||
290 | switch (dev->chip.usb_id) { | 444 | switch (dev->chip.usb_id) { |
291 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1): | 445 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1): |
446 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4): | ||
292 | if (usb_submit_urb(dev->ep4_in_urb, GFP_KERNEL) != 0) | 447 | if (usb_submit_urb(dev->ep4_in_urb, GFP_KERNEL) != 0) |
293 | return -EIO; | 448 | return -EIO; |
294 | break; | 449 | break; |
@@ -306,6 +461,7 @@ static void snd_usb_caiaq_input_close(struct input_dev *idev) | |||
306 | 461 | ||
307 | switch (dev->chip.usb_id) { | 462 | switch (dev->chip.usb_id) { |
308 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1): | 463 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1): |
464 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4): | ||
309 | usb_kill_urb(dev->ep4_in_urb); | 465 | usb_kill_urb(dev->ep4_in_urb); |
310 | break; | 466 | break; |
311 | } | 467 | } |
@@ -456,6 +612,46 @@ int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev *dev) | |||
456 | snd_usb_caiaq_set_auto_msg(dev, 1, 10, 5); | 612 | snd_usb_caiaq_set_auto_msg(dev, 1, 10, 5); |
457 | 613 | ||
458 | break; | 614 | break; |
615 | |||
616 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4): | ||
617 | input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); | ||
618 | BUILD_BUG_ON(sizeof(dev->keycode) < KONTROLS4_BUTTONS); | ||
619 | for (i = 0; i < KONTROLS4_BUTTONS; i++) | ||
620 | dev->keycode[i] = KONTROLS4_BUTTON(i); | ||
621 | input->keycodemax = KONTROLS4_BUTTONS; | ||
622 | |||
623 | for (i = 0; i < KONTROLS4_AXIS; i++) { | ||
624 | int axis = KONTROLS4_ABS(i); | ||
625 | input->absbit[BIT_WORD(axis)] |= BIT_MASK(axis); | ||
626 | } | ||
627 | |||
628 | /* 36 analog potentiometers and faders */ | ||
629 | for (i = 0; i < 36; i++) | ||
630 | input_set_abs_params(input, KONTROLS4_ABS(i), 0, 0xfff, 0, 10); | ||
631 | |||
632 | /* 2 encoder wheels */ | ||
633 | input_set_abs_params(input, KONTROLS4_ABS(36), 0, 0x3ff, 0, 1); | ||
634 | input_set_abs_params(input, KONTROLS4_ABS(37), 0, 0x3ff, 0, 1); | ||
635 | |||
636 | /* 9 rotary encoders */ | ||
637 | for (i = 0; i < 9; i++) | ||
638 | input_set_abs_params(input, KONTROLS4_ABS(38+i), 0, 0xf, 0, 1); | ||
639 | |||
640 | dev->ep4_in_urb = usb_alloc_urb(0, GFP_KERNEL); | ||
641 | if (!dev->ep4_in_urb) { | ||
642 | ret = -ENOMEM; | ||
643 | goto exit_free_idev; | ||
644 | } | ||
645 | |||
646 | usb_fill_bulk_urb(dev->ep4_in_urb, usb_dev, | ||
647 | usb_rcvbulkpipe(usb_dev, 0x4), | ||
648 | dev->ep4_in_buf, EP4_BUFSIZE, | ||
649 | snd_usb_caiaq_ep4_reply_dispatch, dev); | ||
650 | |||
651 | snd_usb_caiaq_set_auto_msg(dev, 1, 10, 5); | ||
652 | |||
653 | break; | ||
654 | |||
459 | default: | 655 | default: |
460 | /* no input methods supported on this device */ | 656 | /* no input methods supported on this device */ |
461 | goto exit_free_idev; | 657 | goto exit_free_idev; |