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_5
, KEY_6
};
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 KONTROLX1_INPUTS (40)
71 #define KONTROLS4_BUTTONS (12 * 8)
72 #define KONTROLS4_AXIS (46)
74 #define KONTROLS4_BUTTON(X) ((X) + BTN_MISC)
75 #define KONTROLS4_ABS(X) ((X) + ABS_HAT0X)
77 #define DEG90 (range / 2)
78 #define DEG180 (range)
79 #define DEG270 (DEG90 + DEG180)
80 #define DEG360 (DEG180 * 2)
81 #define HIGH_PEAK (268)
84 /* some of these devices have endless rotation potentiometers
85 * built in which use two tapers, 90 degrees phase shifted.
86 * this algorithm decodes them to one single value, ranging
88 static unsigned int decode_erp(unsigned char a
, unsigned char b
)
90 int weight_a
, weight_b
;
93 int range
= HIGH_PEAK
- LOW_PEAK
;
94 int mid_value
= (HIGH_PEAK
+ LOW_PEAK
) / 2;
96 weight_b
= abs(mid_value
- a
) - (range
/ 2 - 100) / 2;
104 weight_a
= 100 - weight_b
;
107 /* 0..90 and 270..360 degrees */
108 pos_b
= b
- LOW_PEAK
+ DEG270
;
112 /* 90..270 degrees */
113 pos_b
= HIGH_PEAK
- b
+ DEG90
;
118 pos_a
= a
- LOW_PEAK
;
120 /* 180..360 degrees */
121 pos_a
= HIGH_PEAK
- a
+ DEG180
;
123 /* interpolate both slider values, depending on weight factors */
125 ret
= pos_a
* weight_a
+ pos_b
* weight_b
;
127 /* normalize to 0..999 */
147 static inline void snd_caiaq_input_report_abs(struct snd_usb_caiaqdev
*dev
,
148 int axis
, const unsigned char *buf
,
151 input_report_abs(dev
->input_dev
, axis
,
152 (buf
[offset
* 2] << 8) | buf
[offset
* 2 + 1]);
155 static void snd_caiaq_input_read_analog(struct snd_usb_caiaqdev
*dev
,
156 const unsigned char *buf
,
159 struct input_dev
*input_dev
= dev
->input_dev
;
161 switch (dev
->chip
.usb_id
) {
162 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_RIGKONTROL2
):
163 snd_caiaq_input_report_abs(dev
, ABS_X
, buf
, 2);
164 snd_caiaq_input_report_abs(dev
, ABS_Y
, buf
, 0);
165 snd_caiaq_input_report_abs(dev
, ABS_Z
, buf
, 1);
167 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_RIGKONTROL3
):
168 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_KORECONTROLLER
):
169 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_KORECONTROLLER2
):
170 snd_caiaq_input_report_abs(dev
, ABS_X
, buf
, 0);
171 snd_caiaq_input_report_abs(dev
, ABS_Y
, buf
, 1);
172 snd_caiaq_input_report_abs(dev
, ABS_Z
, buf
, 2);
174 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_TRAKTORKONTROLX1
):
175 snd_caiaq_input_report_abs(dev
, ABS_HAT0X
, buf
, 4);
176 snd_caiaq_input_report_abs(dev
, ABS_HAT0Y
, buf
, 2);
177 snd_caiaq_input_report_abs(dev
, ABS_HAT1X
, buf
, 6);
178 snd_caiaq_input_report_abs(dev
, ABS_HAT1Y
, buf
, 1);
179 snd_caiaq_input_report_abs(dev
, ABS_HAT2X
, buf
, 7);
180 snd_caiaq_input_report_abs(dev
, ABS_HAT2Y
, buf
, 0);
181 snd_caiaq_input_report_abs(dev
, ABS_HAT3X
, buf
, 5);
182 snd_caiaq_input_report_abs(dev
, ABS_HAT3Y
, buf
, 3);
186 input_sync(input_dev
);
189 static void snd_caiaq_input_read_erp(struct snd_usb_caiaqdev
*dev
,
190 const char *buf
, unsigned int len
)
192 struct input_dev
*input_dev
= dev
->input_dev
;
195 switch (dev
->chip
.usb_id
) {
196 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_AK1
):
197 i
= decode_erp(buf
[0], buf
[1]);
198 input_report_abs(input_dev
, ABS_X
, i
);
199 input_sync(input_dev
);
201 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_KORECONTROLLER
):
202 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_KORECONTROLLER2
):
203 i
= decode_erp(buf
[7], buf
[5]);
204 input_report_abs(input_dev
, ABS_HAT0X
, i
);
205 i
= decode_erp(buf
[12], buf
[14]);
206 input_report_abs(input_dev
, ABS_HAT0Y
, i
);
207 i
= decode_erp(buf
[15], buf
[13]);
208 input_report_abs(input_dev
, ABS_HAT1X
, i
);
209 i
= decode_erp(buf
[0], buf
[2]);
210 input_report_abs(input_dev
, ABS_HAT1Y
, i
);
211 i
= decode_erp(buf
[3], buf
[1]);
212 input_report_abs(input_dev
, ABS_HAT2X
, i
);
213 i
= decode_erp(buf
[8], buf
[10]);
214 input_report_abs(input_dev
, ABS_HAT2Y
, i
);
215 i
= decode_erp(buf
[11], buf
[9]);
216 input_report_abs(input_dev
, ABS_HAT3X
, i
);
217 i
= decode_erp(buf
[4], buf
[6]);
218 input_report_abs(input_dev
, ABS_HAT3Y
, i
);
219 input_sync(input_dev
);
224 static void snd_caiaq_input_read_io(struct snd_usb_caiaqdev
*dev
,
225 unsigned char *buf
, unsigned int len
)
227 struct input_dev
*input_dev
= dev
->input_dev
;
228 unsigned short *keycode
= input_dev
->keycode
;
234 if (input_dev
->id
.product
== USB_PID_RIGKONTROL2
)
235 for (i
= 0; i
< len
; i
++)
238 for (i
= 0; i
< input_dev
->keycodemax
&& i
< len
* 8; i
++)
239 input_report_key(input_dev
, keycode
[i
],
240 buf
[i
/ 8] & (1 << (i
% 8)));
242 switch (dev
->chip
.usb_id
) {
243 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_KORECONTROLLER
):
244 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_KORECONTROLLER2
):
245 input_report_abs(dev
->input_dev
, ABS_MISC
, 255 - buf
[4]);
247 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_TRAKTORKONTROLX1
):
248 /* rotary encoders */
249 input_report_abs(dev
->input_dev
, ABS_X
, buf
[5] & 0xf);
250 input_report_abs(dev
->input_dev
, ABS_Y
, buf
[5] >> 4);
251 input_report_abs(dev
->input_dev
, ABS_Z
, buf
[6] & 0xf);
252 input_report_abs(dev
->input_dev
, ABS_MISC
, buf
[6] >> 4);
256 input_sync(input_dev
);
259 #define TKS4_MSGBLOCK_SIZE 16
261 static void snd_usb_caiaq_tks4_dispatch(struct snd_usb_caiaqdev
*dev
,
262 const unsigned char *buf
,
266 unsigned int i
, block_id
= (buf
[0] << 8) | buf
[1];
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);
278 input_report_abs(dev
->input_dev
, KONTROLS4_ABS(36), buf
[9] | ((buf
[8] & 0x3) << 8));
280 input_report_abs(dev
->input_dev
, KONTROLS4_ABS(37), buf
[13] | ((buf
[12] & 0x3) << 8));
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);
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);
304 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(4), buf
, 6);
306 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(7), buf
, 7);
312 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(6), buf
, 3);
314 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(5), buf
, 4);
316 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(8), buf
, 6);
318 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(9), buf
, 7);
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);
336 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(16), buf
, 7);
342 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(17), buf
, 1);
344 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(18), buf
, 2);
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);
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);
377 /* Channel C EQ - Hi */
378 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(31), buf
, 1);
380 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(32), buf
, 2);
382 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(33), buf
, 3);
384 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(34), buf
, 4);
386 snd_caiaq_input_report_abs(dev
, KONTROLS4_ABS(35), buf
, 5);
391 debug("%s(): bogus block (id %d)\n",
396 len
-= TKS4_MSGBLOCK_SIZE
;
397 buf
+= TKS4_MSGBLOCK_SIZE
;
400 input_sync(dev
->input_dev
);
403 static void snd_usb_caiaq_ep4_reply_dispatch(struct urb
*urb
)
405 struct snd_usb_caiaqdev
*dev
= urb
->context
;
406 unsigned char *buf
= urb
->transfer_buffer
;
409 if (urb
->status
|| !dev
|| urb
!= dev
->ep4_in_urb
)
412 switch (dev
->chip
.usb_id
) {
413 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_TRAKTORKONTROLX1
):
414 if (urb
->actual_length
< 24)
418 snd_caiaq_input_read_io(dev
, buf
+ 1, 7);
421 snd_caiaq_input_read_analog(dev
, buf
+ 8, 16);
425 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_TRAKTORKONTROLS4
):
426 snd_usb_caiaq_tks4_dispatch(dev
, buf
, urb
->actual_length
);
431 dev
->ep4_in_urb
->actual_length
= 0;
432 ret
= usb_submit_urb(dev
->ep4_in_urb
, GFP_ATOMIC
);
434 log("unable to submit urb. OOM!?\n");
437 static int snd_usb_caiaq_input_open(struct input_dev
*idev
)
439 struct snd_usb_caiaqdev
*dev
= input_get_drvdata(idev
);
444 switch (dev
->chip
.usb_id
) {
445 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_TRAKTORKONTROLX1
):
446 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_TRAKTORKONTROLS4
):
447 if (usb_submit_urb(dev
->ep4_in_urb
, GFP_KERNEL
) != 0)
455 static void snd_usb_caiaq_input_close(struct input_dev
*idev
)
457 struct snd_usb_caiaqdev
*dev
= input_get_drvdata(idev
);
462 switch (dev
->chip
.usb_id
) {
463 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_TRAKTORKONTROLX1
):
464 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_TRAKTORKONTROLS4
):
465 usb_kill_urb(dev
->ep4_in_urb
);
470 void snd_usb_caiaq_input_dispatch(struct snd_usb_caiaqdev
*dev
,
474 if (!dev
->input_dev
|| len
< 1)
478 case EP1_CMD_READ_ANALOG
:
479 snd_caiaq_input_read_analog(dev
, buf
+ 1, len
- 1);
481 case EP1_CMD_READ_ERP
:
482 snd_caiaq_input_read_erp(dev
, buf
+ 1, len
- 1);
484 case EP1_CMD_READ_IO
:
485 snd_caiaq_input_read_io(dev
, buf
+ 1, len
- 1);
490 int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev
*dev
)
492 struct usb_device
*usb_dev
= dev
->chip
.dev
;
493 struct input_dev
*input
;
496 input
= input_allocate_device();
500 usb_make_path(usb_dev
, dev
->phys
, sizeof(dev
->phys
));
501 strlcat(dev
->phys
, "/input0", sizeof(dev
->phys
));
503 input
->name
= dev
->product_name
;
504 input
->phys
= dev
->phys
;
505 usb_to_input_id(usb_dev
, &input
->id
);
506 input
->dev
.parent
= &usb_dev
->dev
;
508 input_set_drvdata(input
, dev
);
510 switch (dev
->chip
.usb_id
) {
511 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_RIGKONTROL2
):
512 input
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_ABS
);
513 input
->absbit
[0] = BIT_MASK(ABS_X
) | BIT_MASK(ABS_Y
) |
515 BUILD_BUG_ON(sizeof(dev
->keycode
) < sizeof(keycode_rk2
));
516 memcpy(dev
->keycode
, keycode_rk2
, sizeof(keycode_rk2
));
517 input
->keycodemax
= ARRAY_SIZE(keycode_rk2
);
518 input_set_abs_params(input
, ABS_X
, 0, 4096, 0, 10);
519 input_set_abs_params(input
, ABS_Y
, 0, 4096, 0, 10);
520 input_set_abs_params(input
, ABS_Z
, 0, 4096, 0, 10);
521 snd_usb_caiaq_set_auto_msg(dev
, 1, 10, 0);
523 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_RIGKONTROL3
):
524 input
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_ABS
);
525 input
->absbit
[0] = BIT_MASK(ABS_X
) | BIT_MASK(ABS_Y
) |
527 BUILD_BUG_ON(sizeof(dev
->keycode
) < sizeof(keycode_rk3
));
528 memcpy(dev
->keycode
, keycode_rk3
, sizeof(keycode_rk3
));
529 input
->keycodemax
= ARRAY_SIZE(keycode_rk3
);
530 input_set_abs_params(input
, ABS_X
, 0, 1024, 0, 10);
531 input_set_abs_params(input
, ABS_Y
, 0, 1024, 0, 10);
532 input_set_abs_params(input
, ABS_Z
, 0, 1024, 0, 10);
533 snd_usb_caiaq_set_auto_msg(dev
, 1, 10, 0);
535 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_AK1
):
536 input
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_ABS
);
537 input
->absbit
[0] = BIT_MASK(ABS_X
);
538 BUILD_BUG_ON(sizeof(dev
->keycode
) < sizeof(keycode_ak1
));
539 memcpy(dev
->keycode
, keycode_ak1
, sizeof(keycode_ak1
));
540 input
->keycodemax
= ARRAY_SIZE(keycode_ak1
);
541 input_set_abs_params(input
, ABS_X
, 0, 999, 0, 10);
542 snd_usb_caiaq_set_auto_msg(dev
, 1, 0, 5);
544 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_KORECONTROLLER
):
545 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_KORECONTROLLER2
):
546 input
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_ABS
);
547 input
->absbit
[0] = BIT_MASK(ABS_HAT0X
) | BIT_MASK(ABS_HAT0Y
) |
548 BIT_MASK(ABS_HAT1X
) | BIT_MASK(ABS_HAT1Y
) |
549 BIT_MASK(ABS_HAT2X
) | BIT_MASK(ABS_HAT2Y
) |
550 BIT_MASK(ABS_HAT3X
) | BIT_MASK(ABS_HAT3Y
) |
551 BIT_MASK(ABS_X
) | BIT_MASK(ABS_Y
) |
553 input
->absbit
[BIT_WORD(ABS_MISC
)] |= BIT_MASK(ABS_MISC
);
554 BUILD_BUG_ON(sizeof(dev
->keycode
) < sizeof(keycode_kore
));
555 memcpy(dev
->keycode
, keycode_kore
, sizeof(keycode_kore
));
556 input
->keycodemax
= ARRAY_SIZE(keycode_kore
);
557 input_set_abs_params(input
, ABS_HAT0X
, 0, 999, 0, 10);
558 input_set_abs_params(input
, ABS_HAT0Y
, 0, 999, 0, 10);
559 input_set_abs_params(input
, ABS_HAT1X
, 0, 999, 0, 10);
560 input_set_abs_params(input
, ABS_HAT1Y
, 0, 999, 0, 10);
561 input_set_abs_params(input
, ABS_HAT2X
, 0, 999, 0, 10);
562 input_set_abs_params(input
, ABS_HAT2Y
, 0, 999, 0, 10);
563 input_set_abs_params(input
, ABS_HAT3X
, 0, 999, 0, 10);
564 input_set_abs_params(input
, ABS_HAT3Y
, 0, 999, 0, 10);
565 input_set_abs_params(input
, ABS_X
, 0, 4096, 0, 10);
566 input_set_abs_params(input
, ABS_Y
, 0, 4096, 0, 10);
567 input_set_abs_params(input
, ABS_Z
, 0, 4096, 0, 10);
568 input_set_abs_params(input
, ABS_MISC
, 0, 255, 0, 1);
569 snd_usb_caiaq_set_auto_msg(dev
, 1, 10, 5);
571 case USB_ID(USB_VID_NATIVEINSTRUMENTS
, USB_PID_TRAKTORKONTROLX1
):
572 input
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_ABS
);
573 input
->absbit
[0] = BIT_MASK(ABS_HAT0X
) | BIT_MASK(ABS_HAT0Y
) |
574 BIT_MASK(ABS_HAT1X
) | BIT_MASK(ABS_HAT1Y
) |
575 BIT_MASK(ABS_HAT2X
) | BIT_MASK(ABS_HAT2Y
) |
576 BIT_MASK(ABS_HAT3X
) | BIT_MASK(ABS_HAT3Y
) |
577 BIT_MASK(ABS_X
) | BIT_MASK(ABS_Y
) |
579 input
->absbit
[BIT_WORD(ABS_MISC
)] |= BIT_MASK(ABS_MISC
);
580 BUILD_BUG_ON(sizeof(dev
->keycode
) < KONTROLX1_INPUTS
);
581 for (i
= 0; i
< KONTROLX1_INPUTS
; i
++)
582 dev
->keycode
[i
] = BTN_MISC
+ i
;
583 input
->keycodemax
= KONTROLX1_INPUTS
;
585 /* analog potentiometers */
586 input_set_abs_params(input
, ABS_HAT0X
, 0, 4096, 0, 10);
587 input_set_abs_params(input
, ABS_HAT0Y
, 0, 4096, 0, 10);
588 input_set_abs_params(input
, ABS_HAT1X
, 0, 4096, 0, 10);
589 input_set_abs_params(input
, ABS_HAT1Y
, 0, 4096, 0, 10);
590 input_set_abs_params(input
, ABS_HAT2X
, 0, 4096, 0, 10);
591 input_set_abs_params(input
, ABS_HAT2Y
, 0, 4096, 0, 10);
592 input_set_abs_params(input
, ABS_HAT3X
, 0, 4096, 0, 10);
593 input_set_abs_params(input
, ABS_HAT3Y
, 0, 4096, 0, 10);
595 /* rotary encoders */
596 input_set_abs_params(input
, ABS_X
, 0, 0xf, 0, 1);
597 input_set_abs_params(input
, ABS_Y
, 0, 0xf, 0, 1);
598 input_set_abs_params(input
, ABS_Z
, 0, 0xf, 0, 1);
599 input_set_abs_params(input
, ABS_MISC
, 0, 0xf, 0, 1);
601 dev
->ep4_in_urb
= usb_alloc_urb(0, GFP_KERNEL
);
602 if (!dev
->ep4_in_urb
) {
607 usb_fill_bulk_urb(dev
->ep4_in_urb
, usb_dev
,
608 usb_rcvbulkpipe(usb_dev
, 0x4),
609 dev
->ep4_in_buf
, EP4_BUFSIZE
,
610 snd_usb_caiaq_ep4_reply_dispatch
, dev
);
612 snd_usb_caiaq_set_auto_msg(dev
, 1, 10, 5);
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
;
623 for (i
= 0; i
< KONTROLS4_AXIS
; i
++) {
624 int axis
= KONTROLS4_ABS(i
);
625 input
->absbit
[BIT_WORD(axis
)] |= BIT_MASK(axis
);
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);
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);
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);
640 dev
->ep4_in_urb
= usb_alloc_urb(0, GFP_KERNEL
);
641 if (!dev
->ep4_in_urb
) {
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
);
651 snd_usb_caiaq_set_auto_msg(dev
, 1, 10, 5);
656 /* no input methods supported on this device */
660 input
->open
= snd_usb_caiaq_input_open
;
661 input
->close
= snd_usb_caiaq_input_close
;
662 input
->keycode
= dev
->keycode
;
663 input
->keycodesize
= sizeof(unsigned short);
664 for (i
= 0; i
< input
->keycodemax
; i
++)
665 __set_bit(dev
->keycode
[i
], input
->keybit
);
667 ret
= input_register_device(input
);
671 dev
->input_dev
= input
;
675 input_free_device(input
);
679 void snd_usb_caiaq_input_free(struct snd_usb_caiaqdev
*dev
)
681 if (!dev
|| !dev
->input_dev
)
684 usb_kill_urb(dev
->ep4_in_urb
);
685 usb_free_urb(dev
->ep4_in_urb
);
686 dev
->ep4_in_urb
= NULL
;
688 input_unregister_device(dev
->input_dev
);
689 dev
->input_dev
= NULL
;