hid-roccat-pyra.c 16 KB

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