blob: 26a121b42c3c15ef93dd38ead31ad4c79d325737 [file] [log] [blame]
Daniel Mack523f1dc2007-03-26 19:11:24 +02001/*
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
Tejun Heo7b7b9042010-03-30 02:52:29 +090019#include <linux/gfp.h>
Daniel Mack523f1dc2007-03-26 19:11:24 +020020#include <linux/init.h>
Daniel Mack523f1dc2007-03-26 19:11:24 +020021#include <linux/usb.h>
Dmitry Torokhovb18b4932007-11-21 16:45:23 +010022#include <linux/usb/input.h>
Daniel Mack6da7a2a2010-03-22 13:13:37 +010023#include <sound/core.h>
Daniel Mack523f1dc2007-03-26 19:11:24 +020024#include <sound/pcm.h>
Daniel Mack936e7d02009-04-01 19:05:39 +020025
26#include "device.h"
27#include "input.h"
Daniel Mack523f1dc2007-03-26 19:11:24 +020028
Dmitry Torokhovb18b4932007-11-21 16:45:23 +010029static unsigned short keycode_ak1[] = { KEY_C, KEY_B, KEY_A };
30static unsigned short keycode_rk2[] = { KEY_1, KEY_2, KEY_3, KEY_4,
31 KEY_5, KEY_6, KEY_7 };
32static unsigned short keycode_rk3[] = { KEY_1, KEY_2, KEY_3, KEY_4,
Daniel Mackf4389482011-08-06 09:13:08 +020033 KEY_5, KEY_6, KEY_7, KEY_8, KEY_9 };
Daniel Mack523f1dc2007-03-26 19:11:24 +020034
Daniel Mack8e3cd082007-11-22 11:40:04 +010035static 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. */
44 KEY_RIGHT,
45 KEY_DOWN,
46 KEY_UP,
47 KEY_LEFT,
48 KEY_SOUND, /* "listen" */
49 KEY_RECORD,
50 KEY_PLAYPAUSE,
51 KEY_STOP,
52 BTN_4, /* 8 softkeys */
53 BTN_3,
54 BTN_2,
55 BTN_1,
56 BTN_8,
57 BTN_7,
58 BTN_6,
59 BTN_5,
60 KEY_BRL_DOT4, /* touch sensitive knobs */
61 KEY_BRL_DOT3,
62 KEY_BRL_DOT2,
63 KEY_BRL_DOT1,
64 KEY_BRL_DOT8,
65 KEY_BRL_DOT7,
66 KEY_BRL_DOT6,
67 KEY_BRL_DOT5
68};
69
William Lighte6535102011-10-10 15:54:23 +000070#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)
74
75static 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 */
85
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 */
93
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 */
102
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 */
111
112 MASCHINE_BUTTON(15), /* 8 softkeys */
113 MASCHINE_BUTTON(14),
114 MASCHINE_BUTTON(13),
115 MASCHINE_BUTTON(12),
116 MASCHINE_BUTTON(11),
117 MASCHINE_BUTTON(10),
118 MASCHINE_BUTTON(9),
119 MASCHINE_BUTTON(8),
120
121 MASCHINE_BUTTON(16), /* note repeat */
122 MASCHINE_BUTTON(29) /* play */
123};
124
Daniel Mack15c5ab62010-09-10 17:04:57 +0800125#define KONTROLX1_INPUTS (40)
126#define KONTROLS4_BUTTONS (12 * 8)
127#define KONTROLS4_AXIS (46)
128
129#define KONTROLS4_BUTTON(X) ((X) + BTN_MISC)
130#define KONTROLS4_ABS(X) ((X) + ABS_HAT0X)
Daniel Mack6da7a2a2010-03-22 13:13:37 +0100131
Dmitry Torokhovb18b4932007-11-21 16:45:23 +0100132#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)
Daniel Mack523f1dc2007-03-26 19:11:24 +0200138
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
142 * from 0 to 999 */
143static unsigned int decode_erp(unsigned char a, unsigned char b)
144{
145 int weight_a, weight_b;
146 int pos_a, pos_b;
147 int ret;
148 int range = HIGH_PEAK - LOW_PEAK;
149 int mid_value = (HIGH_PEAK + LOW_PEAK) / 2;
150
Dmitry Torokhovb18b4932007-11-21 16:45:23 +0100151 weight_b = abs(mid_value - a) - (range / 2 - 100) / 2;
152
Daniel Mack523f1dc2007-03-26 19:11:24 +0200153 if (weight_b < 0)
154 weight_b = 0;
155
156 if (weight_b > 100)
157 weight_b = 100;
158
159 weight_a = 100 - weight_b;
160
161 if (a < mid_value) {
162 /* 0..90 and 270..360 degrees */
163 pos_b = b - LOW_PEAK + DEG270;
164 if (pos_b >= DEG360)
165 pos_b -= DEG360;
166 } else
167 /* 90..270 degrees */
168 pos_b = HIGH_PEAK - b + DEG90;
169
170
171 if (b > mid_value)
172 /* 0..180 degrees */
173 pos_a = a - LOW_PEAK;
174 else
175 /* 180..360 degrees */
176 pos_a = HIGH_PEAK - a + DEG180;
177
178 /* interpolate both slider values, depending on weight factors */
179 /* 0..99 x DEG360 */
180 ret = pos_a * weight_a + pos_b * weight_b;
181
182 /* normalize to 0..999 */
183 ret *= 10;
184 ret /= DEG360;
185
186 if (ret < 0)
187 ret += 1000;
Dmitry Torokhovb18b4932007-11-21 16:45:23 +0100188
Daniel Mack523f1dc2007-03-26 19:11:24 +0200189 if (ret >= 1000)
190 ret -= 1000;
191
192 return ret;
193}
194
195#undef DEG90
196#undef DEG180
197#undef DEG270
198#undef DEG360
199#undef HIGH_PEAK
200#undef LOW_PEAK
201
Daniel Mack15c5ab62010-09-10 17:04:57 +0800202static inline void snd_caiaq_input_report_abs(struct snd_usb_caiaqdev *dev,
203 int axis, const unsigned char *buf,
204 int offset)
205{
206 input_report_abs(dev->input_dev, axis,
207 (buf[offset * 2] << 8) | buf[offset * 2 + 1]);
208}
Daniel Mack523f1dc2007-03-26 19:11:24 +0200209
Dmitry Torokhovb18b4932007-11-21 16:45:23 +0100210static void snd_caiaq_input_read_analog(struct snd_usb_caiaqdev *dev,
Daniel Mackad1e34b2007-09-17 14:45:14 +0200211 const unsigned char *buf,
212 unsigned int len)
Daniel Mack523f1dc2007-03-26 19:11:24 +0200213{
Dmitry Torokhovb18b4932007-11-21 16:45:23 +0100214 struct input_dev *input_dev = dev->input_dev;
215
Daniel Mack8e3cd082007-11-22 11:40:04 +0100216 switch (dev->chip.usb_id) {
217 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL2):
Daniel Mack15c5ab62010-09-10 17:04:57 +0800218 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);
Daniel Mack523f1dc2007-03-26 19:11:24 +0200221 break;
Daniel Mack8e3cd082007-11-22 11:40:04 +0100222 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL3):
Daniel Mack8e3cd082007-11-22 11:40:04 +0100223 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER):
Daniel Mack7829d0e2007-11-26 09:00:56 +0100224 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER2):
Daniel Mack15c5ab62010-09-10 17:04:57 +0800225 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);
Daniel Mackad1e34b2007-09-17 14:45:14 +0200228 break;
Daniel Mack6da7a2a2010-03-22 13:13:37 +0100229 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
Daniel Mack15c5ab62010-09-10 17:04:57 +0800230 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);
Daniel Mack6da7a2a2010-03-22 13:13:37 +0100238 break;
Daniel Mack523f1dc2007-03-26 19:11:24 +0200239 }
Daniel Mack15c5ab62010-09-10 17:04:57 +0800240
241 input_sync(input_dev);
Daniel Mack523f1dc2007-03-26 19:11:24 +0200242}
243
Dmitry Torokhovb18b4932007-11-21 16:45:23 +0100244static void snd_caiaq_input_read_erp(struct snd_usb_caiaqdev *dev,
Daniel Mack523f1dc2007-03-26 19:11:24 +0200245 const char *buf, unsigned int len)
246{
Dmitry Torokhovb18b4932007-11-21 16:45:23 +0100247 struct input_dev *input_dev = dev->input_dev;
Daniel Mack523f1dc2007-03-26 19:11:24 +0200248 int i;
249
Daniel Mack8e3cd082007-11-22 11:40:04 +0100250 switch (dev->chip.usb_id) {
251 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AK1):
Daniel Mack523f1dc2007-03-26 19:11:24 +0200252 i = decode_erp(buf[0], buf[1]);
Dmitry Torokhovb18b4932007-11-21 16:45:23 +0100253 input_report_abs(input_dev, ABS_X, i);
254 input_sync(input_dev);
Daniel Mack523f1dc2007-03-26 19:11:24 +0200255 break;
Daniel Mack8e3cd082007-11-22 11:40:04 +0100256 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER):
Daniel Mack7829d0e2007-11-26 09:00:56 +0100257 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER2):
Daniel Mack8e3cd082007-11-22 11:40:04 +0100258 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);
275 break;
William Lighte6535102011-10-10 15:54:23 +0000276
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]));
283
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]));
289
290 /* volume */
291 input_report_abs(input_dev, ABS_RX, decode_erp(buf[17], buf[16]));
292 /* tempo */
293 input_report_abs(input_dev, ABS_RY, decode_erp(buf[11], buf[10]));
294 /* swing */
295 input_report_abs(input_dev, ABS_RZ, decode_erp(buf[5], buf[4]));
296
297 input_sync(input_dev);
298 break;
Daniel Mack523f1dc2007-03-26 19:11:24 +0200299 }
300}
301
Dmitry Torokhovb18b4932007-11-21 16:45:23 +0100302static void snd_caiaq_input_read_io(struct snd_usb_caiaqdev *dev,
Daniel Mack6da7a2a2010-03-22 13:13:37 +0100303 unsigned char *buf, unsigned int len)
Daniel Mack523f1dc2007-03-26 19:11:24 +0200304{
Dmitry Torokhovb18b4932007-11-21 16:45:23 +0100305 struct input_dev *input_dev = dev->input_dev;
306 unsigned short *keycode = input_dev->keycode;
Daniel Mack523f1dc2007-03-26 19:11:24 +0200307 int i;
Daniel Mack523f1dc2007-03-26 19:11:24 +0200308
309 if (!keycode)
310 return;
311
Dmitry Torokhovb18b4932007-11-21 16:45:23 +0100312 if (input_dev->id.product == USB_PID_RIGKONTROL2)
313 for (i = 0; i < len; i++)
Daniel Mack523f1dc2007-03-26 19:11:24 +0200314 buf[i] = ~buf[i];
315
Daniel Mack8e3cd082007-11-22 11:40:04 +0100316 for (i = 0; i < input_dev->keycodemax && i < len * 8; i++)
Dmitry Torokhovb18b4932007-11-21 16:45:23 +0100317 input_report_key(input_dev, keycode[i],
318 buf[i / 8] & (1 << (i % 8)));
Daniel Mack523f1dc2007-03-26 19:11:24 +0200319
Daniel Mack6da7a2a2010-03-22 13:13:37 +0100320 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):
Daniel Mack8e3cd082007-11-22 11:40:04 +0100323 input_report_abs(dev->input_dev, ABS_MISC, 255 - buf[4]);
Daniel Mack6da7a2a2010-03-22 13:13:37 +0100324 break;
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);
331 break;
332 }
Daniel Mack8e3cd082007-11-22 11:40:04 +0100333
Dmitry Torokhovb18b4932007-11-21 16:45:23 +0100334 input_sync(input_dev);
Daniel Mack523f1dc2007-03-26 19:11:24 +0200335}
336
Daniel Mack15c5ab62010-09-10 17:04:57 +0800337#define TKS4_MSGBLOCK_SIZE 16
338
339static void snd_usb_caiaq_tks4_dispatch(struct snd_usb_caiaqdev *dev,
340 const unsigned char *buf,
341 unsigned int len)
342{
343 while (len) {
344 unsigned int i, block_id = (buf[0] << 8) | buf[1];
345
346 switch (block_id) {
347 case 0:
348 /* buttons */
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);
352 break;
353
354 case 1:
355 /* left wheel */
356 input_report_abs(dev->input_dev, KONTROLS4_ABS(36), buf[9] | ((buf[8] & 0x3) << 8));
357 /* right wheel */
358 input_report_abs(dev->input_dev, KONTROLS4_ABS(37), buf[13] | ((buf[12] & 0x3) << 8));
359
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);
370
371 break;
372 case 2:
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);
381 /* Loop Volume */
382 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(4), buf, 6);
383 /* Crossfader */
384 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(7), buf, 7);
385
386 break;
387
388 case 3:
389 /* Tempo Fader R */
390 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(6), buf, 3);
391 /* Tempo Fader L */
392 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(5), buf, 4);
393 /* Mic Volume */
394 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(8), buf, 6);
395 /* Cue Mix */
396 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(9), buf, 7);
397
398 break;
399
400 case 4:
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);
413 /* FX2 - dry/wet */
414 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(16), buf, 7);
415
416 break;
417
418 case 5:
419 /* FX2 - 1 */
420 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(17), buf, 1);
421 /* FX2 - 2 */
422 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(18), buf, 2);
423 /* FX2 - 3 */
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);
433
434 break;
435
436 case 6:
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);
451
452 break;
453
454 case 7:
455 /* Channel C EQ - Hi */
456 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(31), buf, 1);
457 /* FX1 - wet/dry */
458 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(32), buf, 2);
459 /* FX1 - 1 */
460 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(33), buf, 3);
461 /* FX1 - 2 */
462 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(34), buf, 4);
463 /* FX1 - 3 */
464 snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(35), buf, 5);
465
466 break;
467
468 default:
469 debug("%s(): bogus block (id %d)\n",
470 __func__, block_id);
471 return;
472 }
473
474 len -= TKS4_MSGBLOCK_SIZE;
475 buf += TKS4_MSGBLOCK_SIZE;
476 }
477
478 input_sync(dev->input_dev);
479}
480
William Lighte6535102011-10-10 15:54:23 +0000481#define MASCHINE_MSGBLOCK_SIZE 2
482
483static void snd_usb_caiaq_maschine_dispatch(struct snd_usb_caiaqdev *dev,
484 const unsigned char *buf,
485 unsigned int len)
486{
487 unsigned int i, pad_id;
488 uint16_t pressure;
489
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;
493
494 input_report_abs(dev->input_dev, MASCHINE_PAD(pad_id), pressure & 0xfff);
495 }
496
497 input_sync(dev->input_dev);
498}
499
Daniel Mack6da7a2a2010-03-22 13:13:37 +0100500static void snd_usb_caiaq_ep4_reply_dispatch(struct urb *urb)
501{
502 struct snd_usb_caiaqdev *dev = urb->context;
503 unsigned char *buf = urb->transfer_buffer;
504 int ret;
505
506 if (urb->status || !dev || urb != dev->ep4_in_urb)
507 return;
508
Daniel Mack6da7a2a2010-03-22 13:13:37 +0100509 switch (dev->chip.usb_id) {
510 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
Daniel Mack15c5ab62010-09-10 17:04:57 +0800511 if (urb->actual_length < 24)
512 goto requeue;
513
Daniel Mack6da7a2a2010-03-22 13:13:37 +0100514 if (buf[0] & 0x3)
515 snd_caiaq_input_read_io(dev, buf + 1, 7);
516
517 if (buf[0] & 0x4)
518 snd_caiaq_input_read_analog(dev, buf + 8, 16);
519
520 break;
Daniel Mack15c5ab62010-09-10 17:04:57 +0800521
522 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4):
523 snd_usb_caiaq_tks4_dispatch(dev, buf, urb->actual_length);
524 break;
William Lighte6535102011-10-10 15:54:23 +0000525
526 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_MASCHINECONTROLLER):
527 if (urb->actual_length < (MASCHINE_PADS * MASCHINE_MSGBLOCK_SIZE))
528 goto requeue;
529
530 snd_usb_caiaq_maschine_dispatch(dev, buf, urb->actual_length);
531 break;
Daniel Mack6da7a2a2010-03-22 13:13:37 +0100532 }
533
534requeue:
535 dev->ep4_in_urb->actual_length = 0;
536 ret = usb_submit_urb(dev->ep4_in_urb, GFP_ATOMIC);
537 if (ret < 0)
538 log("unable to submit urb. OOM!?\n");
539}
540
541static int snd_usb_caiaq_input_open(struct input_dev *idev)
542{
543 struct snd_usb_caiaqdev *dev = input_get_drvdata(idev);
544
545 if (!dev)
546 return -EINVAL;
547
548 switch (dev->chip.usb_id) {
549 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
Daniel Mack15c5ab62010-09-10 17:04:57 +0800550 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4):
William Lighte6535102011-10-10 15:54:23 +0000551 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_MASCHINECONTROLLER):
Daniel Mack6da7a2a2010-03-22 13:13:37 +0100552 if (usb_submit_urb(dev->ep4_in_urb, GFP_KERNEL) != 0)
553 return -EIO;
554 break;
555 }
556
557 return 0;
558}
559
560static void snd_usb_caiaq_input_close(struct input_dev *idev)
561{
562 struct snd_usb_caiaqdev *dev = input_get_drvdata(idev);
563
564 if (!dev)
565 return;
566
567 switch (dev->chip.usb_id) {
568 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
Daniel Mack15c5ab62010-09-10 17:04:57 +0800569 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4):
William Lighte6535102011-10-10 15:54:23 +0000570 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_MASCHINECONTROLLER):
Daniel Mack6da7a2a2010-03-22 13:13:37 +0100571 usb_kill_urb(dev->ep4_in_urb);
572 break;
573 }
574}
575
Dmitry Torokhovb18b4932007-11-21 16:45:23 +0100576void snd_usb_caiaq_input_dispatch(struct snd_usb_caiaqdev *dev,
577 char *buf,
Daniel Mack523f1dc2007-03-26 19:11:24 +0200578 unsigned int len)
579{
Dmitry Torokhovb18b4932007-11-21 16:45:23 +0100580 if (!dev->input_dev || len < 1)
Daniel Mack523f1dc2007-03-26 19:11:24 +0200581 return;
582
583 switch (buf[0]) {
584 case EP1_CMD_READ_ANALOG:
Dmitry Torokhovb18b4932007-11-21 16:45:23 +0100585 snd_caiaq_input_read_analog(dev, buf + 1, len - 1);
Daniel Mack523f1dc2007-03-26 19:11:24 +0200586 break;
587 case EP1_CMD_READ_ERP:
Dmitry Torokhovb18b4932007-11-21 16:45:23 +0100588 snd_caiaq_input_read_erp(dev, buf + 1, len - 1);
Daniel Mack523f1dc2007-03-26 19:11:24 +0200589 break;
590 case EP1_CMD_READ_IO:
Dmitry Torokhovb18b4932007-11-21 16:45:23 +0100591 snd_caiaq_input_read_io(dev, buf + 1, len - 1);
Daniel Mack523f1dc2007-03-26 19:11:24 +0200592 break;
593 }
594}
595
596int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev *dev)
597{
598 struct usb_device *usb_dev = dev->chip.dev;
599 struct input_dev *input;
Daniel Mack6da7a2a2010-03-22 13:13:37 +0100600 int i, ret = 0;
Daniel Mack523f1dc2007-03-26 19:11:24 +0200601
602 input = input_allocate_device();
603 if (!input)
604 return -ENOMEM;
605
Dmitry Torokhovb18b4932007-11-21 16:45:23 +0100606 usb_make_path(usb_dev, dev->phys, sizeof(dev->phys));
607 strlcat(dev->phys, "/input0", sizeof(dev->phys));
608
Daniel Mack523f1dc2007-03-26 19:11:24 +0200609 input->name = dev->product_name;
Dmitry Torokhovb18b4932007-11-21 16:45:23 +0100610 input->phys = dev->phys;
611 usb_to_input_id(usb_dev, &input->id);
612 input->dev.parent = &usb_dev->dev;
Daniel Mack523f1dc2007-03-26 19:11:24 +0200613
Daniel Mack6da7a2a2010-03-22 13:13:37 +0100614 input_set_drvdata(input, dev);
615
616 switch (dev->chip.usb_id) {
Daniel Mack523f1dc2007-03-26 19:11:24 +0200617 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL2):
Jiri Slaby7b19ada2007-10-18 23:40:32 -0700618 input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
619 input->absbit[0] = BIT_MASK(ABS_X) | BIT_MASK(ABS_Y) |
620 BIT_MASK(ABS_Z);
Dmitry Torokhovb18b4932007-11-21 16:45:23 +0100621 BUILD_BUG_ON(sizeof(dev->keycode) < sizeof(keycode_rk2));
622 memcpy(dev->keycode, keycode_rk2, sizeof(keycode_rk2));
Daniel Mack523f1dc2007-03-26 19:11:24 +0200623 input->keycodemax = ARRAY_SIZE(keycode_rk2);
Daniel Mack523f1dc2007-03-26 19:11:24 +0200624 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);
628 break;
Daniel Mackad1e34b2007-09-17 14:45:14 +0200629 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL3):
Daniel Mack8e3cd082007-11-22 11:40:04 +0100630 input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
631 input->absbit[0] = BIT_MASK(ABS_X) | BIT_MASK(ABS_Y) |
632 BIT_MASK(ABS_Z);
Dmitry Torokhovb18b4932007-11-21 16:45:23 +0100633 BUILD_BUG_ON(sizeof(dev->keycode) < sizeof(keycode_rk3));
634 memcpy(dev->keycode, keycode_rk3, sizeof(keycode_rk3));
Daniel Mackad1e34b2007-09-17 14:45:14 +0200635 input->keycodemax = ARRAY_SIZE(keycode_rk3);
Daniel Mackad1e34b2007-09-17 14:45:14 +0200636 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);
640 break;
Daniel Mack523f1dc2007-03-26 19:11:24 +0200641 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AK1):
Jiri Slaby7b19ada2007-10-18 23:40:32 -0700642 input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
643 input->absbit[0] = BIT_MASK(ABS_X);
Dmitry Torokhovb18b4932007-11-21 16:45:23 +0100644 BUILD_BUG_ON(sizeof(dev->keycode) < sizeof(keycode_ak1));
645 memcpy(dev->keycode, keycode_ak1, sizeof(keycode_ak1));
Daniel Mack523f1dc2007-03-26 19:11:24 +0200646 input->keycodemax = ARRAY_SIZE(keycode_ak1);
Daniel Mack523f1dc2007-03-26 19:11:24 +0200647 input_set_abs_params(input, ABS_X, 0, 999, 0, 10);
648 snd_usb_caiaq_set_auto_msg(dev, 1, 0, 5);
649 break;
Daniel Mack8e3cd082007-11-22 11:40:04 +0100650 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER):
Daniel Mack7829d0e2007-11-26 09:00:56 +0100651 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER2):
Daniel Mack8e3cd082007-11-22 11:40:04 +0100652 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) |
658 BIT_MASK(ABS_Z);
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);
676 break;
Daniel Mack6da7a2a2010-03-22 13:13:37 +0100677 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) |
684 BIT_MASK(ABS_Z);
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;
690
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);
700
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);
706
707 dev->ep4_in_urb = usb_alloc_urb(0, GFP_KERNEL);
708 if (!dev->ep4_in_urb) {
709 ret = -ENOMEM;
710 goto exit_free_idev;
711 }
712
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);
717
718 snd_usb_caiaq_set_auto_msg(dev, 1, 10, 5);
719
720 break;
Daniel Mack15c5ab62010-09-10 17:04:57 +0800721
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;
728
729 for (i = 0; i < KONTROLS4_AXIS; i++) {
730 int axis = KONTROLS4_ABS(i);
731 input->absbit[BIT_WORD(axis)] |= BIT_MASK(axis);
732 }
733
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);
737
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);
741
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);
745
746 dev->ep4_in_urb = usb_alloc_urb(0, GFP_KERNEL);
747 if (!dev->ep4_in_urb) {
748 ret = -ENOMEM;
749 goto exit_free_idev;
750 }
751
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);
756
757 snd_usb_caiaq_set_auto_msg(dev, 1, 10, 5);
758
759 break;
760
William Lighte6535102011-10-10 15:54:23 +0000761 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) |
768 BIT_MASK(ABS_RZ);
769
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);
773
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);
777 }
778
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);
790
791 dev->ep4_in_urb = usb_alloc_urb(0, GFP_KERNEL);
792 if (!dev->ep4_in_urb) {
793 ret = -ENOMEM;
794 goto exit_free_idev;
795 }
796
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);
801
802 snd_usb_caiaq_set_auto_msg(dev, 1, 10, 5);
803 break;
804
Daniel Mack523f1dc2007-03-26 19:11:24 +0200805 default:
806 /* no input methods supported on this device */
Daniel Mack6da7a2a2010-03-22 13:13:37 +0100807 goto exit_free_idev;
Daniel Mack523f1dc2007-03-26 19:11:24 +0200808 }
809
Daniel Mack6da7a2a2010-03-22 13:13:37 +0100810 input->open = snd_usb_caiaq_input_open;
811 input->close = snd_usb_caiaq_input_close;
Dmitry Torokhovb18b4932007-11-21 16:45:23 +0100812 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);
816
William Light3d37fbe2011-10-10 15:54:22 +0000817 dev->input_dev = input;
818
Daniel Mack523f1dc2007-03-26 19:11:24 +0200819 ret = input_register_device(input);
Daniel Mack6da7a2a2010-03-22 13:13:37 +0100820 if (ret < 0)
821 goto exit_free_idev;
Daniel Mack523f1dc2007-03-26 19:11:24 +0200822
Daniel Mack523f1dc2007-03-26 19:11:24 +0200823 return 0;
Daniel Mack6da7a2a2010-03-22 13:13:37 +0100824
825exit_free_idev:
826 input_free_device(input);
William Light3d37fbe2011-10-10 15:54:22 +0000827 dev->input_dev = NULL;
Daniel Mack6da7a2a2010-03-22 13:13:37 +0100828 return ret;
Daniel Mack523f1dc2007-03-26 19:11:24 +0200829}
830
831void snd_usb_caiaq_input_free(struct snd_usb_caiaqdev *dev)
832{
833 if (!dev || !dev->input_dev)
834 return;
835
Daniel Mack6da7a2a2010-03-22 13:13:37 +0100836 usb_kill_urb(dev->ep4_in_urb);
837 usb_free_urb(dev->ep4_in_urb);
838 dev->ep4_in_urb = NULL;
839
Daniel Mack523f1dc2007-03-26 19:11:24 +0200840 input_unregister_device(dev->input_dev);
Daniel Mack523f1dc2007-03-26 19:11:24 +0200841 dev->input_dev = NULL;
842}