hid-roccat-kovaplus.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  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_info(struct usb_device *usb_dev,
  60. struct kovaplus_info *buf)
  61. {
  62. return roccat_common2_receive(usb_dev, KOVAPLUS_COMMAND_INFO,
  63. buf, sizeof(struct kovaplus_info));
  64. }
  65. static int kovaplus_get_profile_settings(struct usb_device *usb_dev,
  66. struct kovaplus_profile_settings *buf, uint number)
  67. {
  68. int retval;
  69. retval = kovaplus_select_profile(usb_dev, number,
  70. KOVAPLUS_CONTROL_REQUEST_PROFILE_SETTINGS);
  71. if (retval)
  72. return retval;
  73. return roccat_common2_receive(usb_dev, KOVAPLUS_COMMAND_PROFILE_SETTINGS,
  74. buf, sizeof(struct kovaplus_profile_settings));
  75. }
  76. static int kovaplus_set_profile_settings(struct usb_device *usb_dev,
  77. struct kovaplus_profile_settings const *settings)
  78. {
  79. return roccat_common2_send_with_status(usb_dev,
  80. KOVAPLUS_COMMAND_PROFILE_SETTINGS,
  81. settings, sizeof(struct kovaplus_profile_settings));
  82. }
  83. static int kovaplus_get_profile_buttons(struct usb_device *usb_dev,
  84. struct kovaplus_profile_buttons *buf, int number)
  85. {
  86. int retval;
  87. retval = kovaplus_select_profile(usb_dev, number,
  88. KOVAPLUS_CONTROL_REQUEST_PROFILE_BUTTONS);
  89. if (retval)
  90. return retval;
  91. return roccat_common2_receive(usb_dev, KOVAPLUS_COMMAND_PROFILE_BUTTONS,
  92. buf, sizeof(struct kovaplus_profile_buttons));
  93. }
  94. static int kovaplus_set_profile_buttons(struct usb_device *usb_dev,
  95. struct kovaplus_profile_buttons const *buttons)
  96. {
  97. return roccat_common2_send_with_status(usb_dev,
  98. KOVAPLUS_COMMAND_PROFILE_BUTTONS,
  99. buttons, sizeof(struct kovaplus_profile_buttons));
  100. }
  101. /* retval is 0-4 on success, < 0 on error */
  102. static int kovaplus_get_actual_profile(struct usb_device *usb_dev)
  103. {
  104. struct kovaplus_actual_profile buf;
  105. int retval;
  106. retval = roccat_common2_receive(usb_dev, KOVAPLUS_COMMAND_ACTUAL_PROFILE,
  107. &buf, sizeof(struct kovaplus_actual_profile));
  108. return retval ? retval : buf.actual_profile;
  109. }
  110. static int kovaplus_set_actual_profile(struct usb_device *usb_dev,
  111. int new_profile)
  112. {
  113. struct kovaplus_actual_profile buf;
  114. buf.command = KOVAPLUS_COMMAND_ACTUAL_PROFILE;
  115. buf.size = sizeof(struct kovaplus_actual_profile);
  116. buf.actual_profile = new_profile;
  117. return roccat_common2_send_with_status(usb_dev,
  118. KOVAPLUS_COMMAND_ACTUAL_PROFILE,
  119. &buf, sizeof(struct kovaplus_actual_profile));
  120. }
  121. static ssize_t kovaplus_sysfs_read_profilex_settings(struct file *fp,
  122. struct kobject *kobj, struct bin_attribute *attr, char *buf,
  123. loff_t off, size_t count)
  124. {
  125. struct device *dev =
  126. container_of(kobj, struct device, kobj)->parent->parent;
  127. struct kovaplus_device *kovaplus = hid_get_drvdata(dev_get_drvdata(dev));
  128. if (off >= sizeof(struct kovaplus_profile_settings))
  129. return 0;
  130. if (off + count > sizeof(struct kovaplus_profile_settings))
  131. count = sizeof(struct kovaplus_profile_settings) - off;
  132. mutex_lock(&kovaplus->kovaplus_lock);
  133. memcpy(buf, ((char const *)&kovaplus->profile_settings[*(uint *)(attr->private)]) + off,
  134. count);
  135. mutex_unlock(&kovaplus->kovaplus_lock);
  136. return count;
  137. }
  138. static ssize_t kovaplus_sysfs_write_profile_settings(struct file *fp,
  139. struct kobject *kobj, struct bin_attribute *attr, char *buf,
  140. loff_t off, size_t count)
  141. {
  142. struct device *dev =
  143. container_of(kobj, struct device, kobj)->parent->parent;
  144. struct kovaplus_device *kovaplus = hid_get_drvdata(dev_get_drvdata(dev));
  145. struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
  146. int retval = 0;
  147. int difference;
  148. int profile_index;
  149. struct kovaplus_profile_settings *profile_settings;
  150. if (off != 0 || count != sizeof(struct kovaplus_profile_settings))
  151. return -EINVAL;
  152. profile_index = ((struct kovaplus_profile_settings const *)buf)->profile_index;
  153. profile_settings = &kovaplus->profile_settings[profile_index];
  154. mutex_lock(&kovaplus->kovaplus_lock);
  155. difference = memcmp(buf, profile_settings,
  156. sizeof(struct kovaplus_profile_settings));
  157. if (difference) {
  158. retval = kovaplus_set_profile_settings(usb_dev,
  159. (struct kovaplus_profile_settings const *)buf);
  160. if (!retval)
  161. memcpy(profile_settings, buf,
  162. sizeof(struct kovaplus_profile_settings));
  163. }
  164. mutex_unlock(&kovaplus->kovaplus_lock);
  165. if (retval)
  166. return retval;
  167. return sizeof(struct kovaplus_profile_settings);
  168. }
  169. static ssize_t kovaplus_sysfs_read_profilex_buttons(struct file *fp,
  170. struct kobject *kobj, struct bin_attribute *attr, char *buf,
  171. loff_t off, size_t count)
  172. {
  173. struct device *dev =
  174. container_of(kobj, struct device, kobj)->parent->parent;
  175. struct kovaplus_device *kovaplus = hid_get_drvdata(dev_get_drvdata(dev));
  176. if (off >= sizeof(struct kovaplus_profile_buttons))
  177. return 0;
  178. if (off + count > sizeof(struct kovaplus_profile_buttons))
  179. count = sizeof(struct kovaplus_profile_buttons) - off;
  180. mutex_lock(&kovaplus->kovaplus_lock);
  181. memcpy(buf, ((char const *)&kovaplus->profile_buttons[*(uint *)(attr->private)]) + off,
  182. count);
  183. mutex_unlock(&kovaplus->kovaplus_lock);
  184. return count;
  185. }
  186. static ssize_t kovaplus_sysfs_write_profile_buttons(struct file *fp,
  187. struct kobject *kobj, struct bin_attribute *attr, char *buf,
  188. loff_t off, size_t count)
  189. {
  190. struct device *dev =
  191. container_of(kobj, struct device, kobj)->parent->parent;
  192. struct kovaplus_device *kovaplus = hid_get_drvdata(dev_get_drvdata(dev));
  193. struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
  194. int retval = 0;
  195. int difference;
  196. uint profile_index;
  197. struct kovaplus_profile_buttons *profile_buttons;
  198. if (off != 0 || count != sizeof(struct kovaplus_profile_buttons))
  199. return -EINVAL;
  200. profile_index = ((struct kovaplus_profile_buttons const *)buf)->profile_index;
  201. profile_buttons = &kovaplus->profile_buttons[profile_index];
  202. mutex_lock(&kovaplus->kovaplus_lock);
  203. difference = memcmp(buf, profile_buttons,
  204. sizeof(struct kovaplus_profile_buttons));
  205. if (difference) {
  206. retval = kovaplus_set_profile_buttons(usb_dev,
  207. (struct kovaplus_profile_buttons const *)buf);
  208. if (!retval)
  209. memcpy(profile_buttons, buf,
  210. sizeof(struct kovaplus_profile_buttons));
  211. }
  212. mutex_unlock(&kovaplus->kovaplus_lock);
  213. if (retval)
  214. return retval;
  215. return sizeof(struct kovaplus_profile_buttons);
  216. }
  217. static ssize_t kovaplus_sysfs_show_actual_profile(struct device *dev,
  218. struct device_attribute *attr, char *buf)
  219. {
  220. struct kovaplus_device *kovaplus =
  221. hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
  222. return snprintf(buf, PAGE_SIZE, "%d\n", kovaplus->actual_profile);
  223. }
  224. static ssize_t kovaplus_sysfs_set_actual_profile(struct device *dev,
  225. struct device_attribute *attr, char const *buf, size_t size)
  226. {
  227. struct kovaplus_device *kovaplus;
  228. struct usb_device *usb_dev;
  229. unsigned long profile;
  230. int retval;
  231. struct kovaplus_roccat_report roccat_report;
  232. dev = dev->parent->parent;
  233. kovaplus = hid_get_drvdata(dev_get_drvdata(dev));
  234. usb_dev = interface_to_usbdev(to_usb_interface(dev));
  235. retval = strict_strtoul(buf, 10, &profile);
  236. if (retval)
  237. return retval;
  238. if (profile >= 5)
  239. return -EINVAL;
  240. mutex_lock(&kovaplus->kovaplus_lock);
  241. retval = kovaplus_set_actual_profile(usb_dev, profile);
  242. if (retval) {
  243. mutex_unlock(&kovaplus->kovaplus_lock);
  244. return retval;
  245. }
  246. kovaplus_profile_activated(kovaplus, profile);
  247. roccat_report.type = KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_PROFILE_1;
  248. roccat_report.profile = profile + 1;
  249. roccat_report.button = 0;
  250. roccat_report.data1 = profile + 1;
  251. roccat_report.data2 = 0;
  252. roccat_report_event(kovaplus->chrdev_minor,
  253. (uint8_t const *)&roccat_report);
  254. mutex_unlock(&kovaplus->kovaplus_lock);
  255. return size;
  256. }
  257. static ssize_t kovaplus_sysfs_show_actual_cpi(struct device *dev,
  258. struct device_attribute *attr, char *buf)
  259. {
  260. struct kovaplus_device *kovaplus =
  261. hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
  262. return snprintf(buf, PAGE_SIZE, "%d\n", kovaplus->actual_cpi);
  263. }
  264. static ssize_t kovaplus_sysfs_show_actual_sensitivity_x(struct device *dev,
  265. struct device_attribute *attr, char *buf)
  266. {
  267. struct kovaplus_device *kovaplus =
  268. hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
  269. return snprintf(buf, PAGE_SIZE, "%d\n", kovaplus->actual_x_sensitivity);
  270. }
  271. static ssize_t kovaplus_sysfs_show_actual_sensitivity_y(struct device *dev,
  272. struct device_attribute *attr, char *buf)
  273. {
  274. struct kovaplus_device *kovaplus =
  275. hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
  276. return snprintf(buf, PAGE_SIZE, "%d\n", kovaplus->actual_y_sensitivity);
  277. }
  278. static ssize_t kovaplus_sysfs_show_firmware_version(struct device *dev,
  279. struct device_attribute *attr, char *buf)
  280. {
  281. struct kovaplus_device *kovaplus =
  282. hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
  283. return snprintf(buf, PAGE_SIZE, "%d\n", kovaplus->info.firmware_version);
  284. }
  285. static struct device_attribute kovaplus_attributes[] = {
  286. __ATTR(actual_cpi, 0440,
  287. kovaplus_sysfs_show_actual_cpi, NULL),
  288. __ATTR(firmware_version, 0440,
  289. kovaplus_sysfs_show_firmware_version, NULL),
  290. __ATTR(actual_profile, 0660,
  291. kovaplus_sysfs_show_actual_profile,
  292. kovaplus_sysfs_set_actual_profile),
  293. __ATTR(actual_sensitivity_x, 0440,
  294. kovaplus_sysfs_show_actual_sensitivity_x, NULL),
  295. __ATTR(actual_sensitivity_y, 0440,
  296. kovaplus_sysfs_show_actual_sensitivity_y, NULL),
  297. __ATTR_NULL
  298. };
  299. static struct bin_attribute kovaplus_bin_attributes[] = {
  300. {
  301. .attr = { .name = "profile_settings", .mode = 0220 },
  302. .size = sizeof(struct kovaplus_profile_settings),
  303. .write = kovaplus_sysfs_write_profile_settings
  304. },
  305. {
  306. .attr = { .name = "profile1_settings", .mode = 0440 },
  307. .size = sizeof(struct kovaplus_profile_settings),
  308. .read = kovaplus_sysfs_read_profilex_settings,
  309. .private = &profile_numbers[0]
  310. },
  311. {
  312. .attr = { .name = "profile2_settings", .mode = 0440 },
  313. .size = sizeof(struct kovaplus_profile_settings),
  314. .read = kovaplus_sysfs_read_profilex_settings,
  315. .private = &profile_numbers[1]
  316. },
  317. {
  318. .attr = { .name = "profile3_settings", .mode = 0440 },
  319. .size = sizeof(struct kovaplus_profile_settings),
  320. .read = kovaplus_sysfs_read_profilex_settings,
  321. .private = &profile_numbers[2]
  322. },
  323. {
  324. .attr = { .name = "profile4_settings", .mode = 0440 },
  325. .size = sizeof(struct kovaplus_profile_settings),
  326. .read = kovaplus_sysfs_read_profilex_settings,
  327. .private = &profile_numbers[3]
  328. },
  329. {
  330. .attr = { .name = "profile5_settings", .mode = 0440 },
  331. .size = sizeof(struct kovaplus_profile_settings),
  332. .read = kovaplus_sysfs_read_profilex_settings,
  333. .private = &profile_numbers[4]
  334. },
  335. {
  336. .attr = { .name = "profile_buttons", .mode = 0220 },
  337. .size = sizeof(struct kovaplus_profile_buttons),
  338. .write = kovaplus_sysfs_write_profile_buttons
  339. },
  340. {
  341. .attr = { .name = "profile1_buttons", .mode = 0440 },
  342. .size = sizeof(struct kovaplus_profile_buttons),
  343. .read = kovaplus_sysfs_read_profilex_buttons,
  344. .private = &profile_numbers[0]
  345. },
  346. {
  347. .attr = { .name = "profile2_buttons", .mode = 0440 },
  348. .size = sizeof(struct kovaplus_profile_buttons),
  349. .read = kovaplus_sysfs_read_profilex_buttons,
  350. .private = &profile_numbers[1]
  351. },
  352. {
  353. .attr = { .name = "profile3_buttons", .mode = 0440 },
  354. .size = sizeof(struct kovaplus_profile_buttons),
  355. .read = kovaplus_sysfs_read_profilex_buttons,
  356. .private = &profile_numbers[2]
  357. },
  358. {
  359. .attr = { .name = "profile4_buttons", .mode = 0440 },
  360. .size = sizeof(struct kovaplus_profile_buttons),
  361. .read = kovaplus_sysfs_read_profilex_buttons,
  362. .private = &profile_numbers[3]
  363. },
  364. {
  365. .attr = { .name = "profile5_buttons", .mode = 0440 },
  366. .size = sizeof(struct kovaplus_profile_buttons),
  367. .read = kovaplus_sysfs_read_profilex_buttons,
  368. .private = &profile_numbers[4]
  369. },
  370. __ATTR_NULL
  371. };
  372. static int kovaplus_init_kovaplus_device_struct(struct usb_device *usb_dev,
  373. struct kovaplus_device *kovaplus)
  374. {
  375. int retval, i;
  376. static uint wait = 70; /* device will freeze with just 60 */
  377. mutex_init(&kovaplus->kovaplus_lock);
  378. retval = kovaplus_get_info(usb_dev, &kovaplus->info);
  379. if (retval)
  380. return retval;
  381. for (i = 0; i < 5; ++i) {
  382. msleep(wait);
  383. retval = kovaplus_get_profile_settings(usb_dev,
  384. &kovaplus->profile_settings[i], i);
  385. if (retval)
  386. return retval;
  387. msleep(wait);
  388. retval = kovaplus_get_profile_buttons(usb_dev,
  389. &kovaplus->profile_buttons[i], i);
  390. if (retval)
  391. return retval;
  392. }
  393. msleep(wait);
  394. retval = kovaplus_get_actual_profile(usb_dev);
  395. if (retval < 0)
  396. return retval;
  397. kovaplus_profile_activated(kovaplus, retval);
  398. return 0;
  399. }
  400. static int kovaplus_init_specials(struct hid_device *hdev)
  401. {
  402. struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
  403. struct usb_device *usb_dev = interface_to_usbdev(intf);
  404. struct kovaplus_device *kovaplus;
  405. int retval;
  406. if (intf->cur_altsetting->desc.bInterfaceProtocol
  407. == USB_INTERFACE_PROTOCOL_MOUSE) {
  408. kovaplus = kzalloc(sizeof(*kovaplus), GFP_KERNEL);
  409. if (!kovaplus) {
  410. hid_err(hdev, "can't alloc device descriptor\n");
  411. return -ENOMEM;
  412. }
  413. hid_set_drvdata(hdev, kovaplus);
  414. retval = kovaplus_init_kovaplus_device_struct(usb_dev, kovaplus);
  415. if (retval) {
  416. hid_err(hdev, "couldn't init struct kovaplus_device\n");
  417. goto exit_free;
  418. }
  419. retval = roccat_connect(kovaplus_class, hdev,
  420. sizeof(struct kovaplus_roccat_report));
  421. if (retval < 0) {
  422. hid_err(hdev, "couldn't init char dev\n");
  423. } else {
  424. kovaplus->chrdev_minor = retval;
  425. kovaplus->roccat_claimed = 1;
  426. }
  427. } else {
  428. hid_set_drvdata(hdev, NULL);
  429. }
  430. return 0;
  431. exit_free:
  432. kfree(kovaplus);
  433. return retval;
  434. }
  435. static void kovaplus_remove_specials(struct hid_device *hdev)
  436. {
  437. struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
  438. struct kovaplus_device *kovaplus;
  439. if (intf->cur_altsetting->desc.bInterfaceProtocol
  440. == USB_INTERFACE_PROTOCOL_MOUSE) {
  441. kovaplus = hid_get_drvdata(hdev);
  442. if (kovaplus->roccat_claimed)
  443. roccat_disconnect(kovaplus->chrdev_minor);
  444. kfree(kovaplus);
  445. }
  446. }
  447. static int kovaplus_probe(struct hid_device *hdev,
  448. const struct hid_device_id *id)
  449. {
  450. int retval;
  451. retval = hid_parse(hdev);
  452. if (retval) {
  453. hid_err(hdev, "parse failed\n");
  454. goto exit;
  455. }
  456. retval = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
  457. if (retval) {
  458. hid_err(hdev, "hw start failed\n");
  459. goto exit;
  460. }
  461. retval = kovaplus_init_specials(hdev);
  462. if (retval) {
  463. hid_err(hdev, "couldn't install mouse\n");
  464. goto exit_stop;
  465. }
  466. return 0;
  467. exit_stop:
  468. hid_hw_stop(hdev);
  469. exit:
  470. return retval;
  471. }
  472. static void kovaplus_remove(struct hid_device *hdev)
  473. {
  474. kovaplus_remove_specials(hdev);
  475. hid_hw_stop(hdev);
  476. }
  477. static void kovaplus_keep_values_up_to_date(struct kovaplus_device *kovaplus,
  478. u8 const *data)
  479. {
  480. struct kovaplus_mouse_report_button const *button_report;
  481. if (data[0] != KOVAPLUS_MOUSE_REPORT_NUMBER_BUTTON)
  482. return;
  483. button_report = (struct kovaplus_mouse_report_button const *)data;
  484. switch (button_report->type) {
  485. case KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_PROFILE_1:
  486. kovaplus_profile_activated(kovaplus, button_report->data1 - 1);
  487. break;
  488. case KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_CPI:
  489. kovaplus->actual_cpi = kovaplus_convert_event_cpi(button_report->data1);
  490. case KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_SENSITIVITY:
  491. kovaplus->actual_x_sensitivity = button_report->data1;
  492. kovaplus->actual_y_sensitivity = button_report->data2;
  493. }
  494. }
  495. static void kovaplus_report_to_chrdev(struct kovaplus_device const *kovaplus,
  496. u8 const *data)
  497. {
  498. struct kovaplus_roccat_report roccat_report;
  499. struct kovaplus_mouse_report_button const *button_report;
  500. if (data[0] != KOVAPLUS_MOUSE_REPORT_NUMBER_BUTTON)
  501. return;
  502. button_report = (struct kovaplus_mouse_report_button const *)data;
  503. if (button_report->type == KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_PROFILE_2)
  504. return;
  505. roccat_report.type = button_report->type;
  506. roccat_report.profile = kovaplus->actual_profile + 1;
  507. if (roccat_report.type == KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_MACRO ||
  508. roccat_report.type == KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_SHORTCUT ||
  509. roccat_report.type == KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_QUICKLAUNCH ||
  510. roccat_report.type == KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_TIMER)
  511. roccat_report.button = button_report->data1;
  512. else
  513. roccat_report.button = 0;
  514. if (roccat_report.type == KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_CPI)
  515. roccat_report.data1 = kovaplus_convert_event_cpi(button_report->data1);
  516. else
  517. roccat_report.data1 = button_report->data1;
  518. roccat_report.data2 = button_report->data2;
  519. roccat_report_event(kovaplus->chrdev_minor,
  520. (uint8_t const *)&roccat_report);
  521. }
  522. static int kovaplus_raw_event(struct hid_device *hdev,
  523. struct hid_report *report, u8 *data, int size)
  524. {
  525. struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
  526. struct kovaplus_device *kovaplus = hid_get_drvdata(hdev);
  527. if (intf->cur_altsetting->desc.bInterfaceProtocol
  528. != USB_INTERFACE_PROTOCOL_MOUSE)
  529. return 0;
  530. if (kovaplus == NULL)
  531. return 0;
  532. kovaplus_keep_values_up_to_date(kovaplus, data);
  533. if (kovaplus->roccat_claimed)
  534. kovaplus_report_to_chrdev(kovaplus, data);
  535. return 0;
  536. }
  537. static const struct hid_device_id kovaplus_devices[] = {
  538. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KOVAPLUS) },
  539. { }
  540. };
  541. MODULE_DEVICE_TABLE(hid, kovaplus_devices);
  542. static struct hid_driver kovaplus_driver = {
  543. .name = "kovaplus",
  544. .id_table = kovaplus_devices,
  545. .probe = kovaplus_probe,
  546. .remove = kovaplus_remove,
  547. .raw_event = kovaplus_raw_event
  548. };
  549. static int __init kovaplus_init(void)
  550. {
  551. int retval;
  552. kovaplus_class = class_create(THIS_MODULE, "kovaplus");
  553. if (IS_ERR(kovaplus_class))
  554. return PTR_ERR(kovaplus_class);
  555. kovaplus_class->dev_attrs = kovaplus_attributes;
  556. kovaplus_class->dev_bin_attrs = kovaplus_bin_attributes;
  557. retval = hid_register_driver(&kovaplus_driver);
  558. if (retval)
  559. class_destroy(kovaplus_class);
  560. return retval;
  561. }
  562. static void __exit kovaplus_exit(void)
  563. {
  564. hid_unregister_driver(&kovaplus_driver);
  565. class_destroy(kovaplus_class);
  566. }
  567. module_init(kovaplus_init);
  568. module_exit(kovaplus_exit);
  569. MODULE_AUTHOR("Stefan Achatz");
  570. MODULE_DESCRIPTION("USB Roccat Kova[+] driver");
  571. MODULE_LICENSE("GPL v2");