hid-roccat-kovaplus.c 18 KB

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