input.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. /*
  2. * Copyright (c) 2006,2007 Daniel Mack, Tim Ruetz
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. #include <linux/gfp.h>
  19. #include <linux/init.h>
  20. #include <linux/usb.h>
  21. #include <linux/usb/input.h>
  22. #include <sound/core.h>
  23. #include <sound/pcm.h>
  24. #include "device.h"
  25. #include "input.h"
  26. static unsigned short keycode_ak1[] = { KEY_C, KEY_B, KEY_A };
  27. static unsigned short keycode_rk2[] = { KEY_1, KEY_2, KEY_3, KEY_4,
  28. KEY_5, KEY_6, KEY_7 };
  29. static unsigned short keycode_rk3[] = { KEY_1, KEY_2, KEY_3, KEY_4,
  30. KEY_5, KEY_6, KEY_7, KEY_8, KEY_9 };
  31. static unsigned short keycode_kore[] = {
  32. KEY_FN_F1, /* "menu" */
  33. KEY_FN_F7, /* "lcd backlight */
  34. KEY_FN_F2, /* "control" */
  35. KEY_FN_F3, /* "enter" */
  36. KEY_FN_F4, /* "view" */
  37. KEY_FN_F5, /* "esc" */
  38. KEY_FN_F6, /* "sound" */
  39. KEY_FN_F8, /* array spacer, never triggered. */
  40. KEY_RIGHT,
  41. KEY_DOWN,
  42. KEY_UP,
  43. KEY_LEFT,
  44. KEY_SOUND, /* "listen" */
  45. KEY_RECORD,
  46. KEY_PLAYPAUSE,
  47. KEY_STOP,
  48. BTN_4, /* 8 softkeys */
  49. BTN_3,
  50. BTN_2,
  51. BTN_1,
  52. BTN_8,
  53. BTN_7,
  54. BTN_6,
  55. BTN_5,
  56. KEY_BRL_DOT4, /* touch sensitive knobs */
  57. KEY_BRL_DOT3,
  58. KEY_BRL_DOT2,
  59. KEY_BRL_DOT1,
  60. KEY_BRL_DOT8,
  61. KEY_BRL_DOT7,
  62. KEY_BRL_DOT6,
  63. KEY_BRL_DOT5
  64. };
  65. #define KONTROLX1_INPUTS (40)
  66. #define KONTROLS4_BUTTONS (12 * 8)
  67. #define KONTROLS4_AXIS (46)
  68. #define KONTROLS4_BUTTON(X) ((X) + BTN_MISC)
  69. #define KONTROLS4_ABS(X) ((X) + ABS_HAT0X)
  70. #define DEG90 (range / 2)
  71. #define DEG180 (range)
  72. #define DEG270 (DEG90 + DEG180)
  73. #define DEG360 (DEG180 * 2)
  74. #define HIGH_PEAK (268)
  75. #define LOW_PEAK (-7)
  76. /* some of these devices have endless rotation potentiometers
  77. * built in which use two tapers, 90 degrees phase shifted.
  78. * this algorithm decodes them to one single value, ranging
  79. * from 0 to 999 */
  80. static unsigned int decode_erp(unsigned char a, unsigned char b)
  81. {
  82. int weight_a, weight_b;
  83. int pos_a, pos_b;
  84. int ret;
  85. int range = HIGH_PEAK - LOW_PEAK;
  86. int mid_value = (HIGH_PEAK + LOW_PEAK) / 2;
  87. weight_b = abs(mid_value - a) - (range / 2 - 100) / 2;
  88. if (weight_b < 0)
  89. weight_b = 0;
  90. if (weight_b > 100)
  91. weight_b = 100;
  92. weight_a = 100 - weight_b;
  93. if (a < mid_value) {
  94. /* 0..90 and 270..360 degrees */
  95. pos_b = b - LOW_PEAK + DEG270;
  96. if (pos_b >= DEG360)
  97. pos_b -= DEG360;
  98. } else
  99. /* 90..270 degrees */
  100. pos_b = HIGH_PEAK - b + DEG90;
  101. if (b > mid_value)
  102. /* 0..180 degrees */
  103. pos_a = a - LOW_PEAK;
  104. else
  105. /* 180..360 degrees */
  106. pos_a = HIGH_PEAK - a + DEG180;
  107. /* interpolate both slider values, depending on weight factors */
  108. /* 0..99 x DEG360 */
  109. ret = pos_a * weight_a + pos_b * weight_b;
  110. /* normalize to 0..999 */
  111. ret *= 10;
  112. ret /= DEG360;
  113. if (ret < 0)
  114. ret += 1000;
  115. if (ret >= 1000)
  116. ret -= 1000;
  117. return ret;
  118. }
  119. #undef DEG90
  120. #undef DEG180
  121. #undef DEG270
  122. #undef DEG360
  123. #undef HIGH_PEAK
  124. #undef LOW_PEAK
  125. static inline void snd_caiaq_input_report_abs(struct snd_usb_caiaqdev *dev,
  126. int axis, const unsigned char *buf,
  127. int offset)
  128. {
  129. input_report_abs(dev->input_dev, axis,
  130. (buf[offset * 2] << 8) | buf[offset * 2 + 1]);
  131. }
  132. static void snd_caiaq_input_read_analog(struct snd_usb_caiaqdev *dev,
  133. const unsigned char *buf,
  134. unsigned int len)
  135. {
  136. struct input_dev *input_dev = dev->input_dev;
  137. switch (dev->chip.usb_id) {
  138. case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL2):
  139. snd_caiaq_input_report_abs(dev, ABS_X, buf, 2);
  140. snd_caiaq_input_report_abs(dev, ABS_Y, buf, 0);
  141. snd_caiaq_input_report_abs(dev, ABS_Z, buf, 1);
  142. break;
  143. case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL3):
  144. case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER):
  145. case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER2):
  146. snd_caiaq_input_report_abs(dev, ABS_X, buf, 0);
  147. snd_caiaq_input_report_abs(dev, ABS_Y, buf, 1);
  148. snd_caiaq_input_report_abs(dev, ABS_Z, buf, 2);
  149. break;
  150. case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
  151. snd_caiaq_input_report_abs(dev, ABS_HAT0X, buf, 4);
  152. snd_caiaq_input_report_abs(dev, ABS_HAT0Y, buf, 2);
  153. snd_caiaq_input_report_abs(dev, ABS_HAT1X, buf, 6);
  154. snd_caiaq_input_report_abs(dev, ABS_HAT1Y, buf, 1);
  155. snd_caiaq_input_report_abs(dev, ABS_HAT2X, buf, 7);
  156. snd_caiaq_input_report_abs(dev, ABS_HAT2Y, buf, 0);
  157. snd_caiaq_input_report_abs(dev, ABS_HAT3X, buf, 5);
  158. snd_caiaq_input_report_abs(dev, ABS_HAT3Y, buf, 3);
  159. break;
  160. }
  161. input_sync(input_dev);
  162. }
  163. static void snd_caiaq_input_read_erp(struct snd_usb_caiaqdev *dev,
  164. const char *buf, unsigned int len)
  165. {
  166. struct input_dev *input_dev = dev->input_dev;
  167. int i;
  168. switch (dev->chip.usb_id) {
  169. case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AK1):
  170. i = decode_erp(buf[0], buf[1]);
  171. input_report_abs(input_dev, ABS_X, i);
  172. input_sync(input_dev);
  173. break;
  174. case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER):
  175. case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER2):
  176. i = decode_erp(buf[7], buf[5]);
  177. input_report_abs(input_dev, ABS_HAT0X, i);
  178. i = decode_erp(buf[12], buf[14]);
  179. input_report_abs(input_dev, ABS_HAT0Y, i);
  180. i = decode_erp(buf[15], buf[13]);
  181. input_report_abs(input_dev, ABS_HAT1X, i);
  182. i = decode_erp(buf[0], buf[2]);
  183. input_report_abs(input_dev, ABS_HAT1Y, i);
  184. i = decode_erp(buf[3], buf[1]);
  185. input_report_abs(input_dev, ABS_HAT2X, i);
  186. i = decode_erp(buf[8], buf[10]);
  187. input_report_abs(input_dev, ABS_HAT2Y, i);
  188. i = decode_erp(buf[11], buf[9]);
  189. input_report_abs(input_dev, ABS_HAT3X, i);
  190. i = decode_erp(buf[4], buf[6]);
  191. input_report_abs(input_dev, ABS_HAT3Y, i);
  192. input_sync(input_dev);
  193. break;
  194. }
  195. }
  196. static void snd_caiaq_input_read_io(struct snd_usb_caiaqdev *dev,
  197. unsigned char *buf, unsigned int len)
  198. {
  199. struct input_dev *input_dev = dev->input_dev;
  200. unsigned short *keycode = input_dev->keycode;
  201. int i;
  202. if (!keycode)
  203. return;
  204. if (input_dev->id.product == USB_PID_RIGKONTROL2)
  205. for (i = 0; i < len; i++)
  206. buf[i] = ~buf[i];
  207. for (i = 0; i < input_dev->keycodemax && i < len * 8; i++)
  208. input_report_key(input_dev, keycode[i],
  209. buf[i / 8] & (1 << (i % 8)));
  210. switch (dev->chip.usb_id) {
  211. case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER):
  212. case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER2):
  213. input_report_abs(dev->input_dev, ABS_MISC, 255 - buf[4]);
  214. break;
  215. case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
  216. /* rotary encoders */
  217. input_report_abs(dev->input_dev, ABS_X, buf[5] & 0xf);
  218. input_report_abs(dev->input_dev, ABS_Y, buf[5] >> 4);
  219. input_report_abs(dev->input_dev, ABS_Z, buf[6] & 0xf);
  220. input_report_abs(dev->input_dev, ABS_MISC, buf[6] >> 4);
  221. break;
  222. }
  223. input_sync(input_dev);
  224. }
  225. #define TKS4_MSGBLOCK_SIZE 16
  226. static void snd_usb_caiaq_tks4_dispatch(struct snd_usb_caiaqdev *dev,
  227. const unsigned char *buf,
  228. unsigned int len)
  229. {
  230. while (len) {
  231. unsigned int i, block_id = (buf[0] << 8) | buf[1];
  232. switch (block_id) {
  233. case 0:
  234. /* buttons */
  235. for (i = 0; i < KONTROLS4_BUTTONS; i++)
  236. input_report_key(dev->input_dev, KONTROLS4_BUTTON(i),
  237. (buf[4 + (i / 8)] >> (i % 8)) & 1);
  238. break;
  239. case 1:
  240. /* left wheel */
  241. input_report_abs(dev->input_dev, KONTROLS4_ABS(36), buf[9] | ((buf[8] & 0x3) << 8));
  242. /* right wheel */
  243. input_report_abs(dev->input_dev, KONTROLS4_ABS(37), buf[13] | ((buf[12] & 0x3) << 8));
  244. /* rotary encoders */
  245. input_report_abs(dev->input_dev, KONTROLS4_ABS(38), buf[3] & 0xf);
  246. input_report_abs(dev->input_dev, KONTROLS4_ABS(39), buf[4] >> 4);
  247. input_report_abs(dev->input_dev, KONTROLS4_ABS(40), buf[4] & 0xf);
  248. input_report_abs(dev->input_dev, KONTROLS4_ABS(41), buf[5] >> 4);
  249. input_report_abs(dev->input_dev, KONTROLS4_ABS(42), buf[5] & 0xf);
  250. input_report_abs(dev->input_dev, KONTROLS4_ABS(43), buf[6] >> 4);
  251. input_report_abs(dev->input_dev, KONTROLS4_ABS(44), buf[6] & 0xf);
  252. input_report_abs(dev->input_dev, KONTROLS4_ABS(45), buf[7] >> 4);
  253. input_report_abs(dev->input_dev, KONTROLS4_ABS(46), buf[7] & 0xf);
  254. break;
  255. case 2:
  256. /* Volume Fader Channel D */
  257. snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(0), buf, 1);
  258. /* Volume Fader Channel B */
  259. snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(1), buf, 2);
  260. /* Volume Fader Channel A */
  261. snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(2), buf, 3);
  262. /* Volume Fader Channel C */
  263. snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(3), buf, 4);
  264. /* Loop Volume */
  265. snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(4), buf, 6);
  266. /* Crossfader */
  267. snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(7), buf, 7);
  268. break;
  269. case 3:
  270. /* Tempo Fader R */
  271. snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(6), buf, 3);
  272. /* Tempo Fader L */
  273. snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(5), buf, 4);
  274. /* Mic Volume */
  275. snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(8), buf, 6);
  276. /* Cue Mix */
  277. snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(9), buf, 7);
  278. break;
  279. case 4:
  280. /* Wheel distance sensor L */
  281. snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(10), buf, 1);
  282. /* Wheel distance sensor R */
  283. snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(11), buf, 2);
  284. /* Channel D EQ - Filter */
  285. snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(12), buf, 3);
  286. /* Channel D EQ - Low */
  287. snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(13), buf, 4);
  288. /* Channel D EQ - Mid */
  289. snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(14), buf, 5);
  290. /* Channel D EQ - Hi */
  291. snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(15), buf, 6);
  292. /* FX2 - dry/wet */
  293. snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(16), buf, 7);
  294. break;
  295. case 5:
  296. /* FX2 - 1 */
  297. snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(17), buf, 1);
  298. /* FX2 - 2 */
  299. snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(18), buf, 2);
  300. /* FX2 - 3 */
  301. snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(19), buf, 3);
  302. /* Channel B EQ - Filter */
  303. snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(20), buf, 4);
  304. /* Channel B EQ - Low */
  305. snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(21), buf, 5);
  306. /* Channel B EQ - Mid */
  307. snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(22), buf, 6);
  308. /* Channel B EQ - Hi */
  309. snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(23), buf, 7);
  310. break;
  311. case 6:
  312. /* Channel A EQ - Filter */
  313. snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(24), buf, 1);
  314. /* Channel A EQ - Low */
  315. snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(25), buf, 2);
  316. /* Channel A EQ - Mid */
  317. snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(26), buf, 3);
  318. /* Channel A EQ - Hi */
  319. snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(27), buf, 4);
  320. /* Channel C EQ - Filter */
  321. snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(28), buf, 5);
  322. /* Channel C EQ - Low */
  323. snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(29), buf, 6);
  324. /* Channel C EQ - Mid */
  325. snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(30), buf, 7);
  326. break;
  327. case 7:
  328. /* Channel C EQ - Hi */
  329. snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(31), buf, 1);
  330. /* FX1 - wet/dry */
  331. snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(32), buf, 2);
  332. /* FX1 - 1 */
  333. snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(33), buf, 3);
  334. /* FX1 - 2 */
  335. snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(34), buf, 4);
  336. /* FX1 - 3 */
  337. snd_caiaq_input_report_abs(dev, KONTROLS4_ABS(35), buf, 5);
  338. break;
  339. default:
  340. debug("%s(): bogus block (id %d)\n",
  341. __func__, block_id);
  342. return;
  343. }
  344. len -= TKS4_MSGBLOCK_SIZE;
  345. buf += TKS4_MSGBLOCK_SIZE;
  346. }
  347. input_sync(dev->input_dev);
  348. }
  349. static void snd_usb_caiaq_ep4_reply_dispatch(struct urb *urb)
  350. {
  351. struct snd_usb_caiaqdev *dev = urb->context;
  352. unsigned char *buf = urb->transfer_buffer;
  353. int ret;
  354. if (urb->status || !dev || urb != dev->ep4_in_urb)
  355. return;
  356. switch (dev->chip.usb_id) {
  357. case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
  358. if (urb->actual_length < 24)
  359. goto requeue;
  360. if (buf[0] & 0x3)
  361. snd_caiaq_input_read_io(dev, buf + 1, 7);
  362. if (buf[0] & 0x4)
  363. snd_caiaq_input_read_analog(dev, buf + 8, 16);
  364. break;
  365. case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4):
  366. snd_usb_caiaq_tks4_dispatch(dev, buf, urb->actual_length);
  367. break;
  368. }
  369. requeue:
  370. dev->ep4_in_urb->actual_length = 0;
  371. ret = usb_submit_urb(dev->ep4_in_urb, GFP_ATOMIC);
  372. if (ret < 0)
  373. log("unable to submit urb. OOM!?\n");
  374. }
  375. static int snd_usb_caiaq_input_open(struct input_dev *idev)
  376. {
  377. struct snd_usb_caiaqdev *dev = input_get_drvdata(idev);
  378. if (!dev)
  379. return -EINVAL;
  380. switch (dev->chip.usb_id) {
  381. case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
  382. case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4):
  383. if (usb_submit_urb(dev->ep4_in_urb, GFP_KERNEL) != 0)
  384. return -EIO;
  385. break;
  386. }
  387. return 0;
  388. }
  389. static void snd_usb_caiaq_input_close(struct input_dev *idev)
  390. {
  391. struct snd_usb_caiaqdev *dev = input_get_drvdata(idev);
  392. if (!dev)
  393. return;
  394. switch (dev->chip.usb_id) {
  395. case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
  396. case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4):
  397. usb_kill_urb(dev->ep4_in_urb);
  398. break;
  399. }
  400. }
  401. void snd_usb_caiaq_input_dispatch(struct snd_usb_caiaqdev *dev,
  402. char *buf,
  403. unsigned int len)
  404. {
  405. if (!dev->input_dev || len < 1)
  406. return;
  407. switch (buf[0]) {
  408. case EP1_CMD_READ_ANALOG:
  409. snd_caiaq_input_read_analog(dev, buf + 1, len - 1);
  410. break;
  411. case EP1_CMD_READ_ERP:
  412. snd_caiaq_input_read_erp(dev, buf + 1, len - 1);
  413. break;
  414. case EP1_CMD_READ_IO:
  415. snd_caiaq_input_read_io(dev, buf + 1, len - 1);
  416. break;
  417. }
  418. }
  419. int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev *dev)
  420. {
  421. struct usb_device *usb_dev = dev->chip.dev;
  422. struct input_dev *input;
  423. int i, ret = 0;
  424. input = input_allocate_device();
  425. if (!input)
  426. return -ENOMEM;
  427. usb_make_path(usb_dev, dev->phys, sizeof(dev->phys));
  428. strlcat(dev->phys, "/input0", sizeof(dev->phys));
  429. input->name = dev->product_name;
  430. input->phys = dev->phys;
  431. usb_to_input_id(usb_dev, &input->id);
  432. input->dev.parent = &usb_dev->dev;
  433. input_set_drvdata(input, dev);
  434. switch (dev->chip.usb_id) {
  435. case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL2):
  436. input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
  437. input->absbit[0] = BIT_MASK(ABS_X) | BIT_MASK(ABS_Y) |
  438. BIT_MASK(ABS_Z);
  439. BUILD_BUG_ON(sizeof(dev->keycode) < sizeof(keycode_rk2));
  440. memcpy(dev->keycode, keycode_rk2, sizeof(keycode_rk2));
  441. input->keycodemax = ARRAY_SIZE(keycode_rk2);
  442. input_set_abs_params(input, ABS_X, 0, 4096, 0, 10);
  443. input_set_abs_params(input, ABS_Y, 0, 4096, 0, 10);
  444. input_set_abs_params(input, ABS_Z, 0, 4096, 0, 10);
  445. snd_usb_caiaq_set_auto_msg(dev, 1, 10, 0);
  446. break;
  447. case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL3):
  448. input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
  449. input->absbit[0] = BIT_MASK(ABS_X) | BIT_MASK(ABS_Y) |
  450. BIT_MASK(ABS_Z);
  451. BUILD_BUG_ON(sizeof(dev->keycode) < sizeof(keycode_rk3));
  452. memcpy(dev->keycode, keycode_rk3, sizeof(keycode_rk3));
  453. input->keycodemax = ARRAY_SIZE(keycode_rk3);
  454. input_set_abs_params(input, ABS_X, 0, 1024, 0, 10);
  455. input_set_abs_params(input, ABS_Y, 0, 1024, 0, 10);
  456. input_set_abs_params(input, ABS_Z, 0, 1024, 0, 10);
  457. snd_usb_caiaq_set_auto_msg(dev, 1, 10, 0);
  458. break;
  459. case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AK1):
  460. input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
  461. input->absbit[0] = BIT_MASK(ABS_X);
  462. BUILD_BUG_ON(sizeof(dev->keycode) < sizeof(keycode_ak1));
  463. memcpy(dev->keycode, keycode_ak1, sizeof(keycode_ak1));
  464. input->keycodemax = ARRAY_SIZE(keycode_ak1);
  465. input_set_abs_params(input, ABS_X, 0, 999, 0, 10);
  466. snd_usb_caiaq_set_auto_msg(dev, 1, 0, 5);
  467. break;
  468. case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER):
  469. case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER2):
  470. input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
  471. input->absbit[0] = BIT_MASK(ABS_HAT0X) | BIT_MASK(ABS_HAT0Y) |
  472. BIT_MASK(ABS_HAT1X) | BIT_MASK(ABS_HAT1Y) |
  473. BIT_MASK(ABS_HAT2X) | BIT_MASK(ABS_HAT2Y) |
  474. BIT_MASK(ABS_HAT3X) | BIT_MASK(ABS_HAT3Y) |
  475. BIT_MASK(ABS_X) | BIT_MASK(ABS_Y) |
  476. BIT_MASK(ABS_Z);
  477. input->absbit[BIT_WORD(ABS_MISC)] |= BIT_MASK(ABS_MISC);
  478. BUILD_BUG_ON(sizeof(dev->keycode) < sizeof(keycode_kore));
  479. memcpy(dev->keycode, keycode_kore, sizeof(keycode_kore));
  480. input->keycodemax = ARRAY_SIZE(keycode_kore);
  481. input_set_abs_params(input, ABS_HAT0X, 0, 999, 0, 10);
  482. input_set_abs_params(input, ABS_HAT0Y, 0, 999, 0, 10);
  483. input_set_abs_params(input, ABS_HAT1X, 0, 999, 0, 10);
  484. input_set_abs_params(input, ABS_HAT1Y, 0, 999, 0, 10);
  485. input_set_abs_params(input, ABS_HAT2X, 0, 999, 0, 10);
  486. input_set_abs_params(input, ABS_HAT2Y, 0, 999, 0, 10);
  487. input_set_abs_params(input, ABS_HAT3X, 0, 999, 0, 10);
  488. input_set_abs_params(input, ABS_HAT3Y, 0, 999, 0, 10);
  489. input_set_abs_params(input, ABS_X, 0, 4096, 0, 10);
  490. input_set_abs_params(input, ABS_Y, 0, 4096, 0, 10);
  491. input_set_abs_params(input, ABS_Z, 0, 4096, 0, 10);
  492. input_set_abs_params(input, ABS_MISC, 0, 255, 0, 1);
  493. snd_usb_caiaq_set_auto_msg(dev, 1, 10, 5);
  494. break;
  495. case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
  496. input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
  497. input->absbit[0] = BIT_MASK(ABS_HAT0X) | BIT_MASK(ABS_HAT0Y) |
  498. BIT_MASK(ABS_HAT1X) | BIT_MASK(ABS_HAT1Y) |
  499. BIT_MASK(ABS_HAT2X) | BIT_MASK(ABS_HAT2Y) |
  500. BIT_MASK(ABS_HAT3X) | BIT_MASK(ABS_HAT3Y) |
  501. BIT_MASK(ABS_X) | BIT_MASK(ABS_Y) |
  502. BIT_MASK(ABS_Z);
  503. input->absbit[BIT_WORD(ABS_MISC)] |= BIT_MASK(ABS_MISC);
  504. BUILD_BUG_ON(sizeof(dev->keycode) < KONTROLX1_INPUTS);
  505. for (i = 0; i < KONTROLX1_INPUTS; i++)
  506. dev->keycode[i] = BTN_MISC + i;
  507. input->keycodemax = KONTROLX1_INPUTS;
  508. /* analog potentiometers */
  509. input_set_abs_params(input, ABS_HAT0X, 0, 4096, 0, 10);
  510. input_set_abs_params(input, ABS_HAT0Y, 0, 4096, 0, 10);
  511. input_set_abs_params(input, ABS_HAT1X, 0, 4096, 0, 10);
  512. input_set_abs_params(input, ABS_HAT1Y, 0, 4096, 0, 10);
  513. input_set_abs_params(input, ABS_HAT2X, 0, 4096, 0, 10);
  514. input_set_abs_params(input, ABS_HAT2Y, 0, 4096, 0, 10);
  515. input_set_abs_params(input, ABS_HAT3X, 0, 4096, 0, 10);
  516. input_set_abs_params(input, ABS_HAT3Y, 0, 4096, 0, 10);
  517. /* rotary encoders */
  518. input_set_abs_params(input, ABS_X, 0, 0xf, 0, 1);
  519. input_set_abs_params(input, ABS_Y, 0, 0xf, 0, 1);
  520. input_set_abs_params(input, ABS_Z, 0, 0xf, 0, 1);
  521. input_set_abs_params(input, ABS_MISC, 0, 0xf, 0, 1);
  522. dev->ep4_in_urb = usb_alloc_urb(0, GFP_KERNEL);
  523. if (!dev->ep4_in_urb) {
  524. ret = -ENOMEM;
  525. goto exit_free_idev;
  526. }
  527. usb_fill_bulk_urb(dev->ep4_in_urb, usb_dev,
  528. usb_rcvbulkpipe(usb_dev, 0x4),
  529. dev->ep4_in_buf, EP4_BUFSIZE,
  530. snd_usb_caiaq_ep4_reply_dispatch, dev);
  531. snd_usb_caiaq_set_auto_msg(dev, 1, 10, 5);
  532. break;
  533. case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4):
  534. input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
  535. BUILD_BUG_ON(sizeof(dev->keycode) < KONTROLS4_BUTTONS);
  536. for (i = 0; i < KONTROLS4_BUTTONS; i++)
  537. dev->keycode[i] = KONTROLS4_BUTTON(i);
  538. input->keycodemax = KONTROLS4_BUTTONS;
  539. for (i = 0; i < KONTROLS4_AXIS; i++) {
  540. int axis = KONTROLS4_ABS(i);
  541. input->absbit[BIT_WORD(axis)] |= BIT_MASK(axis);
  542. }
  543. /* 36 analog potentiometers and faders */
  544. for (i = 0; i < 36; i++)
  545. input_set_abs_params(input, KONTROLS4_ABS(i), 0, 0xfff, 0, 10);
  546. /* 2 encoder wheels */
  547. input_set_abs_params(input, KONTROLS4_ABS(36), 0, 0x3ff, 0, 1);
  548. input_set_abs_params(input, KONTROLS4_ABS(37), 0, 0x3ff, 0, 1);
  549. /* 9 rotary encoders */
  550. for (i = 0; i < 9; i++)
  551. input_set_abs_params(input, KONTROLS4_ABS(38+i), 0, 0xf, 0, 1);
  552. dev->ep4_in_urb = usb_alloc_urb(0, GFP_KERNEL);
  553. if (!dev->ep4_in_urb) {
  554. ret = -ENOMEM;
  555. goto exit_free_idev;
  556. }
  557. usb_fill_bulk_urb(dev->ep4_in_urb, usb_dev,
  558. usb_rcvbulkpipe(usb_dev, 0x4),
  559. dev->ep4_in_buf, EP4_BUFSIZE,
  560. snd_usb_caiaq_ep4_reply_dispatch, dev);
  561. snd_usb_caiaq_set_auto_msg(dev, 1, 10, 5);
  562. break;
  563. default:
  564. /* no input methods supported on this device */
  565. goto exit_free_idev;
  566. }
  567. input->open = snd_usb_caiaq_input_open;
  568. input->close = snd_usb_caiaq_input_close;
  569. input->keycode = dev->keycode;
  570. input->keycodesize = sizeof(unsigned short);
  571. for (i = 0; i < input->keycodemax; i++)
  572. __set_bit(dev->keycode[i], input->keybit);
  573. ret = input_register_device(input);
  574. if (ret < 0)
  575. goto exit_free_idev;
  576. dev->input_dev = input;
  577. return 0;
  578. exit_free_idev:
  579. input_free_device(input);
  580. return ret;
  581. }
  582. void snd_usb_caiaq_input_free(struct snd_usb_caiaqdev *dev)
  583. {
  584. if (!dev || !dev->input_dev)
  585. return;
  586. usb_kill_urb(dev->ep4_in_urb);
  587. usb_free_urb(dev->ep4_in_urb);
  588. dev->ep4_in_urb = NULL;
  589. input_unregister_device(dev->input_dev);
  590. dev->input_dev = NULL;
  591. }