1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Roccat Kone driver for Linux
5 * Copyright (c) 2010 Stefan Achatz <erazor_de@users.sourceforge.net>
12 * Roccat Kone is a gamer mouse which consists of a mouse part and a keyboard
13 * part. The keyboard part enables the mouse to execute stored macros with mixed
14 * key- and button-events.
16 * TODO implement on-the-fly polling-rate change
17 * The windows driver has the ability to change the polling rate of the
18 * device on the press of a mousebutton.
19 * Is it possible to remove and reinstall the urb in raw-event- or any
20 * other handler, or to defer this action to be executed somewhere else?
22 * TODO is it possible to overwrite group for sysfs attributes via udev?
25 #include <linux/device.h>
26 #include <linux/input.h>
27 #include <linux/hid.h>
28 #include <linux/module.h>
29 #include <linux/slab.h>
30 #include <linux/hid-roccat.h>
32 #include "hid-roccat-common.h"
33 #include "hid-roccat-kone.h"
35 static uint profile_numbers
[5] = {0, 1, 2, 3, 4};
37 static void kone_profile_activated(struct kone_device
*kone
, uint new_profile
)
39 kone
->actual_profile
= new_profile
;
40 kone
->actual_dpi
= kone
->profiles
[new_profile
- 1].startup_dpi
;
43 static void kone_profile_report(struct kone_device
*kone
, uint new_profile
)
45 struct kone_roccat_report roccat_report
;
47 roccat_report
.event
= kone_mouse_event_switch_profile
;
48 roccat_report
.value
= new_profile
;
49 roccat_report
.key
= 0;
50 roccat_report_event(kone
->chrdev_minor
, (uint8_t *)&roccat_report
);
53 static int kone_receive(struct usb_device
*usb_dev
, uint usb_command
,
54 void *data
, uint size
)
59 buf
= kmalloc(size
, GFP_KERNEL
);
63 len
= usb_control_msg(usb_dev
, usb_rcvctrlpipe(usb_dev
, 0),
65 USB_TYPE_CLASS
| USB_RECIP_INTERFACE
| USB_DIR_IN
,
66 usb_command
, 0, buf
, size
, USB_CTRL_SET_TIMEOUT
);
68 memcpy(data
, buf
, size
);
70 return ((len
< 0) ? len
: ((len
!= size
) ? -EIO
: 0));
73 static int kone_send(struct usb_device
*usb_dev
, uint usb_command
,
74 void const *data
, uint size
)
79 buf
= kmemdup(data
, size
, GFP_KERNEL
);
83 len
= usb_control_msg(usb_dev
, usb_sndctrlpipe(usb_dev
, 0),
85 USB_TYPE_CLASS
| USB_RECIP_INTERFACE
| USB_DIR_OUT
,
86 usb_command
, 0, buf
, size
, USB_CTRL_SET_TIMEOUT
);
89 return ((len
< 0) ? len
: ((len
!= size
) ? -EIO
: 0));
92 /* kone_class is used for creating sysfs attributes via roccat char device */
93 static struct class *kone_class
;
95 static void kone_set_settings_checksum(struct kone_settings
*settings
)
97 uint16_t checksum
= 0;
98 unsigned char *address
= (unsigned char *)settings
;
101 for (i
= 0; i
< sizeof(struct kone_settings
) - 2; ++i
, ++address
)
102 checksum
+= *address
;
103 settings
->checksum
= cpu_to_le16(checksum
);
107 * Checks success after writing data to mouse
108 * On success returns 0
109 * On failure returns errno
111 static int kone_check_write(struct usb_device
*usb_dev
)
118 * Mouse needs 50 msecs until it says ok, but there are
119 * 30 more msecs needed for next write to work.
123 retval
= kone_receive(usb_dev
,
124 kone_command_confirm_write
, &data
, 1);
129 * value of 3 seems to mean something like
130 * "not finished yet, but it looks good"
131 * So check again after a moment.
135 if (data
== 1) /* everything alright */
139 dev_err(&usb_dev
->dev
, "got retval %d when checking write\n", data
);
144 * Reads settings from mouse and stores it in @buf
145 * On success returns 0
146 * On failure returns errno
148 static int kone_get_settings(struct usb_device
*usb_dev
,
149 struct kone_settings
*buf
)
151 return kone_receive(usb_dev
, kone_command_settings
, buf
,
152 sizeof(struct kone_settings
));
156 * Writes settings from @buf to mouse
157 * On success returns 0
158 * On failure returns errno
160 static int kone_set_settings(struct usb_device
*usb_dev
,
161 struct kone_settings
const *settings
)
165 retval
= kone_send(usb_dev
, kone_command_settings
,
166 settings
, sizeof(struct kone_settings
));
169 return kone_check_write(usb_dev
);
173 * Reads profile data from mouse and stores it in @buf
174 * @number: profile number to read
175 * On success returns 0
176 * On failure returns errno
178 static int kone_get_profile(struct usb_device
*usb_dev
,
179 struct kone_profile
*buf
, int number
)
183 if (number
< 1 || number
> 5)
186 len
= usb_control_msg(usb_dev
, usb_rcvctrlpipe(usb_dev
, 0),
187 USB_REQ_CLEAR_FEATURE
,
188 USB_TYPE_CLASS
| USB_RECIP_INTERFACE
| USB_DIR_IN
,
189 kone_command_profile
, number
, buf
,
190 sizeof(struct kone_profile
), USB_CTRL_SET_TIMEOUT
);
192 if (len
!= sizeof(struct kone_profile
))
199 * Writes profile data to mouse.
200 * @number: profile number to write
201 * On success returns 0
202 * On failure returns errno
204 static int kone_set_profile(struct usb_device
*usb_dev
,
205 struct kone_profile
const *profile
, int number
)
209 if (number
< 1 || number
> 5)
212 len
= usb_control_msg(usb_dev
, usb_sndctrlpipe(usb_dev
, 0),
213 USB_REQ_SET_CONFIGURATION
,
214 USB_TYPE_CLASS
| USB_RECIP_INTERFACE
| USB_DIR_OUT
,
215 kone_command_profile
, number
, (void *)profile
,
216 sizeof(struct kone_profile
),
217 USB_CTRL_SET_TIMEOUT
);
219 if (len
!= sizeof(struct kone_profile
))
222 if (kone_check_write(usb_dev
))
229 * Reads value of "fast-clip-weight" and stores it in @result
230 * On success returns 0
231 * On failure returns errno
233 static int kone_get_weight(struct usb_device
*usb_dev
, int *result
)
238 retval
= kone_receive(usb_dev
, kone_command_weight
, &data
, 1);
248 * Reads firmware_version of mouse and stores it in @result
249 * On success returns 0
250 * On failure returns errno
252 static int kone_get_firmware_version(struct usb_device
*usb_dev
, int *result
)
257 retval
= kone_receive(usb_dev
, kone_command_firmware_version
,
262 *result
= le16_to_cpu(data
);
266 static ssize_t
kone_sysfs_read_settings(struct file
*fp
, struct kobject
*kobj
,
267 struct bin_attribute
*attr
, char *buf
,
268 loff_t off
, size_t count
) {
269 struct device
*dev
= kobj_to_dev(kobj
)->parent
->parent
;
270 struct kone_device
*kone
= hid_get_drvdata(dev_get_drvdata(dev
));
272 if (off
>= sizeof(struct kone_settings
))
275 if (off
+ count
> sizeof(struct kone_settings
))
276 count
= sizeof(struct kone_settings
) - off
;
278 mutex_lock(&kone
->kone_lock
);
279 memcpy(buf
, ((char const *)&kone
->settings
) + off
, count
);
280 mutex_unlock(&kone
->kone_lock
);
286 * Writing settings automatically activates startup_profile.
287 * This function keeps values in kone_device up to date and assumes that in
288 * case of error the old data is still valid
290 static ssize_t
kone_sysfs_write_settings(struct file
*fp
, struct kobject
*kobj
,
291 struct bin_attribute
*attr
, char *buf
,
292 loff_t off
, size_t count
) {
293 struct device
*dev
= kobj_to_dev(kobj
)->parent
->parent
;
294 struct kone_device
*kone
= hid_get_drvdata(dev_get_drvdata(dev
));
295 struct usb_device
*usb_dev
= interface_to_usbdev(to_usb_interface(dev
));
296 int retval
= 0, difference
, old_profile
;
298 /* I need to get my data in one piece */
299 if (off
!= 0 || count
!= sizeof(struct kone_settings
))
302 mutex_lock(&kone
->kone_lock
);
303 difference
= memcmp(buf
, &kone
->settings
, sizeof(struct kone_settings
));
305 retval
= kone_set_settings(usb_dev
,
306 (struct kone_settings
const *)buf
);
308 mutex_unlock(&kone
->kone_lock
);
312 old_profile
= kone
->settings
.startup_profile
;
313 memcpy(&kone
->settings
, buf
, sizeof(struct kone_settings
));
315 kone_profile_activated(kone
, kone
->settings
.startup_profile
);
317 if (kone
->settings
.startup_profile
!= old_profile
)
318 kone_profile_report(kone
, kone
->settings
.startup_profile
);
320 mutex_unlock(&kone
->kone_lock
);
322 return sizeof(struct kone_settings
);
324 static BIN_ATTR(settings
, 0660, kone_sysfs_read_settings
,
325 kone_sysfs_write_settings
, sizeof(struct kone_settings
));
327 static ssize_t
kone_sysfs_read_profilex(struct file
*fp
,
328 struct kobject
*kobj
, struct bin_attribute
*attr
,
329 char *buf
, loff_t off
, size_t count
) {
330 struct device
*dev
= kobj_to_dev(kobj
)->parent
->parent
;
331 struct kone_device
*kone
= hid_get_drvdata(dev_get_drvdata(dev
));
333 if (off
>= sizeof(struct kone_profile
))
336 if (off
+ count
> sizeof(struct kone_profile
))
337 count
= sizeof(struct kone_profile
) - off
;
339 mutex_lock(&kone
->kone_lock
);
340 memcpy(buf
, ((char const *)&kone
->profiles
[*(uint
*)(attr
->private)]) + off
, count
);
341 mutex_unlock(&kone
->kone_lock
);
346 /* Writes data only if different to stored data */
347 static ssize_t
kone_sysfs_write_profilex(struct file
*fp
,
348 struct kobject
*kobj
, struct bin_attribute
*attr
,
349 char *buf
, loff_t off
, size_t count
) {
350 struct device
*dev
= kobj_to_dev(kobj
)->parent
->parent
;
351 struct kone_device
*kone
= hid_get_drvdata(dev_get_drvdata(dev
));
352 struct usb_device
*usb_dev
= interface_to_usbdev(to_usb_interface(dev
));
353 struct kone_profile
*profile
;
354 int retval
= 0, difference
;
356 /* I need to get my data in one piece */
357 if (off
!= 0 || count
!= sizeof(struct kone_profile
))
360 profile
= &kone
->profiles
[*(uint
*)(attr
->private)];
362 mutex_lock(&kone
->kone_lock
);
363 difference
= memcmp(buf
, profile
, sizeof(struct kone_profile
));
365 retval
= kone_set_profile(usb_dev
,
366 (struct kone_profile
const *)buf
,
367 *(uint
*)(attr
->private) + 1);
369 memcpy(profile
, buf
, sizeof(struct kone_profile
));
371 mutex_unlock(&kone
->kone_lock
);
376 return sizeof(struct kone_profile
);
378 #define PROFILE_ATTR(number) \
379 static struct bin_attribute bin_attr_profile##number = { \
380 .attr = { .name = "profile" #number, .mode = 0660 }, \
381 .size = sizeof(struct kone_profile), \
382 .read = kone_sysfs_read_profilex, \
383 .write = kone_sysfs_write_profilex, \
384 .private = &profile_numbers[number-1], \
392 static ssize_t
kone_sysfs_show_actual_profile(struct device
*dev
,
393 struct device_attribute
*attr
, char *buf
)
395 struct kone_device
*kone
=
396 hid_get_drvdata(dev_get_drvdata(dev
->parent
->parent
));
397 return snprintf(buf
, PAGE_SIZE
, "%d\n", kone
->actual_profile
);
399 static DEVICE_ATTR(actual_profile
, 0440, kone_sysfs_show_actual_profile
, NULL
);
401 static ssize_t
kone_sysfs_show_actual_dpi(struct device
*dev
,
402 struct device_attribute
*attr
, char *buf
)
404 struct kone_device
*kone
=
405 hid_get_drvdata(dev_get_drvdata(dev
->parent
->parent
));
406 return snprintf(buf
, PAGE_SIZE
, "%d\n", kone
->actual_dpi
);
408 static DEVICE_ATTR(actual_dpi
, 0440, kone_sysfs_show_actual_dpi
, NULL
);
410 /* weight is read each time, since we don't get informed when it's changed */
411 static ssize_t
kone_sysfs_show_weight(struct device
*dev
,
412 struct device_attribute
*attr
, char *buf
)
414 struct kone_device
*kone
;
415 struct usb_device
*usb_dev
;
419 dev
= dev
->parent
->parent
;
420 kone
= hid_get_drvdata(dev_get_drvdata(dev
));
421 usb_dev
= interface_to_usbdev(to_usb_interface(dev
));
423 mutex_lock(&kone
->kone_lock
);
424 retval
= kone_get_weight(usb_dev
, &weight
);
425 mutex_unlock(&kone
->kone_lock
);
429 return snprintf(buf
, PAGE_SIZE
, "%d\n", weight
);
431 static DEVICE_ATTR(weight
, 0440, kone_sysfs_show_weight
, NULL
);
433 static ssize_t
kone_sysfs_show_firmware_version(struct device
*dev
,
434 struct device_attribute
*attr
, char *buf
)
436 struct kone_device
*kone
=
437 hid_get_drvdata(dev_get_drvdata(dev
->parent
->parent
));
438 return snprintf(buf
, PAGE_SIZE
, "%d\n", kone
->firmware_version
);
440 static DEVICE_ATTR(firmware_version
, 0440, kone_sysfs_show_firmware_version
,
443 static ssize_t
kone_sysfs_show_tcu(struct device
*dev
,
444 struct device_attribute
*attr
, char *buf
)
446 struct kone_device
*kone
=
447 hid_get_drvdata(dev_get_drvdata(dev
->parent
->parent
));
448 return snprintf(buf
, PAGE_SIZE
, "%d\n", kone
->settings
.tcu
);
451 static int kone_tcu_command(struct usb_device
*usb_dev
, int number
)
456 return kone_send(usb_dev
, kone_command_calibrate
, &value
, 1);
460 * Calibrating the tcu is the only action that changes settings data inside the
461 * mouse, so this data needs to be reread
463 static ssize_t
kone_sysfs_set_tcu(struct device
*dev
,
464 struct device_attribute
*attr
, char const *buf
, size_t size
)
466 struct kone_device
*kone
;
467 struct usb_device
*usb_dev
;
471 dev
= dev
->parent
->parent
;
472 kone
= hid_get_drvdata(dev_get_drvdata(dev
));
473 usb_dev
= interface_to_usbdev(to_usb_interface(dev
));
475 retval
= kstrtoul(buf
, 10, &state
);
479 if (state
!= 0 && state
!= 1)
482 mutex_lock(&kone
->kone_lock
);
484 if (state
== 1) { /* state activate */
485 retval
= kone_tcu_command(usb_dev
, 1);
488 retval
= kone_tcu_command(usb_dev
, 2);
491 ssleep(5); /* tcu needs this time for calibration */
492 retval
= kone_tcu_command(usb_dev
, 3);
495 retval
= kone_tcu_command(usb_dev
, 0);
498 retval
= kone_tcu_command(usb_dev
, 4);
502 * Kone needs this time to settle things.
503 * Reading settings too early will result in invalid data.
504 * Roccat's driver waits 1 sec, maybe this time could be
510 /* calibration changes values in settings, so reread */
511 retval
= kone_get_settings(usb_dev
, &kone
->settings
);
513 goto exit_no_settings
;
515 /* only write settings back if activation state is different */
516 if (kone
->settings
.tcu
!= state
) {
517 kone
->settings
.tcu
= state
;
518 kone_set_settings_checksum(&kone
->settings
);
520 retval
= kone_set_settings(usb_dev
, &kone
->settings
);
522 dev_err(&usb_dev
->dev
, "couldn't set tcu state\n");
524 * try to reread valid settings into buffer overwriting
527 retval
= kone_get_settings(usb_dev
, &kone
->settings
);
529 goto exit_no_settings
;
532 /* calibration resets profile */
533 kone_profile_activated(kone
, kone
->settings
.startup_profile
);
538 dev_err(&usb_dev
->dev
, "couldn't read settings\n");
540 mutex_unlock(&kone
->kone_lock
);
543 static DEVICE_ATTR(tcu
, 0660, kone_sysfs_show_tcu
, kone_sysfs_set_tcu
);
545 static ssize_t
kone_sysfs_show_startup_profile(struct device
*dev
,
546 struct device_attribute
*attr
, char *buf
)
548 struct kone_device
*kone
=
549 hid_get_drvdata(dev_get_drvdata(dev
->parent
->parent
));
550 return snprintf(buf
, PAGE_SIZE
, "%d\n", kone
->settings
.startup_profile
);
553 static ssize_t
kone_sysfs_set_startup_profile(struct device
*dev
,
554 struct device_attribute
*attr
, char const *buf
, size_t size
)
556 struct kone_device
*kone
;
557 struct usb_device
*usb_dev
;
559 unsigned long new_startup_profile
;
561 dev
= dev
->parent
->parent
;
562 kone
= hid_get_drvdata(dev_get_drvdata(dev
));
563 usb_dev
= interface_to_usbdev(to_usb_interface(dev
));
565 retval
= kstrtoul(buf
, 10, &new_startup_profile
);
569 if (new_startup_profile
< 1 || new_startup_profile
> 5)
572 mutex_lock(&kone
->kone_lock
);
574 kone
->settings
.startup_profile
= new_startup_profile
;
575 kone_set_settings_checksum(&kone
->settings
);
577 retval
= kone_set_settings(usb_dev
, &kone
->settings
);
579 mutex_unlock(&kone
->kone_lock
);
583 /* changing the startup profile immediately activates this profile */
584 kone_profile_activated(kone
, new_startup_profile
);
585 kone_profile_report(kone
, new_startup_profile
);
587 mutex_unlock(&kone
->kone_lock
);
590 static DEVICE_ATTR(startup_profile
, 0660, kone_sysfs_show_startup_profile
,
591 kone_sysfs_set_startup_profile
);
593 static struct attribute
*kone_attrs
[] = {
595 * Read actual dpi settings.
596 * Returns raw value for further processing. Refer to enum
597 * kone_polling_rates to get real value.
599 &dev_attr_actual_dpi
.attr
,
600 &dev_attr_actual_profile
.attr
,
603 * The mouse can be equipped with one of four supplied weights from 5
604 * to 20 grams which are recognized and its value can be read out.
605 * This returns the raw value reported by the mouse for easy evaluation
606 * by software. Refer to enum kone_weights to get corresponding real
609 &dev_attr_weight
.attr
,
612 * Prints firmware version stored in mouse as integer.
613 * The raw value reported by the mouse is returned for easy evaluation,
614 * to get the real version number the decimal point has to be shifted 2
615 * positions to the left. E.g. a value of 138 means 1.38.
617 &dev_attr_firmware_version
.attr
,
620 * Prints state of Tracking Control Unit as number where 0 = off and
621 * 1 = on. Writing 0 deactivates tcu and writing 1 calibrates and
626 /* Prints and takes the number of the profile the mouse starts with */
627 &dev_attr_startup_profile
.attr
,
631 static struct bin_attribute
*kone_bin_attributes
[] = {
641 static const struct attribute_group kone_group
= {
643 .bin_attrs
= kone_bin_attributes
,
646 static const struct attribute_group
*kone_groups
[] = {
651 static int kone_init_kone_device_struct(struct usb_device
*usb_dev
,
652 struct kone_device
*kone
)
657 mutex_init(&kone
->kone_lock
);
659 for (i
= 0; i
< 5; ++i
) {
660 retval
= kone_get_profile(usb_dev
, &kone
->profiles
[i
], i
+ 1);
665 retval
= kone_get_settings(usb_dev
, &kone
->settings
);
669 retval
= kone_get_firmware_version(usb_dev
, &kone
->firmware_version
);
673 kone_profile_activated(kone
, kone
->settings
.startup_profile
);
679 * Since IGNORE_MOUSE quirk moved to hid-apple, there is no way to bind only to
680 * mousepart if usb_hid is compiled into the kernel and kone is compiled as
682 * Secial behaviour is bound only to mousepart since only mouseevents contain
683 * additional notifications.
685 static int kone_init_specials(struct hid_device
*hdev
)
687 struct usb_interface
*intf
= to_usb_interface(hdev
->dev
.parent
);
688 struct usb_device
*usb_dev
= interface_to_usbdev(intf
);
689 struct kone_device
*kone
;
692 if (intf
->cur_altsetting
->desc
.bInterfaceProtocol
693 == USB_INTERFACE_PROTOCOL_MOUSE
) {
695 kone
= kzalloc(sizeof(*kone
), GFP_KERNEL
);
698 hid_set_drvdata(hdev
, kone
);
700 retval
= kone_init_kone_device_struct(usb_dev
, kone
);
702 hid_err(hdev
, "couldn't init struct kone_device\n");
706 retval
= roccat_connect(kone_class
, hdev
,
707 sizeof(struct kone_roccat_report
));
709 hid_err(hdev
, "couldn't init char dev\n");
710 /* be tolerant about not getting chrdev */
712 kone
->roccat_claimed
= 1;
713 kone
->chrdev_minor
= retval
;
716 hid_set_drvdata(hdev
, NULL
);
725 static void kone_remove_specials(struct hid_device
*hdev
)
727 struct usb_interface
*intf
= to_usb_interface(hdev
->dev
.parent
);
728 struct kone_device
*kone
;
730 if (intf
->cur_altsetting
->desc
.bInterfaceProtocol
731 == USB_INTERFACE_PROTOCOL_MOUSE
) {
732 kone
= hid_get_drvdata(hdev
);
733 if (kone
->roccat_claimed
)
734 roccat_disconnect(kone
->chrdev_minor
);
735 kfree(hid_get_drvdata(hdev
));
739 static int kone_probe(struct hid_device
*hdev
, const struct hid_device_id
*id
)
743 retval
= hid_parse(hdev
);
745 hid_err(hdev
, "parse failed\n");
749 retval
= hid_hw_start(hdev
, HID_CONNECT_DEFAULT
);
751 hid_err(hdev
, "hw start failed\n");
755 retval
= kone_init_specials(hdev
);
757 hid_err(hdev
, "couldn't install mouse\n");
769 static void kone_remove(struct hid_device
*hdev
)
771 kone_remove_specials(hdev
);
775 /* handle special events and keep actual profile and dpi values up to date */
776 static void kone_keep_values_up_to_date(struct kone_device
*kone
,
777 struct kone_mouse_event
const *event
)
779 switch (event
->event
) {
780 case kone_mouse_event_switch_profile
:
781 kone
->actual_dpi
= kone
->profiles
[event
->value
- 1].
784 case kone_mouse_event_osd_profile
:
785 kone
->actual_profile
= event
->value
;
787 case kone_mouse_event_switch_dpi
:
788 case kone_mouse_event_osd_dpi
:
789 kone
->actual_dpi
= event
->value
;
794 static void kone_report_to_chrdev(struct kone_device
const *kone
,
795 struct kone_mouse_event
const *event
)
797 struct kone_roccat_report roccat_report
;
799 switch (event
->event
) {
800 case kone_mouse_event_switch_profile
:
801 case kone_mouse_event_switch_dpi
:
802 case kone_mouse_event_osd_profile
:
803 case kone_mouse_event_osd_dpi
:
804 roccat_report
.event
= event
->event
;
805 roccat_report
.value
= event
->value
;
806 roccat_report
.key
= 0;
807 roccat_report_event(kone
->chrdev_minor
,
808 (uint8_t *)&roccat_report
);
810 case kone_mouse_event_call_overlong_macro
:
811 case kone_mouse_event_multimedia
:
812 if (event
->value
== kone_keystroke_action_press
) {
813 roccat_report
.event
= event
->event
;
814 roccat_report
.value
= kone
->actual_profile
;
815 roccat_report
.key
= event
->macro_key
;
816 roccat_report_event(kone
->chrdev_minor
,
817 (uint8_t *)&roccat_report
);
825 * Is called for keyboard- and mousepart.
826 * Only mousepart gets informations about special events in its extended event
829 static int kone_raw_event(struct hid_device
*hdev
, struct hid_report
*report
,
832 struct kone_device
*kone
= hid_get_drvdata(hdev
);
833 struct kone_mouse_event
*event
= (struct kone_mouse_event
*)data
;
835 /* keyboard events are always processed by default handler */
836 if (size
!= sizeof(struct kone_mouse_event
))
843 * Firmware 1.38 introduced new behaviour for tilt and special buttons.
844 * Pressed button is reported in each movement event.
845 * Workaround sends only one event per press.
847 if (memcmp(&kone
->last_mouse_event
.tilt
, &event
->tilt
, 5))
848 memcpy(&kone
->last_mouse_event
, event
,
849 sizeof(struct kone_mouse_event
));
851 memset(&event
->tilt
, 0, 5);
853 kone_keep_values_up_to_date(kone
, event
);
855 if (kone
->roccat_claimed
)
856 kone_report_to_chrdev(kone
, event
);
858 return 0; /* always do further processing */
861 static const struct hid_device_id kone_devices
[] = {
862 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT
, USB_DEVICE_ID_ROCCAT_KONE
) },
866 MODULE_DEVICE_TABLE(hid
, kone_devices
);
868 static struct hid_driver kone_driver
= {
870 .id_table
= kone_devices
,
872 .remove
= kone_remove
,
873 .raw_event
= kone_raw_event
876 static int __init
kone_init(void)
880 /* class name has to be same as driver name */
881 kone_class
= class_create(THIS_MODULE
, "kone");
882 if (IS_ERR(kone_class
))
883 return PTR_ERR(kone_class
);
884 kone_class
->dev_groups
= kone_groups
;
886 retval
= hid_register_driver(&kone_driver
);
888 class_destroy(kone_class
);
892 static void __exit
kone_exit(void)
894 hid_unregister_driver(&kone_driver
);
895 class_destroy(kone_class
);
898 module_init(kone_init
);
899 module_exit(kone_exit
);
901 MODULE_AUTHOR("Stefan Achatz");
902 MODULE_DESCRIPTION("USB Roccat Kone driver");
903 MODULE_LICENSE("GPL v2");