hid-roccat-pyra.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  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_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_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_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_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_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_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_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_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. return pyra_send(usb_dev, PYRA_COMMAND_SETTINGS, settings,
  127. sizeof(struct pyra_settings));
  128. }
  129. static ssize_t pyra_sysfs_read_profilex_settings(struct file *fp,
  130. struct kobject *kobj, struct bin_attribute *attr, char *buf,
  131. loff_t off, size_t count)
  132. {
  133. struct device *dev =
  134. container_of(kobj, struct device, kobj)->parent->parent;
  135. struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev));
  136. if (off >= sizeof(struct pyra_profile_settings))
  137. return 0;
  138. if (off + count > sizeof(struct pyra_profile_settings))
  139. count = sizeof(struct pyra_profile_settings) - off;
  140. mutex_lock(&pyra->pyra_lock);
  141. memcpy(buf, ((char const *)&pyra->profile_settings[*(uint *)(attr->private)]) + off,
  142. count);
  143. mutex_unlock(&pyra->pyra_lock);
  144. return count;
  145. }
  146. static ssize_t pyra_sysfs_read_profilex_buttons(struct file *fp,
  147. struct kobject *kobj, struct bin_attribute *attr, char *buf,
  148. loff_t off, size_t count)
  149. {
  150. struct device *dev =
  151. container_of(kobj, struct device, kobj)->parent->parent;
  152. struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev));
  153. if (off >= sizeof(struct pyra_profile_buttons))
  154. return 0;
  155. if (off + count > sizeof(struct pyra_profile_buttons))
  156. count = sizeof(struct pyra_profile_buttons) - off;
  157. mutex_lock(&pyra->pyra_lock);
  158. memcpy(buf, ((char const *)&pyra->profile_buttons[*(uint *)(attr->private)]) + off,
  159. count);
  160. mutex_unlock(&pyra->pyra_lock);
  161. return count;
  162. }
  163. static ssize_t pyra_sysfs_write_profile_settings(struct file *fp,
  164. struct kobject *kobj, struct bin_attribute *attr, char *buf,
  165. loff_t off, size_t count)
  166. {
  167. struct device *dev =
  168. container_of(kobj, struct device, kobj)->parent->parent;
  169. struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev));
  170. struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
  171. int retval = 0;
  172. int difference;
  173. int profile_number;
  174. struct pyra_profile_settings *profile_settings;
  175. if (off != 0 || count != sizeof(struct pyra_profile_settings))
  176. return -EINVAL;
  177. profile_number = ((struct pyra_profile_settings const *)buf)->number;
  178. profile_settings = &pyra->profile_settings[profile_number];
  179. mutex_lock(&pyra->pyra_lock);
  180. difference = memcmp(buf, profile_settings,
  181. sizeof(struct pyra_profile_settings));
  182. if (difference) {
  183. retval = pyra_set_profile_settings(usb_dev,
  184. (struct pyra_profile_settings const *)buf);
  185. if (!retval)
  186. memcpy(profile_settings, buf,
  187. sizeof(struct pyra_profile_settings));
  188. }
  189. mutex_unlock(&pyra->pyra_lock);
  190. if (retval)
  191. return retval;
  192. return sizeof(struct pyra_profile_settings);
  193. }
  194. static ssize_t pyra_sysfs_write_profile_buttons(struct file *fp,
  195. struct kobject *kobj, struct bin_attribute *attr, char *buf,
  196. loff_t off, size_t count)
  197. {
  198. struct device *dev =
  199. container_of(kobj, struct device, kobj)->parent->parent;
  200. struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev));
  201. struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
  202. int retval = 0;
  203. int difference;
  204. int profile_number;
  205. struct pyra_profile_buttons *profile_buttons;
  206. if (off != 0 || count != sizeof(struct pyra_profile_buttons))
  207. return -EINVAL;
  208. profile_number = ((struct pyra_profile_buttons const *)buf)->number;
  209. profile_buttons = &pyra->profile_buttons[profile_number];
  210. mutex_lock(&pyra->pyra_lock);
  211. difference = memcmp(buf, profile_buttons,
  212. sizeof(struct pyra_profile_buttons));
  213. if (difference) {
  214. retval = pyra_set_profile_buttons(usb_dev,
  215. (struct pyra_profile_buttons const *)buf);
  216. if (!retval)
  217. memcpy(profile_buttons, buf,
  218. sizeof(struct pyra_profile_buttons));
  219. }
  220. mutex_unlock(&pyra->pyra_lock);
  221. if (retval)
  222. return retval;
  223. return sizeof(struct pyra_profile_buttons);
  224. }
  225. static ssize_t pyra_sysfs_read_settings(struct file *fp,
  226. struct kobject *kobj, struct bin_attribute *attr, char *buf,
  227. loff_t off, size_t count)
  228. {
  229. struct device *dev =
  230. container_of(kobj, struct device, kobj)->parent->parent;
  231. struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev));
  232. if (off >= sizeof(struct pyra_settings))
  233. return 0;
  234. if (off + count > sizeof(struct pyra_settings))
  235. count = sizeof(struct pyra_settings) - off;
  236. mutex_lock(&pyra->pyra_lock);
  237. memcpy(buf, ((char const *)&pyra->settings) + off, count);
  238. mutex_unlock(&pyra->pyra_lock);
  239. return count;
  240. }
  241. static ssize_t pyra_sysfs_write_settings(struct file *fp,
  242. struct kobject *kobj, struct bin_attribute *attr, char *buf,
  243. loff_t off, size_t count)
  244. {
  245. struct device *dev =
  246. container_of(kobj, struct device, kobj)->parent->parent;
  247. struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev));
  248. struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
  249. int retval = 0;
  250. int difference;
  251. if (off != 0 || count != sizeof(struct pyra_settings))
  252. return -EINVAL;
  253. mutex_lock(&pyra->pyra_lock);
  254. difference = memcmp(buf, &pyra->settings, sizeof(struct pyra_settings));
  255. if (difference) {
  256. retval = pyra_set_settings(usb_dev,
  257. (struct pyra_settings const *)buf);
  258. if (!retval)
  259. memcpy(&pyra->settings, buf,
  260. sizeof(struct pyra_settings));
  261. }
  262. mutex_unlock(&pyra->pyra_lock);
  263. if (retval)
  264. return retval;
  265. profile_activated(pyra, pyra->settings.startup_profile);
  266. return sizeof(struct pyra_settings);
  267. }
  268. static ssize_t pyra_sysfs_show_actual_cpi(struct device *dev,
  269. struct device_attribute *attr, char *buf)
  270. {
  271. struct pyra_device *pyra =
  272. hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
  273. return snprintf(buf, PAGE_SIZE, "%d\n", pyra->actual_cpi);
  274. }
  275. static ssize_t pyra_sysfs_show_actual_profile(struct device *dev,
  276. struct device_attribute *attr, char *buf)
  277. {
  278. struct pyra_device *pyra =
  279. hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
  280. return snprintf(buf, PAGE_SIZE, "%d\n", pyra->actual_profile);
  281. }
  282. static ssize_t pyra_sysfs_show_firmware_version(struct device *dev,
  283. struct device_attribute *attr, char *buf)
  284. {
  285. struct pyra_device *pyra =
  286. hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
  287. return snprintf(buf, PAGE_SIZE, "%d\n", pyra->firmware_version);
  288. }
  289. static ssize_t pyra_sysfs_show_startup_profile(struct device *dev,
  290. struct device_attribute *attr, char *buf)
  291. {
  292. struct pyra_device *pyra =
  293. hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
  294. return snprintf(buf, PAGE_SIZE, "%d\n", pyra->settings.startup_profile);
  295. }
  296. static struct device_attribute pyra_attributes[] = {
  297. __ATTR(actual_cpi, 0440, pyra_sysfs_show_actual_cpi, NULL),
  298. __ATTR(actual_profile, 0440, pyra_sysfs_show_actual_profile, NULL),
  299. __ATTR(firmware_version, 0440,
  300. pyra_sysfs_show_firmware_version, NULL),
  301. __ATTR(startup_profile, 0440,
  302. pyra_sysfs_show_startup_profile, NULL),
  303. __ATTR_NULL
  304. };
  305. static struct bin_attribute pyra_bin_attributes[] = {
  306. {
  307. .attr = { .name = "profile_settings", .mode = 0220 },
  308. .size = sizeof(struct pyra_profile_settings),
  309. .write = pyra_sysfs_write_profile_settings
  310. },
  311. {
  312. .attr = { .name = "profile1_settings", .mode = 0440 },
  313. .size = sizeof(struct pyra_profile_settings),
  314. .read = pyra_sysfs_read_profilex_settings,
  315. .private = &profile_numbers[0]
  316. },
  317. {
  318. .attr = { .name = "profile2_settings", .mode = 0440 },
  319. .size = sizeof(struct pyra_profile_settings),
  320. .read = pyra_sysfs_read_profilex_settings,
  321. .private = &profile_numbers[1]
  322. },
  323. {
  324. .attr = { .name = "profile3_settings", .mode = 0440 },
  325. .size = sizeof(struct pyra_profile_settings),
  326. .read = pyra_sysfs_read_profilex_settings,
  327. .private = &profile_numbers[2]
  328. },
  329. {
  330. .attr = { .name = "profile4_settings", .mode = 0440 },
  331. .size = sizeof(struct pyra_profile_settings),
  332. .read = pyra_sysfs_read_profilex_settings,
  333. .private = &profile_numbers[3]
  334. },
  335. {
  336. .attr = { .name = "profile5_settings", .mode = 0440 },
  337. .size = sizeof(struct pyra_profile_settings),
  338. .read = pyra_sysfs_read_profilex_settings,
  339. .private = &profile_numbers[4]
  340. },
  341. {
  342. .attr = { .name = "profile_buttons", .mode = 0220 },
  343. .size = sizeof(struct pyra_profile_buttons),
  344. .write = pyra_sysfs_write_profile_buttons
  345. },
  346. {
  347. .attr = { .name = "profile1_buttons", .mode = 0440 },
  348. .size = sizeof(struct pyra_profile_buttons),
  349. .read = pyra_sysfs_read_profilex_buttons,
  350. .private = &profile_numbers[0]
  351. },
  352. {
  353. .attr = { .name = "profile2_buttons", .mode = 0440 },
  354. .size = sizeof(struct pyra_profile_buttons),
  355. .read = pyra_sysfs_read_profilex_buttons,
  356. .private = &profile_numbers[1]
  357. },
  358. {
  359. .attr = { .name = "profile3_buttons", .mode = 0440 },
  360. .size = sizeof(struct pyra_profile_buttons),
  361. .read = pyra_sysfs_read_profilex_buttons,
  362. .private = &profile_numbers[2]
  363. },
  364. {
  365. .attr = { .name = "profile4_buttons", .mode = 0440 },
  366. .size = sizeof(struct pyra_profile_buttons),
  367. .read = pyra_sysfs_read_profilex_buttons,
  368. .private = &profile_numbers[3]
  369. },
  370. {
  371. .attr = { .name = "profile5_buttons", .mode = 0440 },
  372. .size = sizeof(struct pyra_profile_buttons),
  373. .read = pyra_sysfs_read_profilex_buttons,
  374. .private = &profile_numbers[4]
  375. },
  376. {
  377. .attr = { .name = "settings", .mode = 0660 },
  378. .size = sizeof(struct pyra_settings),
  379. .read = pyra_sysfs_read_settings,
  380. .write = pyra_sysfs_write_settings
  381. },
  382. __ATTR_NULL
  383. };
  384. static int pyra_init_pyra_device_struct(struct usb_device *usb_dev,
  385. struct pyra_device *pyra)
  386. {
  387. struct pyra_info info;
  388. int retval, i;
  389. mutex_init(&pyra->pyra_lock);
  390. retval = pyra_get_info(usb_dev, &info);
  391. if (retval)
  392. return retval;
  393. pyra->firmware_version = info.firmware_version;
  394. retval = pyra_get_settings(usb_dev, &pyra->settings);
  395. if (retval)
  396. return retval;
  397. for (i = 0; i < 5; ++i) {
  398. retval = pyra_get_profile_settings(usb_dev,
  399. &pyra->profile_settings[i], i);
  400. if (retval)
  401. return retval;
  402. retval = pyra_get_profile_buttons(usb_dev,
  403. &pyra->profile_buttons[i], i);
  404. if (retval)
  405. return retval;
  406. }
  407. profile_activated(pyra, pyra->settings.startup_profile);
  408. return 0;
  409. }
  410. static int pyra_init_specials(struct hid_device *hdev)
  411. {
  412. struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
  413. struct usb_device *usb_dev = interface_to_usbdev(intf);
  414. struct pyra_device *pyra;
  415. int retval;
  416. if (intf->cur_altsetting->desc.bInterfaceProtocol
  417. == USB_INTERFACE_PROTOCOL_MOUSE) {
  418. pyra = kzalloc(sizeof(*pyra), GFP_KERNEL);
  419. if (!pyra) {
  420. hid_err(hdev, "can't alloc device descriptor\n");
  421. return -ENOMEM;
  422. }
  423. hid_set_drvdata(hdev, pyra);
  424. retval = pyra_init_pyra_device_struct(usb_dev, pyra);
  425. if (retval) {
  426. hid_err(hdev, "couldn't init struct pyra_device\n");
  427. goto exit_free;
  428. }
  429. retval = roccat_connect(pyra_class, hdev,
  430. sizeof(struct pyra_roccat_report));
  431. if (retval < 0) {
  432. hid_err(hdev, "couldn't init char dev\n");
  433. } else {
  434. pyra->chrdev_minor = retval;
  435. pyra->roccat_claimed = 1;
  436. }
  437. } else {
  438. hid_set_drvdata(hdev, NULL);
  439. }
  440. return 0;
  441. exit_free:
  442. kfree(pyra);
  443. return retval;
  444. }
  445. static void pyra_remove_specials(struct hid_device *hdev)
  446. {
  447. struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
  448. struct pyra_device *pyra;
  449. if (intf->cur_altsetting->desc.bInterfaceProtocol
  450. == USB_INTERFACE_PROTOCOL_MOUSE) {
  451. pyra = hid_get_drvdata(hdev);
  452. if (pyra->roccat_claimed)
  453. roccat_disconnect(pyra->chrdev_minor);
  454. kfree(hid_get_drvdata(hdev));
  455. }
  456. }
  457. static int pyra_probe(struct hid_device *hdev, const struct hid_device_id *id)
  458. {
  459. int retval;
  460. retval = hid_parse(hdev);
  461. if (retval) {
  462. hid_err(hdev, "parse failed\n");
  463. goto exit;
  464. }
  465. retval = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
  466. if (retval) {
  467. hid_err(hdev, "hw start failed\n");
  468. goto exit;
  469. }
  470. retval = pyra_init_specials(hdev);
  471. if (retval) {
  472. hid_err(hdev, "couldn't install mouse\n");
  473. goto exit_stop;
  474. }
  475. return 0;
  476. exit_stop:
  477. hid_hw_stop(hdev);
  478. exit:
  479. return retval;
  480. }
  481. static void pyra_remove(struct hid_device *hdev)
  482. {
  483. pyra_remove_specials(hdev);
  484. hid_hw_stop(hdev);
  485. }
  486. static void pyra_keep_values_up_to_date(struct pyra_device *pyra,
  487. u8 const *data)
  488. {
  489. struct pyra_mouse_event_button const *button_event;
  490. switch (data[0]) {
  491. case PYRA_MOUSE_REPORT_NUMBER_BUTTON:
  492. button_event = (struct pyra_mouse_event_button const *)data;
  493. switch (button_event->type) {
  494. case PYRA_MOUSE_EVENT_BUTTON_TYPE_PROFILE_2:
  495. profile_activated(pyra, button_event->data1 - 1);
  496. break;
  497. case PYRA_MOUSE_EVENT_BUTTON_TYPE_CPI:
  498. pyra->actual_cpi = button_event->data1;
  499. break;
  500. }
  501. break;
  502. }
  503. }
  504. static void pyra_report_to_chrdev(struct pyra_device const *pyra,
  505. u8 const *data)
  506. {
  507. struct pyra_roccat_report roccat_report;
  508. struct pyra_mouse_event_button const *button_event;
  509. if (data[0] != PYRA_MOUSE_REPORT_NUMBER_BUTTON)
  510. return;
  511. button_event = (struct pyra_mouse_event_button const *)data;
  512. switch (button_event->type) {
  513. case PYRA_MOUSE_EVENT_BUTTON_TYPE_PROFILE_2:
  514. case PYRA_MOUSE_EVENT_BUTTON_TYPE_CPI:
  515. roccat_report.type = button_event->type;
  516. roccat_report.value = button_event->data1;
  517. roccat_report.key = 0;
  518. roccat_report_event(pyra->chrdev_minor,
  519. (uint8_t const *)&roccat_report);
  520. break;
  521. case PYRA_MOUSE_EVENT_BUTTON_TYPE_MACRO:
  522. case PYRA_MOUSE_EVENT_BUTTON_TYPE_SHORTCUT:
  523. case PYRA_MOUSE_EVENT_BUTTON_TYPE_QUICKLAUNCH:
  524. if (button_event->data2 == PYRA_MOUSE_EVENT_BUTTON_PRESS) {
  525. roccat_report.type = button_event->type;
  526. roccat_report.key = button_event->data1;
  527. /*
  528. * pyra reports profile numbers with range 1-5.
  529. * Keeping this behaviour.
  530. */
  531. roccat_report.value = pyra->actual_profile + 1;
  532. roccat_report_event(pyra->chrdev_minor,
  533. (uint8_t const *)&roccat_report);
  534. }
  535. break;
  536. }
  537. }
  538. static int pyra_raw_event(struct hid_device *hdev, struct hid_report *report,
  539. u8 *data, int size)
  540. {
  541. struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
  542. struct pyra_device *pyra = hid_get_drvdata(hdev);
  543. if (intf->cur_altsetting->desc.bInterfaceProtocol
  544. != USB_INTERFACE_PROTOCOL_MOUSE)
  545. return 0;
  546. if (pyra == NULL)
  547. return 0;
  548. pyra_keep_values_up_to_date(pyra, data);
  549. if (pyra->roccat_claimed)
  550. pyra_report_to_chrdev(pyra, data);
  551. return 0;
  552. }
  553. static const struct hid_device_id pyra_devices[] = {
  554. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT,
  555. USB_DEVICE_ID_ROCCAT_PYRA_WIRED) },
  556. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT,
  557. USB_DEVICE_ID_ROCCAT_PYRA_WIRELESS) },
  558. { }
  559. };
  560. MODULE_DEVICE_TABLE(hid, pyra_devices);
  561. static struct hid_driver pyra_driver = {
  562. .name = "pyra",
  563. .id_table = pyra_devices,
  564. .probe = pyra_probe,
  565. .remove = pyra_remove,
  566. .raw_event = pyra_raw_event
  567. };
  568. static int __init pyra_init(void)
  569. {
  570. int retval;
  571. /* class name has to be same as driver name */
  572. pyra_class = class_create(THIS_MODULE, "pyra");
  573. if (IS_ERR(pyra_class))
  574. return PTR_ERR(pyra_class);
  575. pyra_class->dev_attrs = pyra_attributes;
  576. pyra_class->dev_bin_attrs = pyra_bin_attributes;
  577. retval = hid_register_driver(&pyra_driver);
  578. if (retval)
  579. class_destroy(pyra_class);
  580. return retval;
  581. }
  582. static void __exit pyra_exit(void)
  583. {
  584. hid_unregister_driver(&pyra_driver);
  585. class_destroy(pyra_class);
  586. }
  587. module_init(pyra_init);
  588. module_exit(pyra_exit);
  589. MODULE_AUTHOR("Stefan Achatz");
  590. MODULE_DESCRIPTION("USB Roccat Pyra driver");
  591. MODULE_LICENSE("GPL v2");