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