hid-roccat-kovaplus.c 18 KB

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