hid-roccat-pyra.c 18 KB

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