hid-roccat-pyra.c 16 KB

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