hid-roccat-kovaplus.c 18 KB

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