hid-roccat-kovaplus.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. /*
  2. * Roccat Kova[+] driver for Linux
  3. *
  4. * Copyright (c) 2011 Stefan Achatz <erazor_de@users.sourceforge.net>
  5. */
  6. /*
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the Free
  9. * Software Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. */
  12. /*
  13. * Roccat Kova[+] is a bigger version of the Pyra with two more side buttons.
  14. */
  15. #include <linux/device.h>
  16. #include <linux/input.h>
  17. #include <linux/hid.h>
  18. #include <linux/module.h>
  19. #include <linux/slab.h>
  20. #include <linux/hid-roccat.h>
  21. #include "hid-ids.h"
  22. #include "hid-roccat-common.h"
  23. #include "hid-roccat-kovaplus.h"
  24. static uint profile_numbers[5] = {0, 1, 2, 3, 4};
  25. static struct class *kovaplus_class;
  26. static uint kovaplus_convert_event_cpi(uint value)
  27. {
  28. return (value == 7 ? 4 : (value == 4 ? 3 : value));
  29. }
  30. static void kovaplus_profile_activated(struct kovaplus_device *kovaplus,
  31. uint new_profile_index)
  32. {
  33. kovaplus->actual_profile = new_profile_index;
  34. kovaplus->actual_cpi = kovaplus->profile_settings[new_profile_index].cpi_startup_level;
  35. kovaplus->actual_x_sensitivity = kovaplus->profile_settings[new_profile_index].sensitivity_x;
  36. kovaplus->actual_y_sensitivity = kovaplus->profile_settings[new_profile_index].sensitivity_y;
  37. }
  38. static int kovaplus_send_control(struct usb_device *usb_dev, uint value,
  39. enum kovaplus_control_requests request)
  40. {
  41. int retval;
  42. struct roccat_common2_control control;
  43. if ((request == KOVAPLUS_CONTROL_REQUEST_PROFILE_SETTINGS ||
  44. request == KOVAPLUS_CONTROL_REQUEST_PROFILE_BUTTONS) &&
  45. value > 4)
  46. return -EINVAL;
  47. control.command = ROCCAT_COMMON_COMMAND_CONTROL;
  48. control.value = value;
  49. control.request = request;
  50. retval = roccat_common2_send(usb_dev, ROCCAT_COMMON_COMMAND_CONTROL,
  51. &control, sizeof(struct roccat_common2_control));
  52. return retval;
  53. }
  54. static int kovaplus_select_profile(struct usb_device *usb_dev, uint number,
  55. enum kovaplus_control_requests request)
  56. {
  57. return kovaplus_send_control(usb_dev, number, request);
  58. }
  59. static int kovaplus_get_profile_settings(struct usb_device *usb_dev,
  60. struct kovaplus_profile_settings *buf, uint number)
  61. {
  62. int retval;
  63. retval = kovaplus_select_profile(usb_dev, number,
  64. KOVAPLUS_CONTROL_REQUEST_PROFILE_SETTINGS);
  65. if (retval)
  66. return retval;
  67. return roccat_common2_receive(usb_dev, KOVAPLUS_COMMAND_PROFILE_SETTINGS,
  68. buf, KOVAPLUS_SIZE_PROFILE_SETTINGS);
  69. }
  70. static int kovaplus_get_profile_buttons(struct usb_device *usb_dev,
  71. struct kovaplus_profile_buttons *buf, int number)
  72. {
  73. int retval;
  74. retval = kovaplus_select_profile(usb_dev, number,
  75. KOVAPLUS_CONTROL_REQUEST_PROFILE_BUTTONS);
  76. if (retval)
  77. return retval;
  78. return roccat_common2_receive(usb_dev, KOVAPLUS_COMMAND_PROFILE_BUTTONS,
  79. buf, KOVAPLUS_SIZE_PROFILE_BUTTONS);
  80. }
  81. /* retval is 0-4 on success, < 0 on error */
  82. static int kovaplus_get_actual_profile(struct usb_device *usb_dev)
  83. {
  84. struct kovaplus_actual_profile buf;
  85. int retval;
  86. retval = roccat_common2_receive(usb_dev, KOVAPLUS_COMMAND_ACTUAL_PROFILE,
  87. &buf, sizeof(struct kovaplus_actual_profile));
  88. return retval ? retval : buf.actual_profile;
  89. }
  90. static int kovaplus_set_actual_profile(struct usb_device *usb_dev,
  91. int new_profile)
  92. {
  93. struct kovaplus_actual_profile buf;
  94. buf.command = KOVAPLUS_COMMAND_ACTUAL_PROFILE;
  95. buf.size = sizeof(struct kovaplus_actual_profile);
  96. buf.actual_profile = new_profile;
  97. return roccat_common2_send_with_status(usb_dev,
  98. KOVAPLUS_COMMAND_ACTUAL_PROFILE,
  99. &buf, sizeof(struct kovaplus_actual_profile));
  100. }
  101. static ssize_t kovaplus_sysfs_read(struct file *fp, struct kobject *kobj,
  102. char *buf, loff_t off, size_t count,
  103. size_t real_size, uint command)
  104. {
  105. struct device *dev = kobj_to_dev(kobj)->parent->parent;
  106. struct kovaplus_device *kovaplus = hid_get_drvdata(dev_get_drvdata(dev));
  107. struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
  108. int retval;
  109. if (off >= real_size)
  110. return 0;
  111. if (off != 0 || count != real_size)
  112. return -EINVAL;
  113. mutex_lock(&kovaplus->kovaplus_lock);
  114. retval = roccat_common2_receive(usb_dev, command, buf, real_size);
  115. mutex_unlock(&kovaplus->kovaplus_lock);
  116. if (retval)
  117. return retval;
  118. return real_size;
  119. }
  120. static ssize_t kovaplus_sysfs_write(struct file *fp, struct kobject *kobj,
  121. void const *buf, loff_t off, size_t count,
  122. size_t real_size, uint command)
  123. {
  124. struct device *dev = kobj_to_dev(kobj)->parent->parent;
  125. struct kovaplus_device *kovaplus = hid_get_drvdata(dev_get_drvdata(dev));
  126. struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
  127. int retval;
  128. if (off != 0 || count != real_size)
  129. return -EINVAL;
  130. mutex_lock(&kovaplus->kovaplus_lock);
  131. retval = roccat_common2_send_with_status(usb_dev, command,
  132. buf, real_size);
  133. mutex_unlock(&kovaplus->kovaplus_lock);
  134. if (retval)
  135. return retval;
  136. return real_size;
  137. }
  138. #define KOVAPLUS_SYSFS_W(thingy, THINGY) \
  139. static ssize_t kovaplus_sysfs_write_ ## thingy(struct file *fp, \
  140. struct kobject *kobj, struct bin_attribute *attr, char *buf, \
  141. loff_t off, size_t count) \
  142. { \
  143. return kovaplus_sysfs_write(fp, kobj, buf, off, count, \
  144. KOVAPLUS_SIZE_ ## THINGY, KOVAPLUS_COMMAND_ ## THINGY); \
  145. }
  146. #define KOVAPLUS_SYSFS_R(thingy, THINGY) \
  147. static ssize_t kovaplus_sysfs_read_ ## thingy(struct file *fp, \
  148. struct kobject *kobj, struct bin_attribute *attr, char *buf, \
  149. loff_t off, size_t count) \
  150. { \
  151. return kovaplus_sysfs_read(fp, kobj, buf, off, count, \
  152. KOVAPLUS_SIZE_ ## THINGY, KOVAPLUS_COMMAND_ ## THINGY); \
  153. }
  154. #define KOVAPLUS_SYSFS_RW(thingy, THINGY) \
  155. KOVAPLUS_SYSFS_W(thingy, THINGY) \
  156. KOVAPLUS_SYSFS_R(thingy, THINGY)
  157. #define KOVAPLUS_BIN_ATTRIBUTE_RW(thingy, THINGY) \
  158. KOVAPLUS_SYSFS_RW(thingy, THINGY); \
  159. static struct bin_attribute bin_attr_##thingy = { \
  160. .attr = { .name = #thingy, .mode = 0660 }, \
  161. .size = KOVAPLUS_SIZE_ ## THINGY, \
  162. .read = kovaplus_sysfs_read_ ## thingy, \
  163. .write = kovaplus_sysfs_write_ ## thingy \
  164. }
  165. #define KOVAPLUS_BIN_ATTRIBUTE_W(thingy, THINGY) \
  166. KOVAPLUS_SYSFS_W(thingy, THINGY); \
  167. static struct bin_attribute bin_attr_##thingy = { \
  168. .attr = { .name = #thingy, .mode = 0220 }, \
  169. .size = KOVAPLUS_SIZE_ ## THINGY, \
  170. .write = kovaplus_sysfs_write_ ## thingy \
  171. }
  172. KOVAPLUS_BIN_ATTRIBUTE_W(control, CONTROL);
  173. KOVAPLUS_BIN_ATTRIBUTE_RW(info, INFO);
  174. KOVAPLUS_BIN_ATTRIBUTE_RW(profile_settings, PROFILE_SETTINGS);
  175. KOVAPLUS_BIN_ATTRIBUTE_RW(profile_buttons, PROFILE_BUTTONS);
  176. static ssize_t kovaplus_sysfs_read_profilex_settings(struct file *fp,
  177. struct kobject *kobj, struct bin_attribute *attr, char *buf,
  178. loff_t off, size_t count)
  179. {
  180. struct device *dev = kobj_to_dev(kobj)->parent->parent;
  181. struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
  182. ssize_t retval;
  183. retval = kovaplus_select_profile(usb_dev, *(uint *)(attr->private),
  184. KOVAPLUS_CONTROL_REQUEST_PROFILE_SETTINGS);
  185. if (retval)
  186. return retval;
  187. return kovaplus_sysfs_read(fp, kobj, buf, off, count,
  188. KOVAPLUS_SIZE_PROFILE_SETTINGS,
  189. KOVAPLUS_COMMAND_PROFILE_SETTINGS);
  190. }
  191. static ssize_t kovaplus_sysfs_read_profilex_buttons(struct file *fp,
  192. struct kobject *kobj, struct bin_attribute *attr, char *buf,
  193. loff_t off, size_t count)
  194. {
  195. struct device *dev = kobj_to_dev(kobj)->parent->parent;
  196. struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
  197. ssize_t retval;
  198. retval = kovaplus_select_profile(usb_dev, *(uint *)(attr->private),
  199. KOVAPLUS_CONTROL_REQUEST_PROFILE_BUTTONS);
  200. if (retval)
  201. return retval;
  202. return kovaplus_sysfs_read(fp, kobj, buf, off, count,
  203. KOVAPLUS_SIZE_PROFILE_BUTTONS,
  204. KOVAPLUS_COMMAND_PROFILE_BUTTONS);
  205. }
  206. #define PROFILE_ATTR(number) \
  207. static struct bin_attribute bin_attr_profile##number##_settings = { \
  208. .attr = { .name = "profile" #number "_settings", .mode = 0440 }, \
  209. .size = KOVAPLUS_SIZE_PROFILE_SETTINGS, \
  210. .read = kovaplus_sysfs_read_profilex_settings, \
  211. .private = &profile_numbers[number-1], \
  212. }; \
  213. static struct bin_attribute bin_attr_profile##number##_buttons = { \
  214. .attr = { .name = "profile" #number "_buttons", .mode = 0440 }, \
  215. .size = KOVAPLUS_SIZE_PROFILE_BUTTONS, \
  216. .read = kovaplus_sysfs_read_profilex_buttons, \
  217. .private = &profile_numbers[number-1], \
  218. };
  219. PROFILE_ATTR(1);
  220. PROFILE_ATTR(2);
  221. PROFILE_ATTR(3);
  222. PROFILE_ATTR(4);
  223. PROFILE_ATTR(5);
  224. static ssize_t kovaplus_sysfs_show_actual_profile(struct device *dev,
  225. struct device_attribute *attr, char *buf)
  226. {
  227. struct kovaplus_device *kovaplus =
  228. hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
  229. return snprintf(buf, PAGE_SIZE, "%d\n", kovaplus->actual_profile);
  230. }
  231. static ssize_t kovaplus_sysfs_set_actual_profile(struct device *dev,
  232. struct device_attribute *attr, char const *buf, size_t size)
  233. {
  234. struct kovaplus_device *kovaplus;
  235. struct usb_device *usb_dev;
  236. unsigned long profile;
  237. int retval;
  238. struct kovaplus_roccat_report roccat_report;
  239. dev = dev->parent->parent;
  240. kovaplus = hid_get_drvdata(dev_get_drvdata(dev));
  241. usb_dev = interface_to_usbdev(to_usb_interface(dev));
  242. retval = kstrtoul(buf, 10, &profile);
  243. if (retval)
  244. return retval;
  245. if (profile >= 5)
  246. return -EINVAL;
  247. mutex_lock(&kovaplus->kovaplus_lock);
  248. retval = kovaplus_set_actual_profile(usb_dev, profile);
  249. if (retval) {
  250. mutex_unlock(&kovaplus->kovaplus_lock);
  251. return retval;
  252. }
  253. kovaplus_profile_activated(kovaplus, profile);
  254. roccat_report.type = KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_PROFILE_1;
  255. roccat_report.profile = profile + 1;
  256. roccat_report.button = 0;
  257. roccat_report.data1 = profile + 1;
  258. roccat_report.data2 = 0;
  259. roccat_report_event(kovaplus->chrdev_minor,
  260. (uint8_t const *)&roccat_report);
  261. mutex_unlock(&kovaplus->kovaplus_lock);
  262. return size;
  263. }
  264. static DEVICE_ATTR(actual_profile, 0660,
  265. kovaplus_sysfs_show_actual_profile,
  266. kovaplus_sysfs_set_actual_profile);
  267. static ssize_t kovaplus_sysfs_show_actual_cpi(struct device *dev,
  268. struct device_attribute *attr, char *buf)
  269. {
  270. struct kovaplus_device *kovaplus =
  271. hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
  272. return snprintf(buf, PAGE_SIZE, "%d\n", kovaplus->actual_cpi);
  273. }
  274. static DEVICE_ATTR(actual_cpi, 0440, kovaplus_sysfs_show_actual_cpi, NULL);
  275. static ssize_t kovaplus_sysfs_show_actual_sensitivity_x(struct device *dev,
  276. struct device_attribute *attr, char *buf)
  277. {
  278. struct kovaplus_device *kovaplus =
  279. hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
  280. return snprintf(buf, PAGE_SIZE, "%d\n", kovaplus->actual_x_sensitivity);
  281. }
  282. static DEVICE_ATTR(actual_sensitivity_x, 0440,
  283. kovaplus_sysfs_show_actual_sensitivity_x, NULL);
  284. static ssize_t kovaplus_sysfs_show_actual_sensitivity_y(struct device *dev,
  285. struct device_attribute *attr, char *buf)
  286. {
  287. struct kovaplus_device *kovaplus =
  288. hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
  289. return snprintf(buf, PAGE_SIZE, "%d\n", kovaplus->actual_y_sensitivity);
  290. }
  291. static DEVICE_ATTR(actual_sensitivity_y, 0440,
  292. kovaplus_sysfs_show_actual_sensitivity_y, NULL);
  293. static ssize_t kovaplus_sysfs_show_firmware_version(struct device *dev,
  294. struct device_attribute *attr, char *buf)
  295. {
  296. struct kovaplus_device *kovaplus;
  297. struct usb_device *usb_dev;
  298. struct kovaplus_info info;
  299. dev = dev->parent->parent;
  300. kovaplus = hid_get_drvdata(dev_get_drvdata(dev));
  301. usb_dev = interface_to_usbdev(to_usb_interface(dev));
  302. mutex_lock(&kovaplus->kovaplus_lock);
  303. roccat_common2_receive(usb_dev, KOVAPLUS_COMMAND_INFO,
  304. &info, KOVAPLUS_SIZE_INFO);
  305. mutex_unlock(&kovaplus->kovaplus_lock);
  306. return snprintf(buf, PAGE_SIZE, "%d\n", info.firmware_version);
  307. }
  308. static DEVICE_ATTR(firmware_version, 0440,
  309. kovaplus_sysfs_show_firmware_version, NULL);
  310. static struct attribute *kovaplus_attrs[] = {
  311. &dev_attr_actual_cpi.attr,
  312. &dev_attr_firmware_version.attr,
  313. &dev_attr_actual_profile.attr,
  314. &dev_attr_actual_sensitivity_x.attr,
  315. &dev_attr_actual_sensitivity_y.attr,
  316. NULL,
  317. };
  318. static struct bin_attribute *kovaplus_bin_attributes[] = {
  319. &bin_attr_control,
  320. &bin_attr_info,
  321. &bin_attr_profile_settings,
  322. &bin_attr_profile_buttons,
  323. &bin_attr_profile1_settings,
  324. &bin_attr_profile2_settings,
  325. &bin_attr_profile3_settings,
  326. &bin_attr_profile4_settings,
  327. &bin_attr_profile5_settings,
  328. &bin_attr_profile1_buttons,
  329. &bin_attr_profile2_buttons,
  330. &bin_attr_profile3_buttons,
  331. &bin_attr_profile4_buttons,
  332. &bin_attr_profile5_buttons,
  333. NULL,
  334. };
  335. static const struct attribute_group kovaplus_group = {
  336. .attrs = kovaplus_attrs,
  337. .bin_attrs = kovaplus_bin_attributes,
  338. };
  339. static const struct attribute_group *kovaplus_groups[] = {
  340. &kovaplus_group,
  341. NULL,
  342. };
  343. static int kovaplus_init_kovaplus_device_struct(struct usb_device *usb_dev,
  344. struct kovaplus_device *kovaplus)
  345. {
  346. int retval, i;
  347. static uint wait = 70; /* device will freeze with just 60 */
  348. mutex_init(&kovaplus->kovaplus_lock);
  349. for (i = 0; i < 5; ++i) {
  350. msleep(wait);
  351. retval = kovaplus_get_profile_settings(usb_dev,
  352. &kovaplus->profile_settings[i], i);
  353. if (retval)
  354. return retval;
  355. msleep(wait);
  356. retval = kovaplus_get_profile_buttons(usb_dev,
  357. &kovaplus->profile_buttons[i], i);
  358. if (retval)
  359. return retval;
  360. }
  361. msleep(wait);
  362. retval = kovaplus_get_actual_profile(usb_dev);
  363. if (retval < 0)
  364. return retval;
  365. kovaplus_profile_activated(kovaplus, retval);
  366. return 0;
  367. }
  368. static int kovaplus_init_specials(struct hid_device *hdev)
  369. {
  370. struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
  371. struct usb_device *usb_dev = interface_to_usbdev(intf);
  372. struct kovaplus_device *kovaplus;
  373. int retval;
  374. if (intf->cur_altsetting->desc.bInterfaceProtocol
  375. == USB_INTERFACE_PROTOCOL_MOUSE) {
  376. kovaplus = kzalloc(sizeof(*kovaplus), GFP_KERNEL);
  377. if (!kovaplus) {
  378. hid_err(hdev, "can't alloc device descriptor\n");
  379. return -ENOMEM;
  380. }
  381. hid_set_drvdata(hdev, kovaplus);
  382. retval = kovaplus_init_kovaplus_device_struct(usb_dev, kovaplus);
  383. if (retval) {
  384. hid_err(hdev, "couldn't init struct kovaplus_device\n");
  385. goto exit_free;
  386. }
  387. retval = roccat_connect(kovaplus_class, hdev,
  388. sizeof(struct kovaplus_roccat_report));
  389. if (retval < 0) {
  390. hid_err(hdev, "couldn't init char dev\n");
  391. } else {
  392. kovaplus->chrdev_minor = retval;
  393. kovaplus->roccat_claimed = 1;
  394. }
  395. } else {
  396. hid_set_drvdata(hdev, NULL);
  397. }
  398. return 0;
  399. exit_free:
  400. kfree(kovaplus);
  401. return retval;
  402. }
  403. static void kovaplus_remove_specials(struct hid_device *hdev)
  404. {
  405. struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
  406. struct kovaplus_device *kovaplus;
  407. if (intf->cur_altsetting->desc.bInterfaceProtocol
  408. == USB_INTERFACE_PROTOCOL_MOUSE) {
  409. kovaplus = hid_get_drvdata(hdev);
  410. if (kovaplus->roccat_claimed)
  411. roccat_disconnect(kovaplus->chrdev_minor);
  412. kfree(kovaplus);
  413. }
  414. }
  415. static int kovaplus_probe(struct hid_device *hdev,
  416. const struct hid_device_id *id)
  417. {
  418. int retval;
  419. retval = hid_parse(hdev);
  420. if (retval) {
  421. hid_err(hdev, "parse failed\n");
  422. goto exit;
  423. }
  424. retval = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
  425. if (retval) {
  426. hid_err(hdev, "hw start failed\n");
  427. goto exit;
  428. }
  429. retval = kovaplus_init_specials(hdev);
  430. if (retval) {
  431. hid_err(hdev, "couldn't install mouse\n");
  432. goto exit_stop;
  433. }
  434. return 0;
  435. exit_stop:
  436. hid_hw_stop(hdev);
  437. exit:
  438. return retval;
  439. }
  440. static void kovaplus_remove(struct hid_device *hdev)
  441. {
  442. kovaplus_remove_specials(hdev);
  443. hid_hw_stop(hdev);
  444. }
  445. static void kovaplus_keep_values_up_to_date(struct kovaplus_device *kovaplus,
  446. u8 const *data)
  447. {
  448. struct kovaplus_mouse_report_button const *button_report;
  449. if (data[0] != KOVAPLUS_MOUSE_REPORT_NUMBER_BUTTON)
  450. return;
  451. button_report = (struct kovaplus_mouse_report_button const *)data;
  452. switch (button_report->type) {
  453. case KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_PROFILE_1:
  454. kovaplus_profile_activated(kovaplus, button_report->data1 - 1);
  455. break;
  456. case KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_CPI:
  457. kovaplus->actual_cpi = kovaplus_convert_event_cpi(button_report->data1);
  458. break;
  459. case KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_SENSITIVITY:
  460. kovaplus->actual_x_sensitivity = button_report->data1;
  461. kovaplus->actual_y_sensitivity = button_report->data2;
  462. break;
  463. default:
  464. break;
  465. }
  466. }
  467. static void kovaplus_report_to_chrdev(struct kovaplus_device const *kovaplus,
  468. u8 const *data)
  469. {
  470. struct kovaplus_roccat_report roccat_report;
  471. struct kovaplus_mouse_report_button const *button_report;
  472. if (data[0] != KOVAPLUS_MOUSE_REPORT_NUMBER_BUTTON)
  473. return;
  474. button_report = (struct kovaplus_mouse_report_button const *)data;
  475. if (button_report->type == KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_PROFILE_2)
  476. return;
  477. roccat_report.type = button_report->type;
  478. roccat_report.profile = kovaplus->actual_profile + 1;
  479. if (roccat_report.type == KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_MACRO ||
  480. roccat_report.type == KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_SHORTCUT ||
  481. roccat_report.type == KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_QUICKLAUNCH ||
  482. roccat_report.type == KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_TIMER)
  483. roccat_report.button = button_report->data1;
  484. else
  485. roccat_report.button = 0;
  486. if (roccat_report.type == KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_CPI)
  487. roccat_report.data1 = kovaplus_convert_event_cpi(button_report->data1);
  488. else
  489. roccat_report.data1 = button_report->data1;
  490. roccat_report.data2 = button_report->data2;
  491. roccat_report_event(kovaplus->chrdev_minor,
  492. (uint8_t const *)&roccat_report);
  493. }
  494. static int kovaplus_raw_event(struct hid_device *hdev,
  495. struct hid_report *report, u8 *data, int size)
  496. {
  497. struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
  498. struct kovaplus_device *kovaplus = hid_get_drvdata(hdev);
  499. if (intf->cur_altsetting->desc.bInterfaceProtocol
  500. != USB_INTERFACE_PROTOCOL_MOUSE)
  501. return 0;
  502. if (kovaplus == NULL)
  503. return 0;
  504. kovaplus_keep_values_up_to_date(kovaplus, data);
  505. if (kovaplus->roccat_claimed)
  506. kovaplus_report_to_chrdev(kovaplus, data);
  507. return 0;
  508. }
  509. static const struct hid_device_id kovaplus_devices[] = {
  510. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KOVAPLUS) },
  511. { }
  512. };
  513. MODULE_DEVICE_TABLE(hid, kovaplus_devices);
  514. static struct hid_driver kovaplus_driver = {
  515. .name = "kovaplus",
  516. .id_table = kovaplus_devices,
  517. .probe = kovaplus_probe,
  518. .remove = kovaplus_remove,
  519. .raw_event = kovaplus_raw_event
  520. };
  521. static int __init kovaplus_init(void)
  522. {
  523. int retval;
  524. kovaplus_class = class_create(THIS_MODULE, "kovaplus");
  525. if (IS_ERR(kovaplus_class))
  526. return PTR_ERR(kovaplus_class);
  527. kovaplus_class->dev_groups = kovaplus_groups;
  528. retval = hid_register_driver(&kovaplus_driver);
  529. if (retval)
  530. class_destroy(kovaplus_class);
  531. return retval;
  532. }
  533. static void __exit kovaplus_exit(void)
  534. {
  535. hid_unregister_driver(&kovaplus_driver);
  536. class_destroy(kovaplus_class);
  537. }
  538. module_init(kovaplus_init);
  539. module_exit(kovaplus_exit);
  540. MODULE_AUTHOR("Stefan Achatz");
  541. MODULE_DESCRIPTION("USB Roccat Kova[+] driver");
  542. MODULE_LICENSE("GPL v2");