hid-corsair.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. /*
  2. * HID driver for Corsair devices
  3. *
  4. * Supported devices:
  5. * - Vengeance K90 Keyboard
  6. *
  7. * Copyright (c) 2015 Clement Vuchener
  8. */
  9. /*
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the Free
  12. * Software Foundation; either version 2 of the License, or (at your option)
  13. * any later version.
  14. */
  15. #include <linux/hid.h>
  16. #include <linux/module.h>
  17. #include <linux/usb.h>
  18. #include <linux/leds.h>
  19. #include "hid-ids.h"
  20. #define CORSAIR_USE_K90_MACRO (1<<0)
  21. #define CORSAIR_USE_K90_BACKLIGHT (1<<1)
  22. struct k90_led {
  23. struct led_classdev cdev;
  24. int brightness;
  25. struct work_struct work;
  26. bool removed;
  27. };
  28. struct k90_drvdata {
  29. struct k90_led record_led;
  30. };
  31. struct corsair_drvdata {
  32. unsigned long quirks;
  33. struct k90_drvdata *k90;
  34. struct k90_led *backlight;
  35. };
  36. #define K90_GKEY_COUNT 18
  37. static int corsair_usage_to_gkey(unsigned int usage)
  38. {
  39. /* G1 (0xd0) to G16 (0xdf) */
  40. if (usage >= 0xd0 && usage <= 0xdf)
  41. return usage - 0xd0 + 1;
  42. /* G17 (0xe8) to G18 (0xe9) */
  43. if (usage >= 0xe8 && usage <= 0xe9)
  44. return usage - 0xe8 + 17;
  45. return 0;
  46. }
  47. static unsigned short corsair_gkey_map[K90_GKEY_COUNT] = {
  48. BTN_TRIGGER_HAPPY1,
  49. BTN_TRIGGER_HAPPY2,
  50. BTN_TRIGGER_HAPPY3,
  51. BTN_TRIGGER_HAPPY4,
  52. BTN_TRIGGER_HAPPY5,
  53. BTN_TRIGGER_HAPPY6,
  54. BTN_TRIGGER_HAPPY7,
  55. BTN_TRIGGER_HAPPY8,
  56. BTN_TRIGGER_HAPPY9,
  57. BTN_TRIGGER_HAPPY10,
  58. BTN_TRIGGER_HAPPY11,
  59. BTN_TRIGGER_HAPPY12,
  60. BTN_TRIGGER_HAPPY13,
  61. BTN_TRIGGER_HAPPY14,
  62. BTN_TRIGGER_HAPPY15,
  63. BTN_TRIGGER_HAPPY16,
  64. BTN_TRIGGER_HAPPY17,
  65. BTN_TRIGGER_HAPPY18,
  66. };
  67. module_param_array_named(gkey_codes, corsair_gkey_map, ushort, NULL, S_IRUGO);
  68. MODULE_PARM_DESC(gkey_codes, "Key codes for the G-keys");
  69. static unsigned short corsair_record_keycodes[2] = {
  70. BTN_TRIGGER_HAPPY19,
  71. BTN_TRIGGER_HAPPY20
  72. };
  73. module_param_array_named(recordkey_codes, corsair_record_keycodes, ushort,
  74. NULL, S_IRUGO);
  75. MODULE_PARM_DESC(recordkey_codes, "Key codes for the MR (start and stop record) button");
  76. static unsigned short corsair_profile_keycodes[3] = {
  77. BTN_TRIGGER_HAPPY21,
  78. BTN_TRIGGER_HAPPY22,
  79. BTN_TRIGGER_HAPPY23
  80. };
  81. module_param_array_named(profilekey_codes, corsair_profile_keycodes, ushort,
  82. NULL, S_IRUGO);
  83. MODULE_PARM_DESC(profilekey_codes, "Key codes for the profile buttons");
  84. #define CORSAIR_USAGE_SPECIAL_MIN 0xf0
  85. #define CORSAIR_USAGE_SPECIAL_MAX 0xff
  86. #define CORSAIR_USAGE_MACRO_RECORD_START 0xf6
  87. #define CORSAIR_USAGE_MACRO_RECORD_STOP 0xf7
  88. #define CORSAIR_USAGE_PROFILE 0xf1
  89. #define CORSAIR_USAGE_M1 0xf1
  90. #define CORSAIR_USAGE_M2 0xf2
  91. #define CORSAIR_USAGE_M3 0xf3
  92. #define CORSAIR_USAGE_PROFILE_MAX 0xf3
  93. #define CORSAIR_USAGE_META_OFF 0xf4
  94. #define CORSAIR_USAGE_META_ON 0xf5
  95. #define CORSAIR_USAGE_LIGHT 0xfa
  96. #define CORSAIR_USAGE_LIGHT_OFF 0xfa
  97. #define CORSAIR_USAGE_LIGHT_DIM 0xfb
  98. #define CORSAIR_USAGE_LIGHT_MEDIUM 0xfc
  99. #define CORSAIR_USAGE_LIGHT_BRIGHT 0xfd
  100. #define CORSAIR_USAGE_LIGHT_MAX 0xfd
  101. /* USB control protocol */
  102. #define K90_REQUEST_BRIGHTNESS 49
  103. #define K90_REQUEST_MACRO_MODE 2
  104. #define K90_REQUEST_STATUS 4
  105. #define K90_REQUEST_GET_MODE 5
  106. #define K90_REQUEST_PROFILE 20
  107. #define K90_MACRO_MODE_SW 0x0030
  108. #define K90_MACRO_MODE_HW 0x0001
  109. #define K90_MACRO_LED_ON 0x0020
  110. #define K90_MACRO_LED_OFF 0x0040
  111. /*
  112. * LED class devices
  113. */
  114. #define K90_BACKLIGHT_LED_SUFFIX "::backlight"
  115. #define K90_RECORD_LED_SUFFIX "::record"
  116. static enum led_brightness k90_backlight_get(struct led_classdev *led_cdev)
  117. {
  118. int ret;
  119. struct k90_led *led = container_of(led_cdev, struct k90_led, cdev);
  120. struct device *dev = led->cdev.dev->parent;
  121. struct usb_interface *usbif = to_usb_interface(dev->parent);
  122. struct usb_device *usbdev = interface_to_usbdev(usbif);
  123. int brightness;
  124. char data[8];
  125. ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0),
  126. K90_REQUEST_STATUS,
  127. USB_DIR_IN | USB_TYPE_VENDOR |
  128. USB_RECIP_DEVICE, 0, 0, data, 8,
  129. USB_CTRL_SET_TIMEOUT);
  130. if (ret < 0) {
  131. dev_warn(dev, "Failed to get K90 initial state (error %d).\n",
  132. ret);
  133. return -EIO;
  134. }
  135. brightness = data[4];
  136. if (brightness < 0 || brightness > 3) {
  137. dev_warn(dev,
  138. "Read invalid backlight brightness: %02hhx.\n",
  139. data[4]);
  140. return -EIO;
  141. }
  142. return brightness;
  143. }
  144. static enum led_brightness k90_record_led_get(struct led_classdev *led_cdev)
  145. {
  146. struct k90_led *led = container_of(led_cdev, struct k90_led, cdev);
  147. return led->brightness;
  148. }
  149. static void k90_brightness_set(struct led_classdev *led_cdev,
  150. enum led_brightness brightness)
  151. {
  152. struct k90_led *led = container_of(led_cdev, struct k90_led, cdev);
  153. led->brightness = brightness;
  154. schedule_work(&led->work);
  155. }
  156. static void k90_backlight_work(struct work_struct *work)
  157. {
  158. int ret;
  159. struct k90_led *led = container_of(work, struct k90_led, work);
  160. struct device *dev;
  161. struct usb_interface *usbif;
  162. struct usb_device *usbdev;
  163. if (led->removed)
  164. return;
  165. dev = led->cdev.dev->parent;
  166. usbif = to_usb_interface(dev->parent);
  167. usbdev = interface_to_usbdev(usbif);
  168. ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0),
  169. K90_REQUEST_BRIGHTNESS,
  170. USB_DIR_OUT | USB_TYPE_VENDOR |
  171. USB_RECIP_DEVICE, led->brightness, 0,
  172. NULL, 0, USB_CTRL_SET_TIMEOUT);
  173. if (ret != 0)
  174. dev_warn(dev, "Failed to set backlight brightness (error: %d).\n",
  175. ret);
  176. }
  177. static void k90_record_led_work(struct work_struct *work)
  178. {
  179. int ret;
  180. struct k90_led *led = container_of(work, struct k90_led, work);
  181. struct device *dev;
  182. struct usb_interface *usbif;
  183. struct usb_device *usbdev;
  184. int value;
  185. if (led->removed)
  186. return;
  187. dev = led->cdev.dev->parent;
  188. usbif = to_usb_interface(dev->parent);
  189. usbdev = interface_to_usbdev(usbif);
  190. if (led->brightness > 0)
  191. value = K90_MACRO_LED_ON;
  192. else
  193. value = K90_MACRO_LED_OFF;
  194. ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0),
  195. K90_REQUEST_MACRO_MODE,
  196. USB_DIR_OUT | USB_TYPE_VENDOR |
  197. USB_RECIP_DEVICE, value, 0, NULL, 0,
  198. USB_CTRL_SET_TIMEOUT);
  199. if (ret != 0)
  200. dev_warn(dev, "Failed to set record LED state (error: %d).\n",
  201. ret);
  202. }
  203. /*
  204. * Keyboard attributes
  205. */
  206. static ssize_t k90_show_macro_mode(struct device *dev,
  207. struct device_attribute *attr, char *buf)
  208. {
  209. int ret;
  210. struct usb_interface *usbif = to_usb_interface(dev->parent);
  211. struct usb_device *usbdev = interface_to_usbdev(usbif);
  212. const char *macro_mode;
  213. char data[8];
  214. ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0),
  215. K90_REQUEST_GET_MODE,
  216. USB_DIR_IN | USB_TYPE_VENDOR |
  217. USB_RECIP_DEVICE, 0, 0, data, 2,
  218. USB_CTRL_SET_TIMEOUT);
  219. if (ret < 0) {
  220. dev_warn(dev, "Failed to get K90 initial mode (error %d).\n",
  221. ret);
  222. return -EIO;
  223. }
  224. switch (data[0]) {
  225. case K90_MACRO_MODE_HW:
  226. macro_mode = "HW";
  227. break;
  228. case K90_MACRO_MODE_SW:
  229. macro_mode = "SW";
  230. break;
  231. default:
  232. dev_warn(dev, "K90 in unknown mode: %02hhx.\n",
  233. data[0]);
  234. return -EIO;
  235. }
  236. return snprintf(buf, PAGE_SIZE, "%s\n", macro_mode);
  237. }
  238. static ssize_t k90_store_macro_mode(struct device *dev,
  239. struct device_attribute *attr,
  240. const char *buf, size_t count)
  241. {
  242. int ret;
  243. struct usb_interface *usbif = to_usb_interface(dev->parent);
  244. struct usb_device *usbdev = interface_to_usbdev(usbif);
  245. __u16 value;
  246. if (strncmp(buf, "SW", 2) == 0)
  247. value = K90_MACRO_MODE_SW;
  248. else if (strncmp(buf, "HW", 2) == 0)
  249. value = K90_MACRO_MODE_HW;
  250. else
  251. return -EINVAL;
  252. ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0),
  253. K90_REQUEST_MACRO_MODE,
  254. USB_DIR_OUT | USB_TYPE_VENDOR |
  255. USB_RECIP_DEVICE, value, 0, NULL, 0,
  256. USB_CTRL_SET_TIMEOUT);
  257. if (ret != 0) {
  258. dev_warn(dev, "Failed to set macro mode.\n");
  259. return ret;
  260. }
  261. return count;
  262. }
  263. static ssize_t k90_show_current_profile(struct device *dev,
  264. struct device_attribute *attr,
  265. char *buf)
  266. {
  267. int ret;
  268. struct usb_interface *usbif = to_usb_interface(dev->parent);
  269. struct usb_device *usbdev = interface_to_usbdev(usbif);
  270. int current_profile;
  271. char data[8];
  272. ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0),
  273. K90_REQUEST_STATUS,
  274. USB_DIR_IN | USB_TYPE_VENDOR |
  275. USB_RECIP_DEVICE, 0, 0, data, 8,
  276. USB_CTRL_SET_TIMEOUT);
  277. if (ret < 0) {
  278. dev_warn(dev, "Failed to get K90 initial state (error %d).\n",
  279. ret);
  280. return -EIO;
  281. }
  282. current_profile = data[7];
  283. if (current_profile < 1 || current_profile > 3) {
  284. dev_warn(dev, "Read invalid current profile: %02hhx.\n",
  285. data[7]);
  286. return -EIO;
  287. }
  288. return snprintf(buf, PAGE_SIZE, "%d\n", current_profile);
  289. }
  290. static ssize_t k90_store_current_profile(struct device *dev,
  291. struct device_attribute *attr,
  292. const char *buf, size_t count)
  293. {
  294. int ret;
  295. struct usb_interface *usbif = to_usb_interface(dev->parent);
  296. struct usb_device *usbdev = interface_to_usbdev(usbif);
  297. int profile;
  298. if (kstrtoint(buf, 10, &profile))
  299. return -EINVAL;
  300. if (profile < 1 || profile > 3)
  301. return -EINVAL;
  302. ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0),
  303. K90_REQUEST_PROFILE,
  304. USB_DIR_OUT | USB_TYPE_VENDOR |
  305. USB_RECIP_DEVICE, profile, 0, NULL, 0,
  306. USB_CTRL_SET_TIMEOUT);
  307. if (ret != 0) {
  308. dev_warn(dev, "Failed to change current profile (error %d).\n",
  309. ret);
  310. return ret;
  311. }
  312. return count;
  313. }
  314. static DEVICE_ATTR(macro_mode, 0644, k90_show_macro_mode, k90_store_macro_mode);
  315. static DEVICE_ATTR(current_profile, 0644, k90_show_current_profile,
  316. k90_store_current_profile);
  317. static struct attribute *k90_attrs[] = {
  318. &dev_attr_macro_mode.attr,
  319. &dev_attr_current_profile.attr,
  320. NULL
  321. };
  322. static const struct attribute_group k90_attr_group = {
  323. .attrs = k90_attrs,
  324. };
  325. /*
  326. * Driver functions
  327. */
  328. static int k90_init_backlight(struct hid_device *dev)
  329. {
  330. int ret;
  331. struct corsair_drvdata *drvdata = hid_get_drvdata(dev);
  332. size_t name_sz;
  333. char *name;
  334. drvdata->backlight = kzalloc(sizeof(struct k90_led), GFP_KERNEL);
  335. if (!drvdata->backlight) {
  336. ret = -ENOMEM;
  337. goto fail_backlight_alloc;
  338. }
  339. name_sz =
  340. strlen(dev_name(&dev->dev)) + sizeof(K90_BACKLIGHT_LED_SUFFIX);
  341. name = kzalloc(name_sz, GFP_KERNEL);
  342. if (!name) {
  343. ret = -ENOMEM;
  344. goto fail_name_alloc;
  345. }
  346. snprintf(name, name_sz, "%s" K90_BACKLIGHT_LED_SUFFIX,
  347. dev_name(&dev->dev));
  348. drvdata->backlight->removed = false;
  349. drvdata->backlight->cdev.name = name;
  350. drvdata->backlight->cdev.max_brightness = 3;
  351. drvdata->backlight->cdev.brightness_set = k90_brightness_set;
  352. drvdata->backlight->cdev.brightness_get = k90_backlight_get;
  353. INIT_WORK(&drvdata->backlight->work, k90_backlight_work);
  354. ret = led_classdev_register(&dev->dev, &drvdata->backlight->cdev);
  355. if (ret != 0)
  356. goto fail_register_cdev;
  357. return 0;
  358. fail_register_cdev:
  359. kfree(drvdata->backlight->cdev.name);
  360. fail_name_alloc:
  361. kfree(drvdata->backlight);
  362. drvdata->backlight = NULL;
  363. fail_backlight_alloc:
  364. return ret;
  365. }
  366. static int k90_init_macro_functions(struct hid_device *dev)
  367. {
  368. int ret;
  369. struct corsair_drvdata *drvdata = hid_get_drvdata(dev);
  370. struct k90_drvdata *k90;
  371. size_t name_sz;
  372. char *name;
  373. k90 = kzalloc(sizeof(struct k90_drvdata), GFP_KERNEL);
  374. if (!k90) {
  375. ret = -ENOMEM;
  376. goto fail_drvdata;
  377. }
  378. drvdata->k90 = k90;
  379. /* Init LED device for record LED */
  380. name_sz = strlen(dev_name(&dev->dev)) + sizeof(K90_RECORD_LED_SUFFIX);
  381. name = kzalloc(name_sz, GFP_KERNEL);
  382. if (!name) {
  383. ret = -ENOMEM;
  384. goto fail_record_led_alloc;
  385. }
  386. snprintf(name, name_sz, "%s" K90_RECORD_LED_SUFFIX,
  387. dev_name(&dev->dev));
  388. k90->record_led.removed = false;
  389. k90->record_led.cdev.name = name;
  390. k90->record_led.cdev.max_brightness = 1;
  391. k90->record_led.cdev.brightness_set = k90_brightness_set;
  392. k90->record_led.cdev.brightness_get = k90_record_led_get;
  393. INIT_WORK(&k90->record_led.work, k90_record_led_work);
  394. k90->record_led.brightness = 0;
  395. ret = led_classdev_register(&dev->dev, &k90->record_led.cdev);
  396. if (ret != 0)
  397. goto fail_record_led;
  398. /* Init attributes */
  399. ret = sysfs_create_group(&dev->dev.kobj, &k90_attr_group);
  400. if (ret != 0)
  401. goto fail_sysfs;
  402. return 0;
  403. fail_sysfs:
  404. k90->record_led.removed = true;
  405. led_classdev_unregister(&k90->record_led.cdev);
  406. cancel_work_sync(&k90->record_led.work);
  407. fail_record_led:
  408. kfree(k90->record_led.cdev.name);
  409. fail_record_led_alloc:
  410. kfree(k90);
  411. fail_drvdata:
  412. drvdata->k90 = NULL;
  413. return ret;
  414. }
  415. static void k90_cleanup_backlight(struct hid_device *dev)
  416. {
  417. struct corsair_drvdata *drvdata = hid_get_drvdata(dev);
  418. if (drvdata->backlight) {
  419. drvdata->backlight->removed = true;
  420. led_classdev_unregister(&drvdata->backlight->cdev);
  421. cancel_work_sync(&drvdata->backlight->work);
  422. kfree(drvdata->backlight->cdev.name);
  423. kfree(drvdata->backlight);
  424. }
  425. }
  426. static void k90_cleanup_macro_functions(struct hid_device *dev)
  427. {
  428. struct corsair_drvdata *drvdata = hid_get_drvdata(dev);
  429. struct k90_drvdata *k90 = drvdata->k90;
  430. if (k90) {
  431. sysfs_remove_group(&dev->dev.kobj, &k90_attr_group);
  432. k90->record_led.removed = true;
  433. led_classdev_unregister(&k90->record_led.cdev);
  434. cancel_work_sync(&k90->record_led.work);
  435. kfree(k90->record_led.cdev.name);
  436. kfree(k90);
  437. }
  438. }
  439. static int corsair_probe(struct hid_device *dev, const struct hid_device_id *id)
  440. {
  441. int ret;
  442. unsigned long quirks = id->driver_data;
  443. struct corsair_drvdata *drvdata;
  444. struct usb_interface *usbif = to_usb_interface(dev->dev.parent);
  445. drvdata = devm_kzalloc(&dev->dev, sizeof(struct corsair_drvdata),
  446. GFP_KERNEL);
  447. if (drvdata == NULL)
  448. return -ENOMEM;
  449. drvdata->quirks = quirks;
  450. hid_set_drvdata(dev, drvdata);
  451. ret = hid_parse(dev);
  452. if (ret != 0) {
  453. hid_err(dev, "parse failed\n");
  454. return ret;
  455. }
  456. ret = hid_hw_start(dev, HID_CONNECT_DEFAULT);
  457. if (ret != 0) {
  458. hid_err(dev, "hw start failed\n");
  459. return ret;
  460. }
  461. if (usbif->cur_altsetting->desc.bInterfaceNumber == 0) {
  462. if (quirks & CORSAIR_USE_K90_MACRO) {
  463. ret = k90_init_macro_functions(dev);
  464. if (ret != 0)
  465. hid_warn(dev, "Failed to initialize K90 macro functions.\n");
  466. }
  467. if (quirks & CORSAIR_USE_K90_BACKLIGHT) {
  468. ret = k90_init_backlight(dev);
  469. if (ret != 0)
  470. hid_warn(dev, "Failed to initialize K90 backlight.\n");
  471. }
  472. }
  473. return 0;
  474. }
  475. static void corsair_remove(struct hid_device *dev)
  476. {
  477. k90_cleanup_macro_functions(dev);
  478. k90_cleanup_backlight(dev);
  479. hid_hw_stop(dev);
  480. }
  481. static int corsair_event(struct hid_device *dev, struct hid_field *field,
  482. struct hid_usage *usage, __s32 value)
  483. {
  484. struct corsair_drvdata *drvdata = hid_get_drvdata(dev);
  485. if (!drvdata->k90)
  486. return 0;
  487. switch (usage->hid & HID_USAGE) {
  488. case CORSAIR_USAGE_MACRO_RECORD_START:
  489. drvdata->k90->record_led.brightness = 1;
  490. break;
  491. case CORSAIR_USAGE_MACRO_RECORD_STOP:
  492. drvdata->k90->record_led.brightness = 0;
  493. break;
  494. default:
  495. break;
  496. }
  497. return 0;
  498. }
  499. static int corsair_input_mapping(struct hid_device *dev,
  500. struct hid_input *input,
  501. struct hid_field *field,
  502. struct hid_usage *usage, unsigned long **bit,
  503. int *max)
  504. {
  505. int gkey;
  506. if ((usage->hid & HID_USAGE_PAGE) != HID_UP_KEYBOARD)
  507. return 0;
  508. gkey = corsair_usage_to_gkey(usage->hid & HID_USAGE);
  509. if (gkey != 0) {
  510. hid_map_usage_clear(input, usage, bit, max, EV_KEY,
  511. corsair_gkey_map[gkey - 1]);
  512. return 1;
  513. }
  514. if ((usage->hid & HID_USAGE) >= CORSAIR_USAGE_SPECIAL_MIN &&
  515. (usage->hid & HID_USAGE) <= CORSAIR_USAGE_SPECIAL_MAX) {
  516. switch (usage->hid & HID_USAGE) {
  517. case CORSAIR_USAGE_MACRO_RECORD_START:
  518. hid_map_usage_clear(input, usage, bit, max, EV_KEY,
  519. corsair_record_keycodes[0]);
  520. return 1;
  521. case CORSAIR_USAGE_MACRO_RECORD_STOP:
  522. hid_map_usage_clear(input, usage, bit, max, EV_KEY,
  523. corsair_record_keycodes[1]);
  524. return 1;
  525. case CORSAIR_USAGE_M1:
  526. hid_map_usage_clear(input, usage, bit, max, EV_KEY,
  527. corsair_profile_keycodes[0]);
  528. return 1;
  529. case CORSAIR_USAGE_M2:
  530. hid_map_usage_clear(input, usage, bit, max, EV_KEY,
  531. corsair_profile_keycodes[1]);
  532. return 1;
  533. case CORSAIR_USAGE_M3:
  534. hid_map_usage_clear(input, usage, bit, max, EV_KEY,
  535. corsair_profile_keycodes[2]);
  536. return 1;
  537. default:
  538. return -1;
  539. }
  540. }
  541. return 0;
  542. }
  543. static const struct hid_device_id corsair_devices[] = {
  544. { HID_USB_DEVICE(USB_VENDOR_ID_CORSAIR, USB_DEVICE_ID_CORSAIR_K90),
  545. .driver_data = CORSAIR_USE_K90_MACRO |
  546. CORSAIR_USE_K90_BACKLIGHT },
  547. {}
  548. };
  549. MODULE_DEVICE_TABLE(hid, corsair_devices);
  550. static struct hid_driver corsair_driver = {
  551. .name = "corsair",
  552. .id_table = corsair_devices,
  553. .probe = corsair_probe,
  554. .event = corsair_event,
  555. .remove = corsair_remove,
  556. .input_mapping = corsair_input_mapping,
  557. };
  558. module_hid_driver(corsair_driver);
  559. MODULE_LICENSE("GPL");
  560. MODULE_AUTHOR("Clement Vuchener");
  561. MODULE_DESCRIPTION("HID driver for Corsair devices");