hid-roccat-pyra.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. /*
  2. * Roccat Pyra driver for Linux
  3. *
  4. * Copyright (c) 2010 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 Pyra is a mobile gamer mouse which comes in wired and wireless
  14. * variant. Wireless variant is not tested.
  15. * Userland tools can be found at http://sourceforge.net/projects/roccat
  16. */
  17. #include <linux/device.h>
  18. #include <linux/input.h>
  19. #include <linux/hid.h>
  20. #include <linux/module.h>
  21. #include <linux/slab.h>
  22. #include <linux/hid-roccat.h>
  23. #include "hid-ids.h"
  24. #include "hid-roccat-common.h"
  25. #include "hid-roccat-pyra.h"
  26. static uint profile_numbers[5] = {0, 1, 2, 3, 4};
  27. /* pyra_class is used for creating sysfs attributes via roccat char device */
  28. static struct class *pyra_class;
  29. static void profile_activated(struct pyra_device *pyra,
  30. unsigned int new_profile)
  31. {
  32. pyra->actual_profile = new_profile;
  33. pyra->actual_cpi = pyra->profile_settings[pyra->actual_profile].y_cpi;
  34. }
  35. static int pyra_send_control(struct usb_device *usb_dev, int value,
  36. enum pyra_control_requests request)
  37. {
  38. struct pyra_control control;
  39. if ((request == PYRA_CONTROL_REQUEST_PROFILE_SETTINGS ||
  40. request == PYRA_CONTROL_REQUEST_PROFILE_BUTTONS) &&
  41. (value < 0 || value > 4))
  42. return -EINVAL;
  43. control.command = PYRA_COMMAND_CONTROL;
  44. control.value = value;
  45. control.request = request;
  46. return roccat_common_send(usb_dev, PYRA_USB_COMMAND_CONTROL,
  47. &control, sizeof(struct pyra_control));
  48. }
  49. static int pyra_receive_control_status(struct usb_device *usb_dev)
  50. {
  51. int retval;
  52. struct pyra_control control;
  53. do {
  54. msleep(10);
  55. retval = roccat_common_receive(usb_dev, PYRA_USB_COMMAND_CONTROL,
  56. &control, sizeof(struct pyra_control));
  57. /* requested too early, try again */
  58. } while (retval == -EPROTO);
  59. if (!retval && control.command == PYRA_COMMAND_CONTROL &&
  60. control.request == PYRA_CONTROL_REQUEST_STATUS &&
  61. control.value == 1)
  62. return 0;
  63. else {
  64. hid_err(usb_dev, "receive control status: unknown response 0x%x 0x%x\n",
  65. control.request, control.value);
  66. return retval ? retval : -EINVAL;
  67. }
  68. }
  69. static int pyra_get_profile_settings(struct usb_device *usb_dev,
  70. struct pyra_profile_settings *buf, int number)
  71. {
  72. int retval;
  73. retval = pyra_send_control(usb_dev, number,
  74. PYRA_CONTROL_REQUEST_PROFILE_SETTINGS);
  75. if (retval)
  76. return retval;
  77. return roccat_common_receive(usb_dev, PYRA_USB_COMMAND_PROFILE_SETTINGS,
  78. buf, sizeof(struct pyra_profile_settings));
  79. }
  80. static int pyra_get_profile_buttons(struct usb_device *usb_dev,
  81. struct pyra_profile_buttons *buf, int number)
  82. {
  83. int retval;
  84. retval = pyra_send_control(usb_dev, number,
  85. PYRA_CONTROL_REQUEST_PROFILE_BUTTONS);
  86. if (retval)
  87. return retval;
  88. return roccat_common_receive(usb_dev, PYRA_USB_COMMAND_PROFILE_BUTTONS,
  89. buf, sizeof(struct pyra_profile_buttons));
  90. }
  91. static int pyra_get_settings(struct usb_device *usb_dev,
  92. struct pyra_settings *buf)
  93. {
  94. return roccat_common_receive(usb_dev, PYRA_USB_COMMAND_SETTINGS,
  95. buf, sizeof(struct pyra_settings));
  96. }
  97. static int pyra_get_info(struct usb_device *usb_dev, struct pyra_info *buf)
  98. {
  99. return roccat_common_receive(usb_dev, PYRA_USB_COMMAND_INFO,
  100. buf, sizeof(struct pyra_info));
  101. }
  102. static int pyra_send(struct usb_device *usb_dev, uint command,
  103. void const *buf, uint size)
  104. {
  105. int retval;
  106. retval = roccat_common_send(usb_dev, command, buf, size);
  107. if (retval)
  108. return retval;
  109. return pyra_receive_control_status(usb_dev);
  110. }
  111. static int pyra_set_profile_settings(struct usb_device *usb_dev,
  112. struct pyra_profile_settings const *settings)
  113. {
  114. return pyra_send(usb_dev, PYRA_USB_COMMAND_PROFILE_SETTINGS, settings,
  115. sizeof(struct pyra_profile_settings));
  116. }
  117. static int pyra_set_profile_buttons(struct usb_device *usb_dev,
  118. struct pyra_profile_buttons const *buttons)
  119. {
  120. return pyra_send(usb_dev, PYRA_USB_COMMAND_PROFILE_BUTTONS, buttons,
  121. sizeof(struct pyra_profile_buttons));
  122. }
  123. static int pyra_set_settings(struct usb_device *usb_dev,
  124. struct pyra_settings const *settings)
  125. {
  126. int retval;
  127. retval = roccat_common_send(usb_dev, PYRA_USB_COMMAND_SETTINGS, settings,
  128. sizeof(struct pyra_settings));
  129. if (retval)
  130. return retval;
  131. return pyra_receive_control_status(usb_dev);
  132. }
  133. static ssize_t pyra_sysfs_read_profilex_settings(struct file *fp,
  134. struct kobject *kobj, struct bin_attribute *attr, char *buf,
  135. loff_t off, size_t count)
  136. {
  137. struct device *dev =
  138. container_of(kobj, struct device, kobj)->parent->parent;
  139. struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev));
  140. if (off >= sizeof(struct pyra_profile_settings))
  141. return 0;
  142. if (off + count > sizeof(struct pyra_profile_settings))
  143. count = sizeof(struct pyra_profile_settings) - off;
  144. mutex_lock(&pyra->pyra_lock);
  145. memcpy(buf, ((char const *)&pyra->profile_settings[*(uint *)(attr->private)]) + off,
  146. count);
  147. mutex_unlock(&pyra->pyra_lock);
  148. return count;
  149. }
  150. static ssize_t pyra_sysfs_read_profilex_buttons(struct file *fp,
  151. struct kobject *kobj, struct bin_attribute *attr, char *buf,
  152. loff_t off, size_t count)
  153. {
  154. struct device *dev =
  155. container_of(kobj, struct device, kobj)->parent->parent;
  156. struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev));
  157. if (off >= sizeof(struct pyra_profile_buttons))
  158. return 0;
  159. if (off + count > sizeof(struct pyra_profile_buttons))
  160. count = sizeof(struct pyra_profile_buttons) - off;
  161. mutex_lock(&pyra->pyra_lock);
  162. memcpy(buf, ((char const *)&pyra->profile_buttons[*(uint *)(attr->private)]) + off,
  163. count);
  164. mutex_unlock(&pyra->pyra_lock);
  165. return count;
  166. }
  167. static ssize_t pyra_sysfs_write_profile_settings(struct file *fp,
  168. struct kobject *kobj, struct bin_attribute *attr, char *buf,
  169. loff_t off, size_t count)
  170. {
  171. struct device *dev =
  172. container_of(kobj, struct device, kobj)->parent->parent;
  173. struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev));
  174. struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
  175. int retval = 0;
  176. int difference;
  177. int profile_number;
  178. struct pyra_profile_settings *profile_settings;
  179. if (off != 0 || count != sizeof(struct pyra_profile_settings))
  180. return -EINVAL;
  181. profile_number = ((struct pyra_profile_settings const *)buf)->number;
  182. profile_settings = &pyra->profile_settings[profile_number];
  183. mutex_lock(&pyra->pyra_lock);
  184. difference = memcmp(buf, profile_settings,
  185. sizeof(struct pyra_profile_settings));
  186. if (difference) {
  187. retval = pyra_set_profile_settings(usb_dev,
  188. (struct pyra_profile_settings const *)buf);
  189. if (!retval)
  190. memcpy(profile_settings, buf,
  191. sizeof(struct pyra_profile_settings));
  192. }
  193. mutex_unlock(&pyra->pyra_lock);
  194. if (retval)
  195. return retval;
  196. return sizeof(struct pyra_profile_settings);
  197. }
  198. static ssize_t pyra_sysfs_write_profile_buttons(struct file *fp,
  199. struct kobject *kobj, struct bin_attribute *attr, char *buf,
  200. loff_t off, size_t count)
  201. {
  202. struct device *dev =
  203. container_of(kobj, struct device, kobj)->parent->parent;
  204. struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev));
  205. struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
  206. int retval = 0;
  207. int difference;
  208. int profile_number;
  209. struct pyra_profile_buttons *profile_buttons;
  210. if (off != 0 || count != sizeof(struct pyra_profile_buttons))
  211. return -EINVAL;
  212. profile_number = ((struct pyra_profile_buttons const *)buf)->number;
  213. profile_buttons = &pyra->profile_buttons[profile_number];
  214. mutex_lock(&pyra->pyra_lock);
  215. difference = memcmp(buf, profile_buttons,
  216. sizeof(struct pyra_profile_buttons));
  217. if (difference) {
  218. retval = pyra_set_profile_buttons(usb_dev,
  219. (struct pyra_profile_buttons const *)buf);
  220. if (!retval)
  221. memcpy(profile_buttons, buf,
  222. sizeof(struct pyra_profile_buttons));
  223. }
  224. mutex_unlock(&pyra->pyra_lock);
  225. if (retval)
  226. return retval;
  227. return sizeof(struct pyra_profile_buttons);
  228. }
  229. static ssize_t pyra_sysfs_read_settings(struct file *fp,
  230. struct kobject *kobj, struct bin_attribute *attr, char *buf,
  231. loff_t off, size_t count)
  232. {
  233. struct device *dev =
  234. container_of(kobj, struct device, kobj)->parent->parent;
  235. struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev));
  236. if (off >= sizeof(struct pyra_settings))
  237. return 0;
  238. if (off + count > sizeof(struct pyra_settings))
  239. count = sizeof(struct pyra_settings) - off;
  240. mutex_lock(&pyra->pyra_lock);
  241. memcpy(buf, ((char const *)&pyra->settings) + off, count);
  242. mutex_unlock(&pyra->pyra_lock);
  243. return count;
  244. }
  245. static ssize_t pyra_sysfs_write_settings(struct file *fp,
  246. struct kobject *kobj, struct bin_attribute *attr, char *buf,
  247. loff_t off, size_t count)
  248. {
  249. struct device *dev =
  250. container_of(kobj, struct device, kobj)->parent->parent;
  251. struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev));
  252. struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
  253. int retval = 0;
  254. int difference;
  255. if (off != 0 || count != sizeof(struct pyra_settings))
  256. return -EINVAL;
  257. mutex_lock(&pyra->pyra_lock);
  258. difference = memcmp(buf, &pyra->settings, sizeof(struct pyra_settings));
  259. if (difference) {
  260. retval = pyra_set_settings(usb_dev,
  261. (struct pyra_settings const *)buf);
  262. if (!retval)
  263. memcpy(&pyra->settings, buf,
  264. sizeof(struct pyra_settings));
  265. }
  266. mutex_unlock(&pyra->pyra_lock);
  267. if (retval)
  268. return retval;
  269. profile_activated(pyra, pyra->settings.startup_profile);
  270. return sizeof(struct pyra_settings);
  271. }
  272. static ssize_t pyra_sysfs_show_actual_cpi(struct device *dev,
  273. struct device_attribute *attr, char *buf)
  274. {
  275. struct pyra_device *pyra =
  276. hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
  277. return snprintf(buf, PAGE_SIZE, "%d\n", pyra->actual_cpi);
  278. }
  279. static ssize_t pyra_sysfs_show_actual_profile(struct device *dev,
  280. struct device_attribute *attr, char *buf)
  281. {
  282. struct pyra_device *pyra =
  283. hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
  284. return snprintf(buf, PAGE_SIZE, "%d\n", pyra->actual_profile);
  285. }
  286. static ssize_t pyra_sysfs_show_firmware_version(struct device *dev,
  287. struct device_attribute *attr, char *buf)
  288. {
  289. struct pyra_device *pyra =
  290. hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
  291. return snprintf(buf, PAGE_SIZE, "%d\n", pyra->firmware_version);
  292. }
  293. static ssize_t pyra_sysfs_show_startup_profile(struct device *dev,
  294. struct device_attribute *attr, char *buf)
  295. {
  296. struct pyra_device *pyra =
  297. hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
  298. return snprintf(buf, PAGE_SIZE, "%d\n", pyra->settings.startup_profile);
  299. }
  300. static struct device_attribute pyra_attributes[] = {
  301. __ATTR(actual_cpi, 0440, pyra_sysfs_show_actual_cpi, NULL),
  302. __ATTR(actual_profile, 0440, pyra_sysfs_show_actual_profile, NULL),
  303. __ATTR(firmware_version, 0440,
  304. pyra_sysfs_show_firmware_version, NULL),
  305. __ATTR(startup_profile, 0440,
  306. pyra_sysfs_show_startup_profile, NULL),
  307. __ATTR_NULL
  308. };
  309. static struct bin_attribute pyra_bin_attributes[] = {
  310. {
  311. .attr = { .name = "profile_settings", .mode = 0220 },
  312. .size = sizeof(struct pyra_profile_settings),
  313. .write = pyra_sysfs_write_profile_settings
  314. },
  315. {
  316. .attr = { .name = "profile1_settings", .mode = 0440 },
  317. .size = sizeof(struct pyra_profile_settings),
  318. .read = pyra_sysfs_read_profilex_settings,
  319. .private = &profile_numbers[0]
  320. },
  321. {
  322. .attr = { .name = "profile2_settings", .mode = 0440 },
  323. .size = sizeof(struct pyra_profile_settings),
  324. .read = pyra_sysfs_read_profilex_settings,
  325. .private = &profile_numbers[1]
  326. },
  327. {
  328. .attr = { .name = "profile3_settings", .mode = 0440 },
  329. .size = sizeof(struct pyra_profile_settings),
  330. .read = pyra_sysfs_read_profilex_settings,
  331. .private = &profile_numbers[2]
  332. },
  333. {
  334. .attr = { .name = "profile4_settings", .mode = 0440 },
  335. .size = sizeof(struct pyra_profile_settings),
  336. .read = pyra_sysfs_read_profilex_settings,
  337. .private = &profile_numbers[3]
  338. },
  339. {
  340. .attr = { .name = "profile5_settings", .mode = 0440 },
  341. .size = sizeof(struct pyra_profile_settings),
  342. .read = pyra_sysfs_read_profilex_settings,
  343. .private = &profile_numbers[4]
  344. },
  345. {
  346. .attr = { .name = "profile_buttons", .mode = 0220 },
  347. .size = sizeof(struct pyra_profile_buttons),
  348. .write = pyra_sysfs_write_profile_buttons
  349. },
  350. {
  351. .attr = { .name = "profile1_buttons", .mode = 0440 },
  352. .size = sizeof(struct pyra_profile_buttons),
  353. .read = pyra_sysfs_read_profilex_buttons,
  354. .private = &profile_numbers[0]
  355. },
  356. {
  357. .attr = { .name = "profile2_buttons", .mode = 0440 },
  358. .size = sizeof(struct pyra_profile_buttons),
  359. .read = pyra_sysfs_read_profilex_buttons,
  360. .private = &profile_numbers[1]
  361. },
  362. {
  363. .attr = { .name = "profile3_buttons", .mode = 0440 },
  364. .size = sizeof(struct pyra_profile_buttons),
  365. .read = pyra_sysfs_read_profilex_buttons,
  366. .private = &profile_numbers[2]
  367. },
  368. {
  369. .attr = { .name = "profile4_buttons", .mode = 0440 },
  370. .size = sizeof(struct pyra_profile_buttons),
  371. .read = pyra_sysfs_read_profilex_buttons,
  372. .private = &profile_numbers[3]
  373. },
  374. {
  375. .attr = { .name = "profile5_buttons", .mode = 0440 },
  376. .size = sizeof(struct pyra_profile_buttons),
  377. .read = pyra_sysfs_read_profilex_buttons,
  378. .private = &profile_numbers[4]
  379. },
  380. {
  381. .attr = { .name = "settings", .mode = 0660 },
  382. .size = sizeof(struct pyra_settings),
  383. .read = pyra_sysfs_read_settings,
  384. .write = pyra_sysfs_write_settings
  385. },
  386. __ATTR_NULL
  387. };
  388. static int pyra_init_pyra_device_struct(struct usb_device *usb_dev,
  389. struct pyra_device *pyra)
  390. {
  391. struct pyra_info info;
  392. int retval, i;
  393. mutex_init(&pyra->pyra_lock);
  394. retval = pyra_get_info(usb_dev, &info);
  395. if (retval)
  396. return retval;
  397. pyra->firmware_version = info.firmware_version;
  398. retval = pyra_get_settings(usb_dev, &pyra->settings);
  399. if (retval)
  400. return retval;
  401. for (i = 0; i < 5; ++i) {
  402. retval = pyra_get_profile_settings(usb_dev,
  403. &pyra->profile_settings[i], i);
  404. if (retval)
  405. return retval;
  406. retval = pyra_get_profile_buttons(usb_dev,
  407. &pyra->profile_buttons[i], i);
  408. if (retval)
  409. return retval;
  410. }
  411. profile_activated(pyra, pyra->settings.startup_profile);
  412. return 0;
  413. }
  414. static int pyra_init_specials(struct hid_device *hdev)
  415. {
  416. struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
  417. struct usb_device *usb_dev = interface_to_usbdev(intf);
  418. struct pyra_device *pyra;
  419. int retval;
  420. if (intf->cur_altsetting->desc.bInterfaceProtocol
  421. == USB_INTERFACE_PROTOCOL_MOUSE) {
  422. pyra = kzalloc(sizeof(*pyra), GFP_KERNEL);
  423. if (!pyra) {
  424. hid_err(hdev, "can't alloc device descriptor\n");
  425. return -ENOMEM;
  426. }
  427. hid_set_drvdata(hdev, pyra);
  428. retval = pyra_init_pyra_device_struct(usb_dev, pyra);
  429. if (retval) {
  430. hid_err(hdev, "couldn't init struct pyra_device\n");
  431. goto exit_free;
  432. }
  433. retval = roccat_connect(pyra_class, hdev,
  434. sizeof(struct pyra_roccat_report));
  435. if (retval < 0) {
  436. hid_err(hdev, "couldn't init char dev\n");
  437. } else {
  438. pyra->chrdev_minor = retval;
  439. pyra->roccat_claimed = 1;
  440. }
  441. } else {
  442. hid_set_drvdata(hdev, NULL);
  443. }
  444. return 0;
  445. exit_free:
  446. kfree(pyra);
  447. return retval;
  448. }
  449. static void pyra_remove_specials(struct hid_device *hdev)
  450. {
  451. struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
  452. struct pyra_device *pyra;
  453. if (intf->cur_altsetting->desc.bInterfaceProtocol
  454. == USB_INTERFACE_PROTOCOL_MOUSE) {
  455. pyra = hid_get_drvdata(hdev);
  456. if (pyra->roccat_claimed)
  457. roccat_disconnect(pyra->chrdev_minor);
  458. kfree(hid_get_drvdata(hdev));
  459. }
  460. }
  461. static int pyra_probe(struct hid_device *hdev, const struct hid_device_id *id)
  462. {
  463. int retval;
  464. retval = hid_parse(hdev);
  465. if (retval) {
  466. hid_err(hdev, "parse failed\n");
  467. goto exit;
  468. }
  469. retval = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
  470. if (retval) {
  471. hid_err(hdev, "hw start failed\n");
  472. goto exit;
  473. }
  474. retval = pyra_init_specials(hdev);
  475. if (retval) {
  476. hid_err(hdev, "couldn't install mouse\n");
  477. goto exit_stop;
  478. }
  479. return 0;
  480. exit_stop:
  481. hid_hw_stop(hdev);
  482. exit:
  483. return retval;
  484. }
  485. static void pyra_remove(struct hid_device *hdev)
  486. {
  487. pyra_remove_specials(hdev);
  488. hid_hw_stop(hdev);
  489. }
  490. static void pyra_keep_values_up_to_date(struct pyra_device *pyra,
  491. u8 const *data)
  492. {
  493. struct pyra_mouse_event_button const *button_event;
  494. switch (data[0]) {
  495. case PYRA_MOUSE_REPORT_NUMBER_BUTTON:
  496. button_event = (struct pyra_mouse_event_button const *)data;
  497. switch (button_event->type) {
  498. case PYRA_MOUSE_EVENT_BUTTON_TYPE_PROFILE_2:
  499. profile_activated(pyra, button_event->data1 - 1);
  500. break;
  501. case PYRA_MOUSE_EVENT_BUTTON_TYPE_CPI:
  502. pyra->actual_cpi = button_event->data1;
  503. break;
  504. }
  505. break;
  506. }
  507. }
  508. static void pyra_report_to_chrdev(struct pyra_device const *pyra,
  509. u8 const *data)
  510. {
  511. struct pyra_roccat_report roccat_report;
  512. struct pyra_mouse_event_button const *button_event;
  513. if (data[0] != PYRA_MOUSE_REPORT_NUMBER_BUTTON)
  514. return;
  515. button_event = (struct pyra_mouse_event_button const *)data;
  516. switch (button_event->type) {
  517. case PYRA_MOUSE_EVENT_BUTTON_TYPE_PROFILE_2:
  518. case PYRA_MOUSE_EVENT_BUTTON_TYPE_CPI:
  519. roccat_report.type = button_event->type;
  520. roccat_report.value = button_event->data1;
  521. roccat_report.key = 0;
  522. roccat_report_event(pyra->chrdev_minor,
  523. (uint8_t const *)&roccat_report);
  524. break;
  525. case PYRA_MOUSE_EVENT_BUTTON_TYPE_MACRO:
  526. case PYRA_MOUSE_EVENT_BUTTON_TYPE_SHORTCUT:
  527. case PYRA_MOUSE_EVENT_BUTTON_TYPE_QUICKLAUNCH:
  528. if (button_event->data2 == PYRA_MOUSE_EVENT_BUTTON_PRESS) {
  529. roccat_report.type = button_event->type;
  530. roccat_report.key = button_event->data1;
  531. /*
  532. * pyra reports profile numbers with range 1-5.
  533. * Keeping this behaviour.
  534. */
  535. roccat_report.value = pyra->actual_profile + 1;
  536. roccat_report_event(pyra->chrdev_minor,
  537. (uint8_t const *)&roccat_report);
  538. }
  539. break;
  540. }
  541. }
  542. static int pyra_raw_event(struct hid_device *hdev, struct hid_report *report,
  543. u8 *data, int size)
  544. {
  545. struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
  546. struct pyra_device *pyra = hid_get_drvdata(hdev);
  547. if (intf->cur_altsetting->desc.bInterfaceProtocol
  548. != USB_INTERFACE_PROTOCOL_MOUSE)
  549. return 0;
  550. pyra_keep_values_up_to_date(pyra, data);
  551. if (pyra->roccat_claimed)
  552. pyra_report_to_chrdev(pyra, data);
  553. return 0;
  554. }
  555. static const struct hid_device_id pyra_devices[] = {
  556. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT,
  557. USB_DEVICE_ID_ROCCAT_PYRA_WIRED) },
  558. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT,
  559. USB_DEVICE_ID_ROCCAT_PYRA_WIRELESS) },
  560. { }
  561. };
  562. MODULE_DEVICE_TABLE(hid, pyra_devices);
  563. static struct hid_driver pyra_driver = {
  564. .name = "pyra",
  565. .id_table = pyra_devices,
  566. .probe = pyra_probe,
  567. .remove = pyra_remove,
  568. .raw_event = pyra_raw_event
  569. };
  570. static int __init pyra_init(void)
  571. {
  572. int retval;
  573. /* class name has to be same as driver name */
  574. pyra_class = class_create(THIS_MODULE, "pyra");
  575. if (IS_ERR(pyra_class))
  576. return PTR_ERR(pyra_class);
  577. pyra_class->dev_attrs = pyra_attributes;
  578. pyra_class->dev_bin_attrs = pyra_bin_attributes;
  579. retval = hid_register_driver(&pyra_driver);
  580. if (retval)
  581. class_destroy(pyra_class);
  582. return retval;
  583. }
  584. static void __exit pyra_exit(void)
  585. {
  586. hid_unregister_driver(&pyra_driver);
  587. class_destroy(pyra_class);
  588. }
  589. module_init(pyra_init);
  590. module_exit(pyra_exit);
  591. MODULE_AUTHOR("Stefan Achatz");
  592. MODULE_DESCRIPTION("USB Roccat Pyra driver");
  593. MODULE_LICENSE("GPL v2");