GNU Linux-libre 4.4.288-gnu1
[releases.git] / drivers / hid / hid-roccat-kovaplus.c
1 /*
2  * Roccat Kova[+] driver for Linux
3  *
4  * Copyright (c) 2011 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 Kova[+] is a bigger version of the Pyra with two more side buttons.
16  */
17
18 #include <linux/device.h>
19 #include <linux/input.h>
20 #include <linux/hid.h>
21 #include <linux/module.h>
22 #include <linux/slab.h>
23 #include <linux/hid-roccat.h>
24 #include "hid-ids.h"
25 #include "hid-roccat-common.h"
26 #include "hid-roccat-kovaplus.h"
27
28 static uint profile_numbers[5] = {0, 1, 2, 3, 4};
29
30 static struct class *kovaplus_class;
31
32 static uint kovaplus_convert_event_cpi(uint value)
33 {
34         return (value == 7 ? 4 : (value == 4 ? 3 : value));
35 }
36
37 static void kovaplus_profile_activated(struct kovaplus_device *kovaplus,
38                 uint new_profile_index)
39 {
40         if (new_profile_index >= ARRAY_SIZE(kovaplus->profile_settings))
41                 return;
42         kovaplus->actual_profile = new_profile_index;
43         kovaplus->actual_cpi = kovaplus->profile_settings[new_profile_index].cpi_startup_level;
44         kovaplus->actual_x_sensitivity = kovaplus->profile_settings[new_profile_index].sensitivity_x;
45         kovaplus->actual_y_sensitivity = kovaplus->profile_settings[new_profile_index].sensitivity_y;
46 }
47
48 static int kovaplus_send_control(struct usb_device *usb_dev, uint value,
49                 enum kovaplus_control_requests request)
50 {
51         int retval;
52         struct roccat_common2_control control;
53
54         if ((request == KOVAPLUS_CONTROL_REQUEST_PROFILE_SETTINGS ||
55                         request == KOVAPLUS_CONTROL_REQUEST_PROFILE_BUTTONS) &&
56                         value > 4)
57                 return -EINVAL;
58
59         control.command = ROCCAT_COMMON_COMMAND_CONTROL;
60         control.value = value;
61         control.request = request;
62
63         retval = roccat_common2_send(usb_dev, ROCCAT_COMMON_COMMAND_CONTROL,
64                         &control, sizeof(struct roccat_common2_control));
65
66         return retval;
67 }
68
69 static int kovaplus_select_profile(struct usb_device *usb_dev, uint number,
70                 enum kovaplus_control_requests request)
71 {
72         return kovaplus_send_control(usb_dev, number, request);
73 }
74
75 static int kovaplus_get_profile_settings(struct usb_device *usb_dev,
76                 struct kovaplus_profile_settings *buf, uint number)
77 {
78         int retval;
79
80         retval = kovaplus_select_profile(usb_dev, number,
81                         KOVAPLUS_CONTROL_REQUEST_PROFILE_SETTINGS);
82         if (retval)
83                 return retval;
84
85         return roccat_common2_receive(usb_dev, KOVAPLUS_COMMAND_PROFILE_SETTINGS,
86                         buf, KOVAPLUS_SIZE_PROFILE_SETTINGS);
87 }
88
89 static int kovaplus_get_profile_buttons(struct usb_device *usb_dev,
90                 struct kovaplus_profile_buttons *buf, int number)
91 {
92         int retval;
93
94         retval = kovaplus_select_profile(usb_dev, number,
95                         KOVAPLUS_CONTROL_REQUEST_PROFILE_BUTTONS);
96         if (retval)
97                 return retval;
98
99         return roccat_common2_receive(usb_dev, KOVAPLUS_COMMAND_PROFILE_BUTTONS,
100                         buf, KOVAPLUS_SIZE_PROFILE_BUTTONS);
101 }
102
103 /* retval is 0-4 on success, < 0 on error */
104 static int kovaplus_get_actual_profile(struct usb_device *usb_dev)
105 {
106         struct kovaplus_actual_profile buf;
107         int retval;
108
109         retval = roccat_common2_receive(usb_dev, KOVAPLUS_COMMAND_ACTUAL_PROFILE,
110                         &buf, sizeof(struct kovaplus_actual_profile));
111
112         return retval ? retval : buf.actual_profile;
113 }
114
115 static int kovaplus_set_actual_profile(struct usb_device *usb_dev,
116                 int new_profile)
117 {
118         struct kovaplus_actual_profile buf;
119
120         buf.command = KOVAPLUS_COMMAND_ACTUAL_PROFILE;
121         buf.size = sizeof(struct kovaplus_actual_profile);
122         buf.actual_profile = new_profile;
123
124         return roccat_common2_send_with_status(usb_dev,
125                         KOVAPLUS_COMMAND_ACTUAL_PROFILE,
126                         &buf, sizeof(struct kovaplus_actual_profile));
127 }
128
129 static ssize_t kovaplus_sysfs_read(struct file *fp, struct kobject *kobj,
130                 char *buf, loff_t off, size_t count,
131                 size_t real_size, uint command)
132 {
133         struct device *dev =
134                         container_of(kobj, struct device, kobj)->parent->parent;
135         struct kovaplus_device *kovaplus = hid_get_drvdata(dev_get_drvdata(dev));
136         struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
137         int retval;
138
139         if (off >= real_size)
140                 return 0;
141
142         if (off != 0 || count != real_size)
143                 return -EINVAL;
144
145         mutex_lock(&kovaplus->kovaplus_lock);
146         retval = roccat_common2_receive(usb_dev, command, buf, real_size);
147         mutex_unlock(&kovaplus->kovaplus_lock);
148
149         if (retval)
150                 return retval;
151
152         return real_size;
153 }
154
155 static ssize_t kovaplus_sysfs_write(struct file *fp, struct kobject *kobj,
156                 void const *buf, loff_t off, size_t count,
157                 size_t real_size, uint command)
158 {
159         struct device *dev =
160                         container_of(kobj, struct device, kobj)->parent->parent;
161         struct kovaplus_device *kovaplus = hid_get_drvdata(dev_get_drvdata(dev));
162         struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
163         int retval;
164
165         if (off != 0 || count != real_size)
166                 return -EINVAL;
167
168         mutex_lock(&kovaplus->kovaplus_lock);
169         retval = roccat_common2_send_with_status(usb_dev, command,
170                         buf, real_size);
171         mutex_unlock(&kovaplus->kovaplus_lock);
172
173         if (retval)
174                 return retval;
175
176         return real_size;
177 }
178
179 #define KOVAPLUS_SYSFS_W(thingy, THINGY) \
180 static ssize_t kovaplus_sysfs_write_ ## thingy(struct file *fp, \
181                 struct kobject *kobj, struct bin_attribute *attr, char *buf, \
182                 loff_t off, size_t count) \
183 { \
184         return kovaplus_sysfs_write(fp, kobj, buf, off, count, \
185                         KOVAPLUS_SIZE_ ## THINGY, KOVAPLUS_COMMAND_ ## THINGY); \
186 }
187
188 #define KOVAPLUS_SYSFS_R(thingy, THINGY) \
189 static ssize_t kovaplus_sysfs_read_ ## thingy(struct file *fp, \
190                 struct kobject *kobj, struct bin_attribute *attr, char *buf, \
191                 loff_t off, size_t count) \
192 { \
193         return kovaplus_sysfs_read(fp, kobj, buf, off, count, \
194                         KOVAPLUS_SIZE_ ## THINGY, KOVAPLUS_COMMAND_ ## THINGY); \
195 }
196
197 #define KOVAPLUS_SYSFS_RW(thingy, THINGY) \
198 KOVAPLUS_SYSFS_W(thingy, THINGY) \
199 KOVAPLUS_SYSFS_R(thingy, THINGY)
200
201 #define KOVAPLUS_BIN_ATTRIBUTE_RW(thingy, THINGY) \
202 KOVAPLUS_SYSFS_RW(thingy, THINGY); \
203 static struct bin_attribute bin_attr_##thingy = { \
204         .attr = { .name = #thingy, .mode = 0660 }, \
205         .size = KOVAPLUS_SIZE_ ## THINGY, \
206         .read = kovaplus_sysfs_read_ ## thingy, \
207         .write = kovaplus_sysfs_write_ ## thingy \
208 }
209
210 #define KOVAPLUS_BIN_ATTRIBUTE_W(thingy, THINGY) \
211 KOVAPLUS_SYSFS_W(thingy, THINGY); \
212 static struct bin_attribute bin_attr_##thingy = { \
213         .attr = { .name = #thingy, .mode = 0220 }, \
214         .size = KOVAPLUS_SIZE_ ## THINGY, \
215         .write = kovaplus_sysfs_write_ ## thingy \
216 }
217 KOVAPLUS_BIN_ATTRIBUTE_W(control, CONTROL);
218 KOVAPLUS_BIN_ATTRIBUTE_RW(info, INFO);
219 KOVAPLUS_BIN_ATTRIBUTE_RW(profile_settings, PROFILE_SETTINGS);
220 KOVAPLUS_BIN_ATTRIBUTE_RW(profile_buttons, PROFILE_BUTTONS);
221
222 static ssize_t kovaplus_sysfs_read_profilex_settings(struct file *fp,
223                 struct kobject *kobj, struct bin_attribute *attr, char *buf,
224                 loff_t off, size_t count)
225 {
226         struct device *dev =
227                         container_of(kobj, struct device, kobj)->parent->parent;
228         struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
229         ssize_t retval;
230
231         retval = kovaplus_select_profile(usb_dev, *(uint *)(attr->private),
232                         KOVAPLUS_CONTROL_REQUEST_PROFILE_SETTINGS);
233         if (retval)
234                 return retval;
235
236         return kovaplus_sysfs_read(fp, kobj, buf, off, count,
237                         KOVAPLUS_SIZE_PROFILE_SETTINGS,
238                         KOVAPLUS_COMMAND_PROFILE_SETTINGS);
239 }
240
241 static ssize_t kovaplus_sysfs_read_profilex_buttons(struct file *fp,
242                 struct kobject *kobj, struct bin_attribute *attr, char *buf,
243                 loff_t off, size_t count)
244 {
245         struct device *dev =
246                         container_of(kobj, struct device, kobj)->parent->parent;
247         struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
248         ssize_t retval;
249
250         retval = kovaplus_select_profile(usb_dev, *(uint *)(attr->private),
251                         KOVAPLUS_CONTROL_REQUEST_PROFILE_BUTTONS);
252         if (retval)
253                 return retval;
254
255         return kovaplus_sysfs_read(fp, kobj, buf, off, count,
256                         KOVAPLUS_SIZE_PROFILE_BUTTONS,
257                         KOVAPLUS_COMMAND_PROFILE_BUTTONS);
258 }
259
260 #define PROFILE_ATTR(number)                                            \
261 static struct bin_attribute bin_attr_profile##number##_settings = {     \
262         .attr = { .name = "profile" #number "_settings", .mode = 0440 },        \
263         .size = KOVAPLUS_SIZE_PROFILE_SETTINGS,                         \
264         .read = kovaplus_sysfs_read_profilex_settings,                  \
265         .private = &profile_numbers[number-1],                          \
266 };                                                                      \
267 static struct bin_attribute bin_attr_profile##number##_buttons = {      \
268         .attr = { .name = "profile" #number "_buttons", .mode = 0440 }, \
269         .size = KOVAPLUS_SIZE_PROFILE_BUTTONS,                          \
270         .read = kovaplus_sysfs_read_profilex_buttons,                   \
271         .private = &profile_numbers[number-1],                          \
272 };
273 PROFILE_ATTR(1);
274 PROFILE_ATTR(2);
275 PROFILE_ATTR(3);
276 PROFILE_ATTR(4);
277 PROFILE_ATTR(5);
278
279 static ssize_t kovaplus_sysfs_show_actual_profile(struct device *dev,
280                 struct device_attribute *attr, char *buf)
281 {
282         struct kovaplus_device *kovaplus =
283                         hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
284         return snprintf(buf, PAGE_SIZE, "%d\n", kovaplus->actual_profile);
285 }
286
287 static ssize_t kovaplus_sysfs_set_actual_profile(struct device *dev,
288                 struct device_attribute *attr, char const *buf, size_t size)
289 {
290         struct kovaplus_device *kovaplus;
291         struct usb_device *usb_dev;
292         unsigned long profile;
293         int retval;
294         struct kovaplus_roccat_report roccat_report;
295
296         dev = dev->parent->parent;
297         kovaplus = hid_get_drvdata(dev_get_drvdata(dev));
298         usb_dev = interface_to_usbdev(to_usb_interface(dev));
299
300         retval = kstrtoul(buf, 10, &profile);
301         if (retval)
302                 return retval;
303
304         if (profile >= 5)
305                 return -EINVAL;
306
307         mutex_lock(&kovaplus->kovaplus_lock);
308         retval = kovaplus_set_actual_profile(usb_dev, profile);
309         if (retval) {
310                 mutex_unlock(&kovaplus->kovaplus_lock);
311                 return retval;
312         }
313
314         kovaplus_profile_activated(kovaplus, profile);
315
316         roccat_report.type = KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_PROFILE_1;
317         roccat_report.profile = profile + 1;
318         roccat_report.button = 0;
319         roccat_report.data1 = profile + 1;
320         roccat_report.data2 = 0;
321         roccat_report_event(kovaplus->chrdev_minor,
322                         (uint8_t const *)&roccat_report);
323
324         mutex_unlock(&kovaplus->kovaplus_lock);
325
326         return size;
327 }
328 static DEVICE_ATTR(actual_profile, 0660,
329                    kovaplus_sysfs_show_actual_profile,
330                    kovaplus_sysfs_set_actual_profile);
331
332 static ssize_t kovaplus_sysfs_show_actual_cpi(struct device *dev,
333                 struct device_attribute *attr, char *buf)
334 {
335         struct kovaplus_device *kovaplus =
336                         hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
337         return snprintf(buf, PAGE_SIZE, "%d\n", kovaplus->actual_cpi);
338 }
339 static DEVICE_ATTR(actual_cpi, 0440, kovaplus_sysfs_show_actual_cpi, NULL);
340
341 static ssize_t kovaplus_sysfs_show_actual_sensitivity_x(struct device *dev,
342                 struct device_attribute *attr, char *buf)
343 {
344         struct kovaplus_device *kovaplus =
345                         hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
346         return snprintf(buf, PAGE_SIZE, "%d\n", kovaplus->actual_x_sensitivity);
347 }
348 static DEVICE_ATTR(actual_sensitivity_x, 0440,
349                    kovaplus_sysfs_show_actual_sensitivity_x, NULL);
350
351 static ssize_t kovaplus_sysfs_show_actual_sensitivity_y(struct device *dev,
352                 struct device_attribute *attr, char *buf)
353 {
354         struct kovaplus_device *kovaplus =
355                         hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
356         return snprintf(buf, PAGE_SIZE, "%d\n", kovaplus->actual_y_sensitivity);
357 }
358 static DEVICE_ATTR(actual_sensitivity_y, 0440,
359                    kovaplus_sysfs_show_actual_sensitivity_y, NULL);
360
361 static ssize_t kovaplus_sysfs_show_firmware_version(struct device *dev,
362                 struct device_attribute *attr, char *buf)
363 {
364         struct kovaplus_device *kovaplus;
365         struct usb_device *usb_dev;
366         struct kovaplus_info info;
367
368         dev = dev->parent->parent;
369         kovaplus = hid_get_drvdata(dev_get_drvdata(dev));
370         usb_dev = interface_to_usbdev(to_usb_interface(dev));
371
372         mutex_lock(&kovaplus->kovaplus_lock);
373         roccat_common2_receive(usb_dev, KOVAPLUS_COMMAND_INFO,
374                         &info, KOVAPLUS_SIZE_INFO);
375         mutex_unlock(&kovaplus->kovaplus_lock);
376
377         return snprintf(buf, PAGE_SIZE, "%d\n", info.firmware_version);
378 }
379 static DEVICE_ATTR(firmware_version, 0440,
380                    kovaplus_sysfs_show_firmware_version, NULL);
381
382 static struct attribute *kovaplus_attrs[] = {
383         &dev_attr_actual_cpi.attr,
384         &dev_attr_firmware_version.attr,
385         &dev_attr_actual_profile.attr,
386         &dev_attr_actual_sensitivity_x.attr,
387         &dev_attr_actual_sensitivity_y.attr,
388         NULL,
389 };
390
391 static struct bin_attribute *kovaplus_bin_attributes[] = {
392         &bin_attr_control,
393         &bin_attr_info,
394         &bin_attr_profile_settings,
395         &bin_attr_profile_buttons,
396         &bin_attr_profile1_settings,
397         &bin_attr_profile2_settings,
398         &bin_attr_profile3_settings,
399         &bin_attr_profile4_settings,
400         &bin_attr_profile5_settings,
401         &bin_attr_profile1_buttons,
402         &bin_attr_profile2_buttons,
403         &bin_attr_profile3_buttons,
404         &bin_attr_profile4_buttons,
405         &bin_attr_profile5_buttons,
406         NULL,
407 };
408
409 static const struct attribute_group kovaplus_group = {
410         .attrs = kovaplus_attrs,
411         .bin_attrs = kovaplus_bin_attributes,
412 };
413
414 static const struct attribute_group *kovaplus_groups[] = {
415         &kovaplus_group,
416         NULL,
417 };
418
419 static int kovaplus_init_kovaplus_device_struct(struct usb_device *usb_dev,
420                 struct kovaplus_device *kovaplus)
421 {
422         int retval, i;
423         static uint wait = 70; /* device will freeze with just 60 */
424
425         mutex_init(&kovaplus->kovaplus_lock);
426
427         for (i = 0; i < 5; ++i) {
428                 msleep(wait);
429                 retval = kovaplus_get_profile_settings(usb_dev,
430                                 &kovaplus->profile_settings[i], i);
431                 if (retval)
432                         return retval;
433
434                 msleep(wait);
435                 retval = kovaplus_get_profile_buttons(usb_dev,
436                                 &kovaplus->profile_buttons[i], i);
437                 if (retval)
438                         return retval;
439         }
440
441         msleep(wait);
442         retval = kovaplus_get_actual_profile(usb_dev);
443         if (retval < 0)
444                 return retval;
445         kovaplus_profile_activated(kovaplus, retval);
446
447         return 0;
448 }
449
450 static int kovaplus_init_specials(struct hid_device *hdev)
451 {
452         struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
453         struct usb_device *usb_dev = interface_to_usbdev(intf);
454         struct kovaplus_device *kovaplus;
455         int retval;
456
457         if (intf->cur_altsetting->desc.bInterfaceProtocol
458                         == USB_INTERFACE_PROTOCOL_MOUSE) {
459
460                 kovaplus = kzalloc(sizeof(*kovaplus), GFP_KERNEL);
461                 if (!kovaplus) {
462                         hid_err(hdev, "can't alloc device descriptor\n");
463                         return -ENOMEM;
464                 }
465                 hid_set_drvdata(hdev, kovaplus);
466
467                 retval = kovaplus_init_kovaplus_device_struct(usb_dev, kovaplus);
468                 if (retval) {
469                         hid_err(hdev, "couldn't init struct kovaplus_device\n");
470                         goto exit_free;
471                 }
472
473                 retval = roccat_connect(kovaplus_class, hdev,
474                                 sizeof(struct kovaplus_roccat_report));
475                 if (retval < 0) {
476                         hid_err(hdev, "couldn't init char dev\n");
477                 } else {
478                         kovaplus->chrdev_minor = retval;
479                         kovaplus->roccat_claimed = 1;
480                 }
481
482         } else {
483                 hid_set_drvdata(hdev, NULL);
484         }
485
486         return 0;
487 exit_free:
488         kfree(kovaplus);
489         return retval;
490 }
491
492 static void kovaplus_remove_specials(struct hid_device *hdev)
493 {
494         struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
495         struct kovaplus_device *kovaplus;
496
497         if (intf->cur_altsetting->desc.bInterfaceProtocol
498                         == USB_INTERFACE_PROTOCOL_MOUSE) {
499                 kovaplus = hid_get_drvdata(hdev);
500                 if (kovaplus->roccat_claimed)
501                         roccat_disconnect(kovaplus->chrdev_minor);
502                 kfree(kovaplus);
503         }
504 }
505
506 static int kovaplus_probe(struct hid_device *hdev,
507                 const struct hid_device_id *id)
508 {
509         int retval;
510
511         retval = hid_parse(hdev);
512         if (retval) {
513                 hid_err(hdev, "parse failed\n");
514                 goto exit;
515         }
516
517         retval = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
518         if (retval) {
519                 hid_err(hdev, "hw start failed\n");
520                 goto exit;
521         }
522
523         retval = kovaplus_init_specials(hdev);
524         if (retval) {
525                 hid_err(hdev, "couldn't install mouse\n");
526                 goto exit_stop;
527         }
528
529         return 0;
530
531 exit_stop:
532         hid_hw_stop(hdev);
533 exit:
534         return retval;
535 }
536
537 static void kovaplus_remove(struct hid_device *hdev)
538 {
539         kovaplus_remove_specials(hdev);
540         hid_hw_stop(hdev);
541 }
542
543 static void kovaplus_keep_values_up_to_date(struct kovaplus_device *kovaplus,
544                 u8 const *data)
545 {
546         struct kovaplus_mouse_report_button const *button_report;
547
548         if (data[0] != KOVAPLUS_MOUSE_REPORT_NUMBER_BUTTON)
549                 return;
550
551         button_report = (struct kovaplus_mouse_report_button const *)data;
552
553         switch (button_report->type) {
554         case KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_PROFILE_1:
555                 kovaplus_profile_activated(kovaplus, button_report->data1 - 1);
556                 break;
557         case KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_CPI:
558                 kovaplus->actual_cpi = kovaplus_convert_event_cpi(button_report->data1);
559                 break;
560         case KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_SENSITIVITY:
561                 kovaplus->actual_x_sensitivity = button_report->data1;
562                 kovaplus->actual_y_sensitivity = button_report->data2;
563                 break;
564         default:
565                 break;
566         }
567 }
568
569 static void kovaplus_report_to_chrdev(struct kovaplus_device const *kovaplus,
570                 u8 const *data)
571 {
572         struct kovaplus_roccat_report roccat_report;
573         struct kovaplus_mouse_report_button const *button_report;
574
575         if (data[0] != KOVAPLUS_MOUSE_REPORT_NUMBER_BUTTON)
576                 return;
577
578         button_report = (struct kovaplus_mouse_report_button const *)data;
579
580         if (button_report->type == KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_PROFILE_2)
581                 return;
582
583         roccat_report.type = button_report->type;
584         roccat_report.profile = kovaplus->actual_profile + 1;
585
586         if (roccat_report.type == KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_MACRO ||
587                         roccat_report.type == KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_SHORTCUT ||
588                         roccat_report.type == KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_QUICKLAUNCH ||
589                         roccat_report.type == KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_TIMER)
590                 roccat_report.button = button_report->data1;
591         else
592                 roccat_report.button = 0;
593
594         if (roccat_report.type == KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_CPI)
595                 roccat_report.data1 = kovaplus_convert_event_cpi(button_report->data1);
596         else
597                 roccat_report.data1 = button_report->data1;
598
599         roccat_report.data2 = button_report->data2;
600
601         roccat_report_event(kovaplus->chrdev_minor,
602                         (uint8_t const *)&roccat_report);
603 }
604
605 static int kovaplus_raw_event(struct hid_device *hdev,
606                 struct hid_report *report, u8 *data, int size)
607 {
608         struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
609         struct kovaplus_device *kovaplus = hid_get_drvdata(hdev);
610
611         if (intf->cur_altsetting->desc.bInterfaceProtocol
612                         != USB_INTERFACE_PROTOCOL_MOUSE)
613                 return 0;
614
615         if (kovaplus == NULL)
616                 return 0;
617
618         kovaplus_keep_values_up_to_date(kovaplus, data);
619
620         if (kovaplus->roccat_claimed)
621                 kovaplus_report_to_chrdev(kovaplus, data);
622
623         return 0;
624 }
625
626 static const struct hid_device_id kovaplus_devices[] = {
627         { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KOVAPLUS) },
628         { }
629 };
630
631 MODULE_DEVICE_TABLE(hid, kovaplus_devices);
632
633 static struct hid_driver kovaplus_driver = {
634                 .name = "kovaplus",
635                 .id_table = kovaplus_devices,
636                 .probe = kovaplus_probe,
637                 .remove = kovaplus_remove,
638                 .raw_event = kovaplus_raw_event
639 };
640
641 static int __init kovaplus_init(void)
642 {
643         int retval;
644
645         kovaplus_class = class_create(THIS_MODULE, "kovaplus");
646         if (IS_ERR(kovaplus_class))
647                 return PTR_ERR(kovaplus_class);
648         kovaplus_class->dev_groups = kovaplus_groups;
649
650         retval = hid_register_driver(&kovaplus_driver);
651         if (retval)
652                 class_destroy(kovaplus_class);
653         return retval;
654 }
655
656 static void __exit kovaplus_exit(void)
657 {
658         hid_unregister_driver(&kovaplus_driver);
659         class_destroy(kovaplus_class);
660 }
661
662 module_init(kovaplus_init);
663 module_exit(kovaplus_exit);
664
665 MODULE_AUTHOR("Stefan Achatz");
666 MODULE_DESCRIPTION("USB Roccat Kova[+] driver");
667 MODULE_LICENSE("GPL v2");