2 * Copyright (c) 2006,2007 Daniel Mack, Tim Ruetz
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.
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.
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
19 #include <linux/gfp.h>
20 #include <linux/init.h>
21 #include <linux/usb.h>
22 #include <linux/usb/input.h>
23 #include <sound/core.h>
24 #include <sound/pcm.h>
29 static unsigned short keycode_ak1
[] = { KEY_C
, KEY_B
, KEY_A
};
30 static unsigned short keycode_rk2
[] = { KEY_1
, KEY_2
, KEY_3
, KEY_4
,
31 KEY_5
, KEY_6
, KEY_7
};
32 static unsigned short keycode_rk3
[] = { KEY_1
, KEY_2
, KEY_3
, KEY_4
,
33 KEY_5
, KEY_6
, KEY_7
, KEY_8
, KEY_9
};
35 static unsigned short keycode_kore
[] = {
36 KEY_FN_F1
, /* "menu" */
37 KEY_FN_F7
, /* "lcd backlight */
38 KEY_FN_F2
, /* "control" */
39 KEY_FN_F3
, /* "enter" */
40 KEY_FN_F4
, /* "view" */
41 KEY_FN_F5
, /* "esc" */
42 KEY_FN_F6
, /* "sound" */
43 KEY_FN_F8
, /* array spacer, never triggered. */
48 KEY_SOUND
, /* "listen" */
52 BTN_4
, /* 8 softkeys */
60 KEY_BRL_DOT4
, /* touch sensitive knobs */
70 #define MASCHINE_BUTTONS (42)
71 #define MASCHINE_BUTTON(X) ((X) + BTN_MISC)
72 #define MASCHINE_PADS (16)
73 #define MASCHINE_PAD(X) ((X) + ABS_PRESSURE)
75 static unsigned short keycode_maschine
[] = {
76 MASCHINE_BUTTON(40), /* mute */
77 MASCHINE_BUTTON(39), /* solo */
78 MASCHINE_BUTTON(38), /* select */
79 MASCHINE_BUTTON(37), /* duplicate */
80 MASCHINE_BUTTON(36), /* navigate */
81 MASCHINE_BUTTON(35), /* pad mode */
82 MASCHINE_BUTTON(34), /* pattern */
83 MASCHINE_BUTTON(33), /* scene */
84 KEY_RESERVED
, /* spacer */
86 MASCHINE_BUTTON(30), /* rec */
87 MASCHINE_BUTTON(31), /* erase */
88 MASCHINE_BUTTON(32), /* shift */
89 MASCHINE_BUTTON(28), /* grid */
90 MASCHINE_BUTTON(27), /* > */
91 MASCHINE_BUTTON(26), /* < */
92 MASCHINE_BUTTON(25), /* restart */
94 MASCHINE_BUTTON(21), /* E */
95 MASCHINE_BUTTON(22), /* F */
96 MASCHINE_BUTTON(23), /* G */
97 MASCHINE_BUTTON(24), /* H */
98 MASCHINE_BUTTON(20), /* D */
99 MASCHINE_BUTTON(19), /* C */
100 MASCHINE_BUTTON(18), /* B */
101 MASCHINE_BUTTON(17), /* A */
103 MASCHINE_BUTTON(0), /* control */
104 MASCHINE_BUTTON(2), /* browse */
105 MASCHINE_BUTTON(4), /* < */
106 MASCHINE_BUTTON(6), /* snap */
107 MASCHINE_BUTTON(7), /* autowrite */
108 MASCHINE_BUTTON(5), /* > */
109 MASCHINE_BUTTON(3), /* sampling */
110 MASCHINE_BUTTON(1), /* step */
112 MASCHINE_BUTTON(15), /* 8 softkeys */
121 MASCHINE_BUTTON(16), /* note repeat */
122 MASCHINE_BUTTON(29) /* play */
125 #define KONTROLX1_INPUTS (40)
126 #define KONTROLS4_BUTTONS (12 * 8)
127 #define KONTROLS4_AXIS (46)
129 #define KONTROLS4_BUTTON(X) ((X) + BTN_MISC)
130 #define KONTROLS4_ABS(X) ((X) + ABS_HAT0X)
132 #define DEG90 (range / 2)
133 #define DEG180 (range)
134 #define DEG270 (DEG90 + DEG180)
135 #define DEG360 (DEG180 * 2)
136 #define HIGH_PEAK (268)
137 #define LOW_PEAK (-7)
139 /* some of these devices have endless rotation potentiometers
140 * built in which use two tapers, 90 degrees phase shifted.
141 * this algorithm decodes them to one single value, ranging
143 static unsigned int decode_erp(unsigned char a
, unsigned char b
)
145 int weight_a
, weight_b
;
148 int range
= HIGH_PEAK
- LOW_PEAK
;
149 int mid_value
= (HIGH_PEAK
+ LOW_PEAK
) / 2;
151 weight_b
= abs(mid_value
- a
) - (range
/ 2 - 100) / 2;
159 weight_a
= 100 - weight_b
;
162 /* 0..90 and 270..360 degrees */
163 pos_b
= b
- LOW_PEAK
+ DEG270
;
167 /* 90..270 degrees */
168 pos_b
= HIGH_PEAK
- b
+ DEG90
;
173 pos_a
= a
- LOW_PEAK
;
175 /* 180..360 degrees */
176 pos_a
= HIGH_PEAK
- a
+ DEG180
;
178 /* interpolate both slider values, depending on weight factors */
180 ret
= pos_a
* weight_a
+ pos_b
* weight_b
;
182 /* normalize to 0..999 */
202 static inline void snd_caiaq_input_report_abs(struct snd_usb_caiaqdev
*dev
,
203 int axis
, const unsigned char *buf
,
206 input_report_abs(dev
->input_dev
, axis
,
207 (buf
[offset
* 2] << 8) | buf
[offset
* 2 + 1]);
210 static void snd_caiaq_input_read_analog(struct snd_usb_caiaqdev
*dev
,
211 const unsigned char *buf
,
214 struct input_dev
*input_dev
= dev
->input_dev
;
216 switch (dev
->chip
.usb_id
) {
217 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_RIGKONTROL2
):
218 snd_caiaq_input_report_abs(dev
, ABS_X
, buf
, 2);
219 snd_caiaq_input_report_abs(dev
, ABS_Y
, buf
, 0);
220 snd_caiaq_input_report_abs(dev
, ABS_Z
, buf
, 1);
222 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_RIGKONTROL3
):
223 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_KORECONTROLLER
):
224 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_KORECONTROLLER2
):
225 snd_caiaq_input_report_abs(dev
, ABS_X
, buf
, 0);
226 snd_caiaq_input_report_abs(dev
, ABS_Y
, buf
, 1);
227 snd_caiaq_input_report_abs(dev
, ABS_Z
, buf
, 2);
229 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_TRAKTORKONTROLX1
):
230 snd_caiaq_input_report_abs(dev
, ABS_HAT0X
, buf
, 4);
231 snd_caiaq_input_report_abs(dev
, ABS_HAT0Y
, buf
, 2);
232 snd_caiaq_input_report_abs(dev
, ABS_HAT1X
, buf
, 6);
233 snd_caiaq_input_report_abs(dev
, ABS_HAT1Y
, buf
, 1);
234 snd_caiaq_input_report_abs(dev
, ABS_HAT2X
, buf
, 7);
235 snd_caiaq_input_report_abs(dev
, ABS_HAT2Y
, buf
, 0);
236 snd_caiaq_input_report_abs(dev
, ABS_HAT3X
, buf
, 5);
237 snd_caiaq_input_report_abs(dev
, ABS_HAT3Y
, buf
, 3);
241 input_sync(input_dev
);
244 static void snd_caiaq_input_read_erp(struct snd_usb_caiaqdev
*dev
,
245 const char *buf
, unsigned int len
)
247 struct input_dev
*input_dev
= dev
->input_dev
;
250 switch (dev
->chip
.usb_id
) {
251 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_AK1
):
252 i
= decode_erp(buf
[0], buf
[1]);
253 input_report_abs(input_dev
, ABS_X
, i
);
254 input_sync(input_dev
);
256 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_KORECONTROLLER
):
257 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_KORECONTROLLER2
):
258 i
= decode_erp(buf
[7], buf
[5]);
259 input_report_abs(input_dev
, ABS_HAT0X
, i
);
260 i
= decode_erp(buf
[12], buf
[14]);
261 input_report_abs(input_dev
, ABS_HAT0Y
, i
);
262 i
= decode_erp(buf
[15], buf
[13]);
263 input_report_abs(input_dev
, ABS_HAT1X
, i
);
264 i
= decode_erp(buf
[0], buf
[2]);
265 input_report_abs(input_dev
, ABS_HAT1Y
, i
);
266 i
= decode_erp(buf
[3], buf
[1]);
267 input_report_abs(input_dev
, ABS_HAT2X
, i
);
268 i
= decode_erp(buf
[8], buf
[10]);
269 input_report_abs(input_dev
, ABS_HAT2Y
, i
);
270 i
= decode_erp(buf
[11], buf
[9]);
271 input_report_abs(input_dev
, ABS_HAT3X
, i
);
272 i
= decode_erp(buf
[4], buf
[6]);
273 input_report_abs(input_dev
, ABS_HAT3Y
, i
);
274 input_sync(input_dev
);
277 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_MASCHINECONTROLLER
):
278 /* 4 under the left screen */
279 input_report_abs(input_dev
, ABS_HAT0X
, decode_erp(buf
[21], buf
[20]));
280 input_report_abs(input_dev
, ABS_HAT0Y
, decode_erp(buf
[15], buf
[14]));
281 input_report_abs(input_dev
, ABS_HAT1X
, decode_erp(buf
[9], buf
[8]));
282 input_report_abs(input_dev
, ABS_HAT1Y
, decode_erp(buf
[3], buf
[2]));
284 /* 4 under the right screen */
285 input_report_abs(input_dev
, ABS_HAT2X
, decode_erp(buf
[19], buf
[18]));
286 input_report_abs(input_dev
, ABS_HAT2Y
, decode_erp(buf
[13], buf
[12]));
287 input_report_abs(input_dev
, ABS_HAT3X
, decode_erp(buf
[7], buf
[6]));
288 input_report_abs(input_dev
, ABS_HAT3Y
, decode_erp(buf
[1], buf
[0]));
291 input_report_abs(input_dev
, ABS_RX
, decode_erp(buf
[17], buf
[16]));
293 input_report_abs(input_dev
, ABS_RY
, decode_erp(buf
[11], buf
[10]));
295 input_report_abs(input_dev
, ABS_RZ
, decode_erp(buf
[5], buf
[4]));
297 input_sync(input_dev
);
302 static void snd_caiaq_input_read_io(struct snd_usb_caiaqdev
*dev
,
303 unsigned char *buf
, unsigned int len
)
305 struct input_dev
*input_dev
= dev
->input_dev
;
306 unsigned short *keycode
= input_dev
->keycode
;
312 if (input_dev
->id
.product
== USB_PID_RIGKONTROL2
)
313 for (i
= 0; i
< len
; i
++)
316 for (i
= 0; i
< input_dev
->keycodemax
&& i
< len
* 8; i
++)
317 input_report_key(input_dev
, keycode
[i
],
318 buf
[i
/ 8] & (1 << (i
% 8)));
320 switch (dev
->chip
.usb_id
) {
321 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_KORECONTROLLER
):
322 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_KORECONTROLLER2
):
323 input_report_abs(dev
->input_dev
, ABS_MISC
, 255 - buf
[4]);
325 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_TRAKTORKONTROLX1
):
326 /* rotary encoders */
327 input_report_abs(dev
->input_dev
, ABS_X
, buf
[5] & 0xf);
328 input_report_abs(dev
->input_dev
, ABS_Y
, buf
[5] >> 4);
329 input_report_abs(dev
->input_dev
, ABS_Z
, buf
[6] & 0xf);
330 input_report_abs(dev
->input_dev
, ABS_MISC
, buf
[6] >> 4);
334 input_sync(input_dev
);
337 #define TKS4_MSGBLOCK_SIZE 16
339 static void snd_usb_caiaq_tks4_dispatch(struct snd_usb_caiaqdev
*dev
,
340 const unsigned char *buf
,
344 unsigned int i
, block_id
= (buf
[0] << 8) | buf
[1];
349 for (i
= 0; i
< KONTROLS4_BUTTONS
; i
++)
350 input_report_key(dev
->input_dev
, KONTROLS4_BUTTON(i
),
351 (buf
[4 + (i
/ 8)] >> (i
% 8)) & 1);
356 input_report_abs(dev
->input_dev
, KONTROLS4_ABS(36), buf
[9] | ((buf
[8] & 0x3) << 8));
358 input_report_abs(dev
->input_dev
, KONTROLS4_ABS(37), buf
[13] | ((buf
[12] & 0x3) << 8));
360 /* rotary encoders */
361 input_report_abs(dev
->input_dev
, KONTROLS4_ABS(38), buf
[3] & 0xf);
362 input_report_abs(dev
->input_dev
, KONTROLS4_ABS(39), buf
[4] >> 4);
363 input_report_abs(dev
->input_dev
, KONTROLS4_ABS(40), buf
[4] & 0xf);
364 input_report_abs(dev
->input_dev
, KONTROLS4_ABS(41), buf
[5] >> 4);
365 input_report_abs(dev
->input_dev
, KONTROLS4_ABS(42), buf
[5] & 0xf);
366 input_report_abs(dev
->input_dev
, KONTROLS4_ABS(43), buf
[6] >> 4);
367 input_report_abs(dev
->input_dev
, KONTROLS4_ABS(44), buf
[6] & 0xf);
368 input_report_abs(dev
->input_dev
, KONTROLS4_ABS(45), buf
[7] >> 4);
369 input_report_abs(dev
->input_dev
, KONTROLS4_ABS(46), buf
[7] & 0xf);
373 /* Volume Fader Channel D */
374 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(0), buf
, 1);
375 /* Volume Fader Channel B */
376 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(1), buf
, 2);
377 /* Volume Fader Channel A */
378 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(2), buf
, 3);
379 /* Volume Fader Channel C */
380 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(3), buf
, 4);
382 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(4), buf
, 6);
384 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(7), buf
, 7);
390 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(6), buf
, 3);
392 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(5), buf
, 4);
394 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(8), buf
, 6);
396 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(9), buf
, 7);
401 /* Wheel distance sensor L */
402 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(10), buf
, 1);
403 /* Wheel distance sensor R */
404 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(11), buf
, 2);
405 /* Channel D EQ - Filter */
406 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(12), buf
, 3);
407 /* Channel D EQ - Low */
408 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(13), buf
, 4);
409 /* Channel D EQ - Mid */
410 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(14), buf
, 5);
411 /* Channel D EQ - Hi */
412 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(15), buf
, 6);
414 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(16), buf
, 7);
420 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(17), buf
, 1);
422 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(18), buf
, 2);
424 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(19), buf
, 3);
425 /* Channel B EQ - Filter */
426 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(20), buf
, 4);
427 /* Channel B EQ - Low */
428 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(21), buf
, 5);
429 /* Channel B EQ - Mid */
430 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(22), buf
, 6);
431 /* Channel B EQ - Hi */
432 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(23), buf
, 7);
437 /* Channel A EQ - Filter */
438 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(24), buf
, 1);
439 /* Channel A EQ - Low */
440 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(25), buf
, 2);
441 /* Channel A EQ - Mid */
442 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(26), buf
, 3);
443 /* Channel A EQ - Hi */
444 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(27), buf
, 4);
445 /* Channel C EQ - Filter */
446 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(28), buf
, 5);
447 /* Channel C EQ - Low */
448 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(29), buf
, 6);
449 /* Channel C EQ - Mid */
450 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(30), buf
, 7);
455 /* Channel C EQ - Hi */
456 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(31), buf
, 1);
458 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(32), buf
, 2);
460 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(33), buf
, 3);
462 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(34), buf
, 4);
464 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(35), buf
, 5);
469 debug("%s(): bogus block (id %d)\n",
474 len
-= TKS4_MSGBLOCK_SIZE
;
475 buf
+= TKS4_MSGBLOCK_SIZE
;
478 input_sync(dev
->input_dev
);
481 #define MASCHINE_MSGBLOCK_SIZE 2
483 static void snd_usb_caiaq_maschine_dispatch(struct snd_usb_caiaqdev
*dev
,
484 const unsigned char *buf
,
487 unsigned int i
, pad_id
;
490 for (i
= 0; i
< MASCHINE_PADS
; i
++) {
491 pressure
= be16_to_cpu(buf
[i
* 2] << 8 | buf
[(i
* 2) + 1]);
492 pad_id
= pressure
>> 12;
494 input_report_abs(dev
->input_dev
, MASCHINE_PAD(pad_id
), pressure
& 0xfff);
497 input_sync(dev
->input_dev
);
500 static void snd_usb_caiaq_ep4_reply_dispatch(struct urb
*urb
)
502 struct snd_usb_caiaqdev
*dev
= urb
->context
;
503 unsigned char *buf
= urb
->transfer_buffer
;
506 if (urb
->status
|| !dev
|| urb
!= dev
->ep4_in_urb
)
509 switch (dev
->chip
.usb_id
) {
510 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_TRAKTORKONTROLX1
):
511 if (urb
->actual_length
< 24)
515 snd_caiaq_input_read_io(dev
, buf
+ 1, 7);
518 snd_caiaq_input_read_analog(dev
, buf
+ 8, 16);
522 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_TRAKTORKONTROLS4
):
523 snd_usb_caiaq_tks4_dispatch(dev
, buf
, urb
->actual_length
);
526 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_MASCHINECONTROLLER
):
527 if (urb
->actual_length
< (MASCHINE_PADS
* MASCHINE_MSGBLOCK_SIZE
))
530 snd_usb_caiaq_maschine_dispatch(dev
, buf
, urb
->actual_length
);
535 dev
->ep4_in_urb
->actual_length
= 0;
536 ret
= usb_submit_urb(dev
->ep4_in_urb
, GFP_ATOMIC
);
538 log("unable to submit urb. OOM!?\n");
541 static int snd_usb_caiaq_input_open(struct input_dev
*idev
)
543 struct snd_usb_caiaqdev
*dev
= input_get_drvdata(idev
);
548 switch (dev
->chip
.usb_id
) {
549 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_TRAKTORKONTROLX1
):
550 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_TRAKTORKONTROLS4
):
551 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_MASCHINECONTROLLER
):
552 if (usb_submit_urb(dev
->ep4_in_urb
, GFP_KERNEL
) != 0)
560 static void snd_usb_caiaq_input_close(struct input_dev
*idev
)
562 struct snd_usb_caiaqdev
*dev
= input_get_drvdata(idev
);
567 switch (dev
->chip
.usb_id
) {
568 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_TRAKTORKONTROLX1
):
569 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_TRAKTORKONTROLS4
):
570 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_MASCHINECONTROLLER
):
571 usb_kill_urb(dev
->ep4_in_urb
);
576 void snd_usb_caiaq_input_dispatch(struct snd_usb_caiaqdev
*dev
,
580 if (!dev
->input_dev
|| len
< 1)
584 case EP1_CMD_READ_ANALOG
:
585 snd_caiaq_input_read_analog(dev
, buf
+ 1, len
- 1);
587 case EP1_CMD_READ_ERP
:
588 snd_caiaq_input_read_erp(dev
, buf
+ 1, len
- 1);
590 case EP1_CMD_READ_IO
:
591 snd_caiaq_input_read_io(dev
, buf
+ 1, len
- 1);
596 int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev
*dev
)
598 struct usb_device
*usb_dev
= dev
->chip
.dev
;
599 struct input_dev
*input
;
602 input
= input_allocate_device();
606 usb_make_path(usb_dev
, dev
->phys
, sizeof(dev
->phys
));
607 strlcat(dev
->phys
, "/input0", sizeof(dev
->phys
));
609 input
->name
= dev
->product_name
;
610 input
->phys
= dev
->phys
;
611 usb_to_input_id(usb_dev
, &input
->id
);
612 input
->dev
.parent
= &usb_dev
->dev
;
614 input_set_drvdata(input
, dev
);
616 switch (dev
->chip
.usb_id
) {
617 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_RIGKONTROL2
):
618 input
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_ABS
);
619 input
->absbit
[0] = BIT_MASK(ABS_X
) | BIT_MASK(ABS_Y
) |
621 BUILD_BUG_ON(sizeof(dev
->keycode
) < sizeof(keycode_rk2
));
622 memcpy(dev
->keycode
, keycode_rk2
, sizeof(keycode_rk2
));
623 input
->keycodemax
= ARRAY_SIZE(keycode_rk2
);
624 input_set_abs_params(input
, ABS_X
, 0, 4096, 0, 10);
625 input_set_abs_params(input
, ABS_Y
, 0, 4096, 0, 10);
626 input_set_abs_params(input
, ABS_Z
, 0, 4096, 0, 10);
627 snd_usb_caiaq_set_auto_msg(dev
, 1, 10, 0);
629 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_RIGKONTROL3
):
630 input
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_ABS
);
631 input
->absbit
[0] = BIT_MASK(ABS_X
) | BIT_MASK(ABS_Y
) |
633 BUILD_BUG_ON(sizeof(dev
->keycode
) < sizeof(keycode_rk3
));
634 memcpy(dev
->keycode
, keycode_rk3
, sizeof(keycode_rk3
));
635 input
->keycodemax
= ARRAY_SIZE(keycode_rk3
);
636 input_set_abs_params(input
, ABS_X
, 0, 1024, 0, 10);
637 input_set_abs_params(input
, ABS_Y
, 0, 1024, 0, 10);
638 input_set_abs_params(input
, ABS_Z
, 0, 1024, 0, 10);
639 snd_usb_caiaq_set_auto_msg(dev
, 1, 10, 0);
641 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_AK1
):
642 input
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_ABS
);
643 input
->absbit
[0] = BIT_MASK(ABS_X
);
644 BUILD_BUG_ON(sizeof(dev
->keycode
) < sizeof(keycode_ak1
));
645 memcpy(dev
->keycode
, keycode_ak1
, sizeof(keycode_ak1
));
646 input
->keycodemax
= ARRAY_SIZE(keycode_ak1
);
647 input_set_abs_params(input
, ABS_X
, 0, 999, 0, 10);
648 snd_usb_caiaq_set_auto_msg(dev
, 1, 0, 5);
650 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_KORECONTROLLER
):
651 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_KORECONTROLLER2
):
652 input
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_ABS
);
653 input
->absbit
[0] = BIT_MASK(ABS_HAT0X
) | BIT_MASK(ABS_HAT0Y
) |
654 BIT_MASK(ABS_HAT1X
) | BIT_MASK(ABS_HAT1Y
) |
655 BIT_MASK(ABS_HAT2X
) | BIT_MASK(ABS_HAT2Y
) |
656 BIT_MASK(ABS_HAT3X
) | BIT_MASK(ABS_HAT3Y
) |
657 BIT_MASK(ABS_X
) | BIT_MASK(ABS_Y
) |
659 input
->absbit
[BIT_WORD(ABS_MISC
)] |= BIT_MASK(ABS_MISC
);
660 BUILD_BUG_ON(sizeof(dev
->keycode
) < sizeof(keycode_kore
));
661 memcpy(dev
->keycode
, keycode_kore
, sizeof(keycode_kore
));
662 input
->keycodemax
= ARRAY_SIZE(keycode_kore
);
663 input_set_abs_params(input
, ABS_HAT0X
, 0, 999, 0, 10);
664 input_set_abs_params(input
, ABS_HAT0Y
, 0, 999, 0, 10);
665 input_set_abs_params(input
, ABS_HAT1X
, 0, 999, 0, 10);
666 input_set_abs_params(input
, ABS_HAT1Y
, 0, 999, 0, 10);
667 input_set_abs_params(input
, ABS_HAT2X
, 0, 999, 0, 10);
668 input_set_abs_params(input
, ABS_HAT2Y
, 0, 999, 0, 10);
669 input_set_abs_params(input
, ABS_HAT3X
, 0, 999, 0, 10);
670 input_set_abs_params(input
, ABS_HAT3Y
, 0, 999, 0, 10);
671 input_set_abs_params(input
, ABS_X
, 0, 4096, 0, 10);
672 input_set_abs_params(input
, ABS_Y
, 0, 4096, 0, 10);
673 input_set_abs_params(input
, ABS_Z
, 0, 4096, 0, 10);
674 input_set_abs_params(input
, ABS_MISC
, 0, 255, 0, 1);
675 snd_usb_caiaq_set_auto_msg(dev
, 1, 10, 5);
677 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_TRAKTORKONTROLX1
):
678 input
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_ABS
);
679 input
->absbit
[0] = BIT_MASK(ABS_HAT0X
) | BIT_MASK(ABS_HAT0Y
) |
680 BIT_MASK(ABS_HAT1X
) | BIT_MASK(ABS_HAT1Y
) |
681 BIT_MASK(ABS_HAT2X
) | BIT_MASK(ABS_HAT2Y
) |
682 BIT_MASK(ABS_HAT3X
) | BIT_MASK(ABS_HAT3Y
) |
683 BIT_MASK(ABS_X
) | BIT_MASK(ABS_Y
) |
685 input
->absbit
[BIT_WORD(ABS_MISC
)] |= BIT_MASK(ABS_MISC
);
686 BUILD_BUG_ON(sizeof(dev
->keycode
) < KONTROLX1_INPUTS
);
687 for (i
= 0; i
< KONTROLX1_INPUTS
; i
++)
688 dev
->keycode
[i
] = BTN_MISC
+ i
;
689 input
->keycodemax
= KONTROLX1_INPUTS
;
691 /* analog potentiometers */
692 input_set_abs_params(input
, ABS_HAT0X
, 0, 4096, 0, 10);
693 input_set_abs_params(input
, ABS_HAT0Y
, 0, 4096, 0, 10);
694 input_set_abs_params(input
, ABS_HAT1X
, 0, 4096, 0, 10);
695 input_set_abs_params(input
, ABS_HAT1Y
, 0, 4096, 0, 10);
696 input_set_abs_params(input
, ABS_HAT2X
, 0, 4096, 0, 10);
697 input_set_abs_params(input
, ABS_HAT2Y
, 0, 4096, 0, 10);
698 input_set_abs_params(input
, ABS_HAT3X
, 0, 4096, 0, 10);
699 input_set_abs_params(input
, ABS_HAT3Y
, 0, 4096, 0, 10);
701 /* rotary encoders */
702 input_set_abs_params(input
, ABS_X
, 0, 0xf, 0, 1);
703 input_set_abs_params(input
, ABS_Y
, 0, 0xf, 0, 1);
704 input_set_abs_params(input
, ABS_Z
, 0, 0xf, 0, 1);
705 input_set_abs_params(input
, ABS_MISC
, 0, 0xf, 0, 1);
707 dev
->ep4_in_urb
= usb_alloc_urb(0, GFP_KERNEL
);
708 if (!dev
->ep4_in_urb
) {
713 usb_fill_bulk_urb(dev
->ep4_in_urb
, usb_dev
,
714 usb_rcvbulkpipe(usb_dev
, 0x4),
715 dev
->ep4_in_buf
, EP4_BUFSIZE
,
716 snd_usb_caiaq_ep4_reply_dispatch
, dev
);
718 snd_usb_caiaq_set_auto_msg(dev
, 1, 10, 5);
722 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_TRAKTORKONTROLS4
):
723 input
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_ABS
);
724 BUILD_BUG_ON(sizeof(dev
->keycode
) < KONTROLS4_BUTTONS
);
725 for (i
= 0; i
< KONTROLS4_BUTTONS
; i
++)
726 dev
->keycode
[i
] = KONTROLS4_BUTTON(i
);
727 input
->keycodemax
= KONTROLS4_BUTTONS
;
729 for (i
= 0; i
< KONTROLS4_AXIS
; i
++) {
730 int axis
= KONTROLS4_ABS(i
);
731 input
->absbit
[BIT_WORD(axis
)] |= BIT_MASK(axis
);
734 /* 36 analog potentiometers and faders */
735 for (i
= 0; i
< 36; i
++)
736 input_set_abs_params(input
, KONTROLS4_ABS(i
), 0, 0xfff, 0, 10);
738 /* 2 encoder wheels */
739 input_set_abs_params(input
, KONTROLS4_ABS(36), 0, 0x3ff, 0, 1);
740 input_set_abs_params(input
, KONTROLS4_ABS(37), 0, 0x3ff, 0, 1);
742 /* 9 rotary encoders */
743 for (i
= 0; i
< 9; i
++)
744 input_set_abs_params(input
, KONTROLS4_ABS(38+i
), 0, 0xf, 0, 1);
746 dev
->ep4_in_urb
= usb_alloc_urb(0, GFP_KERNEL
);
747 if (!dev
->ep4_in_urb
) {
752 usb_fill_bulk_urb(dev
->ep4_in_urb
, usb_dev
,
753 usb_rcvbulkpipe(usb_dev
, 0x4),
754 dev
->ep4_in_buf
, EP4_BUFSIZE
,
755 snd_usb_caiaq_ep4_reply_dispatch
, dev
);
757 snd_usb_caiaq_set_auto_msg(dev
, 1, 10, 5);
761 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_MASCHINECONTROLLER
):
762 input
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_ABS
);
763 input
->absbit
[0] = BIT_MASK(ABS_HAT0X
) | BIT_MASK(ABS_HAT0Y
) |
764 BIT_MASK(ABS_HAT1X
) | BIT_MASK(ABS_HAT1Y
) |
765 BIT_MASK(ABS_HAT2X
) | BIT_MASK(ABS_HAT2Y
) |
766 BIT_MASK(ABS_HAT3X
) | BIT_MASK(ABS_HAT3Y
) |
767 BIT_MASK(ABS_RX
) | BIT_MASK(ABS_RY
) |
770 BUILD_BUG_ON(sizeof(dev
->keycode
) < sizeof(keycode_maschine
));
771 memcpy(dev
->keycode
, keycode_maschine
, sizeof(keycode_maschine
));
772 input
->keycodemax
= ARRAY_SIZE(keycode_maschine
);
774 for (i
= 0; i
< MASCHINE_PADS
; i
++) {
775 input
->absbit
[0] |= MASCHINE_PAD(i
);
776 input_set_abs_params(input
, MASCHINE_PAD(i
), 0, 0xfff, 5, 10);
779 input_set_abs_params(input
, ABS_HAT0X
, 0, 999, 0, 10);
780 input_set_abs_params(input
, ABS_HAT0Y
, 0, 999, 0, 10);
781 input_set_abs_params(input
, ABS_HAT1X
, 0, 999, 0, 10);
782 input_set_abs_params(input
, ABS_HAT1Y
, 0, 999, 0, 10);
783 input_set_abs_params(input
, ABS_HAT2X
, 0, 999, 0, 10);
784 input_set_abs_params(input
, ABS_HAT2Y
, 0, 999, 0, 10);
785 input_set_abs_params(input
, ABS_HAT3X
, 0, 999, 0, 10);
786 input_set_abs_params(input
, ABS_HAT3Y
, 0, 999, 0, 10);
787 input_set_abs_params(input
, ABS_RX
, 0, 999, 0, 10);
788 input_set_abs_params(input
, ABS_RY
, 0, 999, 0, 10);
789 input_set_abs_params(input
, ABS_RZ
, 0, 999, 0, 10);
791 dev
->ep4_in_urb
= usb_alloc_urb(0, GFP_KERNEL
);
792 if (!dev
->ep4_in_urb
) {
797 usb_fill_bulk_urb(dev
->ep4_in_urb
, usb_dev
,
798 usb_rcvbulkpipe(usb_dev
, 0x4),
799 dev
->ep4_in_buf
, EP4_BUFSIZE
,
800 snd_usb_caiaq_ep4_reply_dispatch
, dev
);
802 snd_usb_caiaq_set_auto_msg(dev
, 1, 10, 5);
806 /* no input methods supported on this device */
810 input
->open
= snd_usb_caiaq_input_open
;
811 input
->close
= snd_usb_caiaq_input_close
;
812 input
->keycode
= dev
->keycode
;
813 input
->keycodesize
= sizeof(unsigned short);
814 for (i
= 0; i
< input
->keycodemax
; i
++)
815 __set_bit(dev
->keycode
[i
], input
->keybit
);
817 dev
->input_dev
= input
;
819 ret
= input_register_device(input
);
826 input_free_device(input
);
827 dev
->input_dev
= NULL
;
831 void snd_usb_caiaq_input_free(struct snd_usb_caiaqdev
*dev
)
833 if (!dev
|| !dev
->input_dev
)
836 usb_kill_urb(dev
->ep4_in_urb
);
837 usb_free_urb(dev
->ep4_in_urb
);
838 dev
->ep4_in_urb
= NULL
;
840 input_unregister_device(dev
->input_dev
);
841 dev
->input_dev
= NULL
;