2 * Roccat Kone driver for Linux
4 * Copyright (c) 2010 Stefan Achatz <erazor_de@users.sourceforge.net>
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)
15 * Roccat Kone is a gamer mouse which consists of a mouse part and a keyboard
16 * part. The keyboard part enables the mouse to execute stored macros with mixed
17 * key- and button-events.
19 * TODO implement on-the-fly polling-rate change
20 * The windows driver has the ability to change the polling rate of the
21 * device on the press of a mousebutton.
22 * Is it possible to remove and reinstall the urb in raw-event- or any
23 * other handler, or to defer this action to be executed somewhere else?
25 * TODO is it possible to overwrite group for sysfs attributes via udev?
28 #include <linux/device.h>
29 #include <linux/input.h>
30 #include <linux/hid.h>
31 #include <linux/usb.h>
32 #include <linux/module.h>
33 #include <linux/slab.h>
35 #include "hid-roccat.h"
36 #include "hid-roccat-kone.h"
38 static uint profile_numbers
[5] = {0, 1, 2, 3, 4};
40 /* kone_class is used for creating sysfs attributes via roccat char device */
41 static struct class *kone_class
;
43 static void kone_set_settings_checksum(struct kone_settings
*settings
)
45 uint16_t checksum
= 0;
46 unsigned char *address
= (unsigned char *)settings
;
49 for (i
= 0; i
< sizeof(struct kone_settings
) - 2; ++i
, ++address
)
51 settings
->checksum
= cpu_to_le16(checksum
);
55 * Checks success after writing data to mouse
56 * On success returns 0
57 * On failure returns errno
59 static int kone_check_write(struct usb_device
*usb_dev
)
64 data
= kmalloc(1, GFP_KERNEL
);
70 * Mouse needs 50 msecs until it says ok, but there are
71 * 30 more msecs needed for next write to work.
75 len
= usb_control_msg(usb_dev
, usb_rcvctrlpipe(usb_dev
, 0),
76 USB_REQ_CLEAR_FEATURE
,
77 USB_TYPE_CLASS
| USB_RECIP_INTERFACE
|
79 kone_command_confirm_write
, 0, data
, 1,
80 USB_CTRL_SET_TIMEOUT
);
88 * value of 3 seems to mean something like
89 * "not finished yet, but it looks good"
90 * So check again after a moment.
94 if (*data
== 1) { /* everything alright */
97 } else { /* unknown answer */
98 hid_err(usb_dev
, "got retval %d when checking write\n", *data
);
105 * Reads settings from mouse and stores it in @buf
106 * @buf has to be alloced with GFP_KERNEL
107 * On success returns 0
108 * On failure returns errno
110 static int kone_get_settings(struct usb_device
*usb_dev
,
111 struct kone_settings
*buf
)
115 len
= usb_control_msg(usb_dev
, usb_rcvctrlpipe(usb_dev
, 0),
116 USB_REQ_CLEAR_FEATURE
,
117 USB_TYPE_CLASS
| USB_RECIP_INTERFACE
| USB_DIR_IN
,
118 kone_command_settings
, 0, buf
,
119 sizeof(struct kone_settings
), USB_CTRL_SET_TIMEOUT
);
121 if (len
!= sizeof(struct kone_settings
))
128 * Writes settings from @buf to mouse
129 * On success returns 0
130 * On failure returns errno
132 static int kone_set_settings(struct usb_device
*usb_dev
,
133 struct kone_settings
const *settings
)
137 len
= usb_control_msg(usb_dev
, usb_sndctrlpipe(usb_dev
, 0),
138 USB_REQ_SET_CONFIGURATION
,
139 USB_TYPE_CLASS
| USB_RECIP_INTERFACE
| USB_DIR_OUT
,
140 kone_command_settings
, 0, (char *)settings
,
141 sizeof(struct kone_settings
),
142 USB_CTRL_SET_TIMEOUT
);
144 if (len
!= sizeof(struct kone_settings
))
147 if (kone_check_write(usb_dev
))
154 * Reads profile data from mouse and stores it in @buf
155 * @number: profile number to read
156 * On success returns 0
157 * On failure returns errno
159 static int kone_get_profile(struct usb_device
*usb_dev
,
160 struct kone_profile
*buf
, int number
)
164 if (number
< 1 || number
> 5)
167 len
= usb_control_msg(usb_dev
, usb_rcvctrlpipe(usb_dev
, 0),
168 USB_REQ_CLEAR_FEATURE
,
169 USB_TYPE_CLASS
| USB_RECIP_INTERFACE
| USB_DIR_IN
,
170 kone_command_profile
, number
, buf
,
171 sizeof(struct kone_profile
), USB_CTRL_SET_TIMEOUT
);
173 if (len
!= sizeof(struct kone_profile
))
180 * Writes profile data to mouse.
181 * @number: profile number to write
182 * On success returns 0
183 * On failure returns errno
185 static int kone_set_profile(struct usb_device
*usb_dev
,
186 struct kone_profile
const *profile
, int number
)
190 if (number
< 1 || number
> 5)
193 len
= usb_control_msg(usb_dev
, usb_sndctrlpipe(usb_dev
, 0),
194 USB_REQ_SET_CONFIGURATION
,
195 USB_TYPE_CLASS
| USB_RECIP_INTERFACE
| USB_DIR_OUT
,
196 kone_command_profile
, number
, (char *)profile
,
197 sizeof(struct kone_profile
),
198 USB_CTRL_SET_TIMEOUT
);
200 if (len
!= sizeof(struct kone_profile
))
203 if (kone_check_write(usb_dev
))
210 * Reads value of "fast-clip-weight" and stores it in @result
211 * On success returns 0
212 * On failure returns errno
214 static int kone_get_weight(struct usb_device
*usb_dev
, int *result
)
219 data
= kmalloc(1, GFP_KERNEL
);
223 len
= usb_control_msg(usb_dev
, usb_rcvctrlpipe(usb_dev
, 0),
224 USB_REQ_CLEAR_FEATURE
,
225 USB_TYPE_CLASS
| USB_RECIP_INTERFACE
| USB_DIR_IN
,
226 kone_command_weight
, 0, data
, 1, USB_CTRL_SET_TIMEOUT
);
232 *result
= (int)*data
;
238 * Reads firmware_version of mouse and stores it in @result
239 * On success returns 0
240 * On failure returns errno
242 static int kone_get_firmware_version(struct usb_device
*usb_dev
, int *result
)
247 data
= kmalloc(2, GFP_KERNEL
);
251 len
= usb_control_msg(usb_dev
, usb_rcvctrlpipe(usb_dev
, 0),
252 USB_REQ_CLEAR_FEATURE
,
253 USB_TYPE_CLASS
| USB_RECIP_INTERFACE
| USB_DIR_IN
,
254 kone_command_firmware_version
, 0, data
, 2,
255 USB_CTRL_SET_TIMEOUT
);
261 *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
) {
270 container_of(kobj
, struct device
, kobj
)->parent
->parent
;
271 struct kone_device
*kone
= hid_get_drvdata(dev_get_drvdata(dev
));
273 if (off
>= sizeof(struct kone_settings
))
276 if (off
+ count
> sizeof(struct kone_settings
))
277 count
= sizeof(struct kone_settings
) - off
;
279 mutex_lock(&kone
->kone_lock
);
280 memcpy(buf
, ((char const *)&kone
->settings
) + off
, count
);
281 mutex_unlock(&kone
->kone_lock
);
287 * Writing settings automatically activates startup_profile.
288 * This function keeps values in kone_device up to date and assumes that in
289 * case of error the old data is still valid
291 static ssize_t
kone_sysfs_write_settings(struct file
*fp
, struct kobject
*kobj
,
292 struct bin_attribute
*attr
, char *buf
,
293 loff_t off
, size_t count
) {
295 container_of(kobj
, struct device
, kobj
)->parent
->parent
;
296 struct kone_device
*kone
= hid_get_drvdata(dev_get_drvdata(dev
));
297 struct usb_device
*usb_dev
= interface_to_usbdev(to_usb_interface(dev
));
298 int retval
= 0, difference
;
300 /* I need to get my data in one piece */
301 if (off
!= 0 || count
!= sizeof(struct kone_settings
))
304 mutex_lock(&kone
->kone_lock
);
305 difference
= memcmp(buf
, &kone
->settings
, sizeof(struct kone_settings
));
307 retval
= kone_set_settings(usb_dev
,
308 (struct kone_settings
const *)buf
);
310 memcpy(&kone
->settings
, buf
,
311 sizeof(struct kone_settings
));
313 mutex_unlock(&kone
->kone_lock
);
319 * If we get here, treat settings as okay and update actual values
320 * according to startup_profile
322 kone
->actual_profile
= kone
->settings
.startup_profile
;
323 kone
->actual_dpi
= kone
->profiles
[kone
->actual_profile
- 1].startup_dpi
;
325 return sizeof(struct kone_settings
);
328 static ssize_t
kone_sysfs_read_profilex(struct file
*fp
,
329 struct kobject
*kobj
, struct bin_attribute
*attr
,
330 char *buf
, loff_t off
, size_t count
) {
332 container_of(kobj
, struct device
, kobj
)->parent
->parent
;
333 struct kone_device
*kone
= hid_get_drvdata(dev_get_drvdata(dev
));
335 if (off
>= sizeof(struct kone_profile
))
338 if (off
+ count
> sizeof(struct kone_profile
))
339 count
= sizeof(struct kone_profile
) - off
;
341 mutex_lock(&kone
->kone_lock
);
342 memcpy(buf
, ((char const *)&kone
->profiles
[*(uint
*)(attr
->private)]) + off
, count
);
343 mutex_unlock(&kone
->kone_lock
);
348 /* Writes data only if different to stored data */
349 static ssize_t
kone_sysfs_write_profilex(struct file
*fp
,
350 struct kobject
*kobj
, struct bin_attribute
*attr
,
351 char *buf
, loff_t off
, size_t count
) {
353 container_of(kobj
, struct device
, kobj
)->parent
->parent
;
354 struct kone_device
*kone
= hid_get_drvdata(dev_get_drvdata(dev
));
355 struct usb_device
*usb_dev
= interface_to_usbdev(to_usb_interface(dev
));
356 struct kone_profile
*profile
;
357 int retval
= 0, difference
;
359 /* I need to get my data in one piece */
360 if (off
!= 0 || count
!= sizeof(struct kone_profile
))
363 profile
= &kone
->profiles
[*(uint
*)(attr
->private)];
365 mutex_lock(&kone
->kone_lock
);
366 difference
= memcmp(buf
, profile
, sizeof(struct kone_profile
));
368 retval
= kone_set_profile(usb_dev
,
369 (struct kone_profile
const *)buf
,
370 *(uint
*)(attr
->private) + 1);
372 memcpy(profile
, buf
, sizeof(struct kone_profile
));
374 mutex_unlock(&kone
->kone_lock
);
379 return sizeof(struct kone_profile
);
382 static ssize_t
kone_sysfs_show_actual_profile(struct device
*dev
,
383 struct device_attribute
*attr
, char *buf
)
385 struct kone_device
*kone
=
386 hid_get_drvdata(dev_get_drvdata(dev
->parent
->parent
));
387 return snprintf(buf
, PAGE_SIZE
, "%d\n", kone
->actual_profile
);
390 static ssize_t
kone_sysfs_show_actual_dpi(struct device
*dev
,
391 struct device_attribute
*attr
, char *buf
)
393 struct kone_device
*kone
=
394 hid_get_drvdata(dev_get_drvdata(dev
->parent
->parent
));
395 return snprintf(buf
, PAGE_SIZE
, "%d\n", kone
->actual_dpi
);
398 /* weight is read each time, since we don't get informed when it's changed */
399 static ssize_t
kone_sysfs_show_weight(struct device
*dev
,
400 struct device_attribute
*attr
, char *buf
)
402 struct kone_device
*kone
;
403 struct usb_device
*usb_dev
;
407 dev
= dev
->parent
->parent
;
408 kone
= hid_get_drvdata(dev_get_drvdata(dev
));
409 usb_dev
= interface_to_usbdev(to_usb_interface(dev
));
411 mutex_lock(&kone
->kone_lock
);
412 retval
= kone_get_weight(usb_dev
, &weight
);
413 mutex_unlock(&kone
->kone_lock
);
417 return snprintf(buf
, PAGE_SIZE
, "%d\n", weight
);
420 static ssize_t
kone_sysfs_show_firmware_version(struct device
*dev
,
421 struct device_attribute
*attr
, char *buf
)
423 struct kone_device
*kone
=
424 hid_get_drvdata(dev_get_drvdata(dev
->parent
->parent
));
425 return snprintf(buf
, PAGE_SIZE
, "%d\n", kone
->firmware_version
);
428 static ssize_t
kone_sysfs_show_tcu(struct device
*dev
,
429 struct device_attribute
*attr
, char *buf
)
431 struct kone_device
*kone
=
432 hid_get_drvdata(dev_get_drvdata(dev
->parent
->parent
));
433 return snprintf(buf
, PAGE_SIZE
, "%d\n", kone
->settings
.tcu
);
436 static int kone_tcu_command(struct usb_device
*usb_dev
, int number
)
441 value
= kmalloc(1, GFP_KERNEL
);
447 len
= usb_control_msg(usb_dev
, usb_sndctrlpipe(usb_dev
, 0),
448 USB_REQ_SET_CONFIGURATION
,
449 USB_TYPE_CLASS
| USB_RECIP_INTERFACE
| USB_DIR_OUT
,
450 kone_command_calibrate
, 0, value
, 1,
451 USB_CTRL_SET_TIMEOUT
);
454 return ((len
!= 1) ? -EIO
: 0);
458 * Calibrating the tcu is the only action that changes settings data inside the
459 * mouse, so this data needs to be reread
461 static ssize_t
kone_sysfs_set_tcu(struct device
*dev
,
462 struct device_attribute
*attr
, char const *buf
, size_t size
)
464 struct kone_device
*kone
;
465 struct usb_device
*usb_dev
;
469 dev
= dev
->parent
->parent
;
470 kone
= hid_get_drvdata(dev_get_drvdata(dev
));
471 usb_dev
= interface_to_usbdev(to_usb_interface(dev
));
473 retval
= strict_strtoul(buf
, 10, &state
);
477 if (state
!= 0 && state
!= 1)
480 mutex_lock(&kone
->kone_lock
);
482 if (state
== 1) { /* state activate */
483 retval
= kone_tcu_command(usb_dev
, 1);
486 retval
= kone_tcu_command(usb_dev
, 2);
489 ssleep(5); /* tcu needs this time for calibration */
490 retval
= kone_tcu_command(usb_dev
, 3);
493 retval
= kone_tcu_command(usb_dev
, 0);
496 retval
= kone_tcu_command(usb_dev
, 4);
500 * Kone needs this time to settle things.
501 * Reading settings too early will result in invalid data.
502 * Roccat's driver waits 1 sec, maybe this time could be
508 /* calibration changes values in settings, so reread */
509 retval
= kone_get_settings(usb_dev
, &kone
->settings
);
511 goto exit_no_settings
;
513 /* only write settings back if activation state is different */
514 if (kone
->settings
.tcu
!= state
) {
515 kone
->settings
.tcu
= state
;
516 kone_set_settings_checksum(&kone
->settings
);
518 retval
= kone_set_settings(usb_dev
, &kone
->settings
);
520 hid_err(usb_dev
, "couldn't set tcu state\n");
522 * try to reread valid settings into buffer overwriting
525 retval
= kone_get_settings(usb_dev
, &kone
->settings
);
527 goto exit_no_settings
;
534 hid_err(usb_dev
, "couldn't read settings\n");
536 mutex_unlock(&kone
->kone_lock
);
540 static ssize_t
kone_sysfs_show_startup_profile(struct device
*dev
,
541 struct device_attribute
*attr
, char *buf
)
543 struct kone_device
*kone
=
544 hid_get_drvdata(dev_get_drvdata(dev
->parent
->parent
));
545 return snprintf(buf
, PAGE_SIZE
, "%d\n", kone
->settings
.startup_profile
);
548 static ssize_t
kone_sysfs_set_startup_profile(struct device
*dev
,
549 struct device_attribute
*attr
, char const *buf
, size_t size
)
551 struct kone_device
*kone
;
552 struct usb_device
*usb_dev
;
554 unsigned long new_startup_profile
;
556 dev
= dev
->parent
->parent
;
557 kone
= hid_get_drvdata(dev_get_drvdata(dev
));
558 usb_dev
= interface_to_usbdev(to_usb_interface(dev
));
560 retval
= strict_strtoul(buf
, 10, &new_startup_profile
);
564 if (new_startup_profile
< 1 || new_startup_profile
> 5)
567 mutex_lock(&kone
->kone_lock
);
569 kone
->settings
.startup_profile
= new_startup_profile
;
570 kone_set_settings_checksum(&kone
->settings
);
572 retval
= kone_set_settings(usb_dev
, &kone
->settings
);
574 mutex_unlock(&kone
->kone_lock
);
579 /* changing the startup profile immediately activates this profile */
580 kone
->actual_profile
= new_startup_profile
;
581 kone
->actual_dpi
= kone
->profiles
[kone
->actual_profile
- 1].startup_dpi
;
586 static struct device_attribute kone_attributes
[] = {
588 * Read actual dpi settings.
589 * Returns raw value for further processing. Refer to enum
590 * kone_polling_rates to get real value.
592 __ATTR(actual_dpi
, 0440, kone_sysfs_show_actual_dpi
, NULL
),
593 __ATTR(actual_profile
, 0440, kone_sysfs_show_actual_profile
, NULL
),
596 * The mouse can be equipped with one of four supplied weights from 5
597 * to 20 grams which are recognized and its value can be read out.
598 * This returns the raw value reported by the mouse for easy evaluation
599 * by software. Refer to enum kone_weights to get corresponding real
602 __ATTR(weight
, 0440, kone_sysfs_show_weight
, NULL
),
605 * Prints firmware version stored in mouse as integer.
606 * The raw value reported by the mouse is returned for easy evaluation,
607 * to get the real version number the decimal point has to be shifted 2
608 * positions to the left. E.g. a value of 138 means 1.38.
610 __ATTR(firmware_version
, 0440,
611 kone_sysfs_show_firmware_version
, NULL
),
614 * Prints state of Tracking Control Unit as number where 0 = off and
615 * 1 = on. Writing 0 deactivates tcu and writing 1 calibrates and
618 __ATTR(tcu
, 0660, kone_sysfs_show_tcu
, kone_sysfs_set_tcu
),
620 /* Prints and takes the number of the profile the mouse starts with */
621 __ATTR(startup_profile
, 0660,
622 kone_sysfs_show_startup_profile
,
623 kone_sysfs_set_startup_profile
),
627 static struct bin_attribute kone_bin_attributes
[] = {
629 .attr
= { .name
= "settings", .mode
= 0660 },
630 .size
= sizeof(struct kone_settings
),
631 .read
= kone_sysfs_read_settings
,
632 .write
= kone_sysfs_write_settings
635 .attr
= { .name
= "profile1", .mode
= 0660 },
636 .size
= sizeof(struct kone_profile
),
637 .read
= kone_sysfs_read_profilex
,
638 .write
= kone_sysfs_write_profilex
,
639 .private = &profile_numbers
[0]
642 .attr
= { .name
= "profile2", .mode
= 0660 },
643 .size
= sizeof(struct kone_profile
),
644 .read
= kone_sysfs_read_profilex
,
645 .write
= kone_sysfs_write_profilex
,
646 .private = &profile_numbers
[1]
649 .attr
= { .name
= "profile3", .mode
= 0660 },
650 .size
= sizeof(struct kone_profile
),
651 .read
= kone_sysfs_read_profilex
,
652 .write
= kone_sysfs_write_profilex
,
653 .private = &profile_numbers
[2]
656 .attr
= { .name
= "profile4", .mode
= 0660 },
657 .size
= sizeof(struct kone_profile
),
658 .read
= kone_sysfs_read_profilex
,
659 .write
= kone_sysfs_write_profilex
,
660 .private = &profile_numbers
[3]
663 .attr
= { .name
= "profile5", .mode
= 0660 },
664 .size
= sizeof(struct kone_profile
),
665 .read
= kone_sysfs_read_profilex
,
666 .write
= kone_sysfs_write_profilex
,
667 .private = &profile_numbers
[4]
672 static int kone_init_kone_device_struct(struct usb_device
*usb_dev
,
673 struct kone_device
*kone
)
678 mutex_init(&kone
->kone_lock
);
680 for (i
= 0; i
< 5; ++i
) {
681 retval
= kone_get_profile(usb_dev
, &kone
->profiles
[i
], i
+ 1);
686 retval
= kone_get_settings(usb_dev
, &kone
->settings
);
690 retval
= kone_get_firmware_version(usb_dev
, &kone
->firmware_version
);
694 kone
->actual_profile
= kone
->settings
.startup_profile
;
695 kone
->actual_dpi
= kone
->profiles
[kone
->actual_profile
].startup_dpi
;
701 * Since IGNORE_MOUSE quirk moved to hid-apple, there is no way to bind only to
702 * mousepart if usb_hid is compiled into the kernel and kone is compiled as
704 * Secial behaviour is bound only to mousepart since only mouseevents contain
705 * additional notifications.
707 static int kone_init_specials(struct hid_device
*hdev
)
709 struct usb_interface
*intf
= to_usb_interface(hdev
->dev
.parent
);
710 struct usb_device
*usb_dev
= interface_to_usbdev(intf
);
711 struct kone_device
*kone
;
714 if (intf
->cur_altsetting
->desc
.bInterfaceProtocol
715 == USB_INTERFACE_PROTOCOL_MOUSE
) {
717 kone
= kzalloc(sizeof(*kone
), GFP_KERNEL
);
719 hid_err(hdev
, "can't alloc device descriptor\n");
722 hid_set_drvdata(hdev
, kone
);
724 retval
= kone_init_kone_device_struct(usb_dev
, kone
);
726 hid_err(hdev
, "couldn't init struct kone_device\n");
730 retval
= roccat_connect(kone_class
, hdev
);
732 hid_err(hdev
, "couldn't init char dev\n");
733 /* be tolerant about not getting chrdev */
735 kone
->roccat_claimed
= 1;
736 kone
->chrdev_minor
= retval
;
739 hid_set_drvdata(hdev
, NULL
);
748 static void kone_remove_specials(struct hid_device
*hdev
)
750 struct usb_interface
*intf
= to_usb_interface(hdev
->dev
.parent
);
751 struct kone_device
*kone
;
753 if (intf
->cur_altsetting
->desc
.bInterfaceProtocol
754 == USB_INTERFACE_PROTOCOL_MOUSE
) {
755 kone
= hid_get_drvdata(hdev
);
756 if (kone
->roccat_claimed
)
757 roccat_disconnect(kone
->chrdev_minor
);
758 kfree(hid_get_drvdata(hdev
));
762 static int kone_probe(struct hid_device
*hdev
, const struct hid_device_id
*id
)
766 retval
= hid_parse(hdev
);
768 hid_err(hdev
, "parse failed\n");
772 retval
= hid_hw_start(hdev
, HID_CONNECT_DEFAULT
);
774 hid_err(hdev
, "hw start failed\n");
778 retval
= kone_init_specials(hdev
);
780 hid_err(hdev
, "couldn't install mouse\n");
792 static void kone_remove(struct hid_device
*hdev
)
794 kone_remove_specials(hdev
);
798 /* handle special events and keep actual profile and dpi values up to date */
799 static void kone_keep_values_up_to_date(struct kone_device
*kone
,
800 struct kone_mouse_event
const *event
)
802 switch (event
->event
) {
803 case kone_mouse_event_switch_profile
:
804 case kone_mouse_event_osd_profile
:
805 kone
->actual_profile
= event
->value
;
806 kone
->actual_dpi
= kone
->profiles
[kone
->actual_profile
- 1].
809 case kone_mouse_event_switch_dpi
:
810 case kone_mouse_event_osd_dpi
:
811 kone
->actual_dpi
= event
->value
;
816 static void kone_report_to_chrdev(struct kone_device
const *kone
,
817 struct kone_mouse_event
const *event
)
819 struct kone_roccat_report roccat_report
;
821 switch (event
->event
) {
822 case kone_mouse_event_switch_profile
:
823 case kone_mouse_event_switch_dpi
:
824 case kone_mouse_event_osd_profile
:
825 case kone_mouse_event_osd_dpi
:
826 roccat_report
.event
= event
->event
;
827 roccat_report
.value
= event
->value
;
828 roccat_report
.key
= 0;
829 roccat_report_event(kone
->chrdev_minor
,
830 (uint8_t *)&roccat_report
,
831 sizeof(struct kone_roccat_report
));
833 case kone_mouse_event_call_overlong_macro
:
834 if (event
->value
== kone_keystroke_action_press
) {
835 roccat_report
.event
= kone_mouse_event_call_overlong_macro
;
836 roccat_report
.value
= kone
->actual_profile
;
837 roccat_report
.key
= event
->macro_key
;
838 roccat_report_event(kone
->chrdev_minor
,
839 (uint8_t *)&roccat_report
,
840 sizeof(struct kone_roccat_report
));
848 * Is called for keyboard- and mousepart.
849 * Only mousepart gets informations about special events in its extended event
852 static int kone_raw_event(struct hid_device
*hdev
, struct hid_report
*report
,
855 struct kone_device
*kone
= hid_get_drvdata(hdev
);
856 struct kone_mouse_event
*event
= (struct kone_mouse_event
*)data
;
858 /* keyboard events are always processed by default handler */
859 if (size
!= sizeof(struct kone_mouse_event
))
863 * Firmware 1.38 introduced new behaviour for tilt and special buttons.
864 * Pressed button is reported in each movement event.
865 * Workaround sends only one event per press.
867 if (memcmp(&kone
->last_mouse_event
.tilt
, &event
->tilt
, 5))
868 memcpy(&kone
->last_mouse_event
, event
,
869 sizeof(struct kone_mouse_event
));
871 memset(&event
->tilt
, 0, 5);
873 kone_keep_values_up_to_date(kone
, event
);
875 if (kone
->roccat_claimed
)
876 kone_report_to_chrdev(kone
, event
);
878 return 0; /* always do further processing */
881 static const struct hid_device_id kone_devices
[] = {
882 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT
, USB_DEVICE_ID_ROCCAT_KONE
) },
886 MODULE_DEVICE_TABLE(hid
, kone_devices
);
888 static struct hid_driver kone_driver
= {
890 .id_table
= kone_devices
,
892 .remove
= kone_remove
,
893 .raw_event
= kone_raw_event
896 static int __init
kone_init(void)
900 /* class name has to be same as driver name */
901 kone_class
= class_create(THIS_MODULE
, "kone");
902 if (IS_ERR(kone_class
))
903 return PTR_ERR(kone_class
);
904 kone_class
->dev_attrs
= kone_attributes
;
905 kone_class
->dev_bin_attrs
= kone_bin_attributes
;
907 retval
= hid_register_driver(&kone_driver
);
909 class_destroy(kone_class
);
913 static void __exit
kone_exit(void)
915 class_destroy(kone_class
);
916 hid_unregister_driver(&kone_driver
);
919 module_init(kone_init
);
920 module_exit(kone_exit
);
922 MODULE_AUTHOR("Stefan Achatz");
923 MODULE_DESCRIPTION("USB Roccat Kone driver");
924 MODULE_LICENSE("GPL v2");