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 /* kone_class is used for creating sysfs attributes via roccat char device */
39 static struct class *kone_class;
41 static void kone_set_settings_checksum(struct kone_settings *settings)
43 uint16_t checksum = 0;
44 unsigned char *address = (unsigned char *)settings;
47 for (i = 0; i < sizeof(struct kone_settings) - 2; ++i, ++address)
49 settings->checksum = cpu_to_le16(checksum);
53 * Checks success after writing data to mouse
54 * On success returns 0
55 * On failure returns errno
57 static int kone_check_write(struct usb_device *usb_dev)
62 data = kmalloc(1, GFP_KERNEL);
68 * Mouse needs 50 msecs until it says ok, but there are
69 * 30 more msecs needed for next write to work.
73 len = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
74 USB_REQ_CLEAR_FEATURE,
75 USB_TYPE_CLASS | USB_RECIP_INTERFACE |
77 kone_command_confirm_write, 0, data, 1,
78 USB_CTRL_SET_TIMEOUT);
86 * value of 3 seems to mean something like
87 * "not finished yet, but it looks good"
88 * So check again after a moment.
92 if (*data == 1) { /* everything alright */
95 } else { /* unknown answer */
96 hid_err(usb_dev, "got retval %d when checking write\n", *data);
103 * Reads settings from mouse and stores it in @buf
104 * @buf has to be alloced with GFP_KERNEL
105 * On success returns 0
106 * On failure returns errno
108 static int kone_get_settings(struct usb_device *usb_dev,
109 struct kone_settings *buf)
113 len = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
114 USB_REQ_CLEAR_FEATURE,
115 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
116 kone_command_settings, 0, buf,
117 sizeof(struct kone_settings), USB_CTRL_SET_TIMEOUT);
119 if (len != sizeof(struct kone_settings))
126 * Writes settings from @buf to mouse
127 * On success returns 0
128 * On failure returns errno
130 static int kone_set_settings(struct usb_device *usb_dev,
131 struct kone_settings const *settings)
135 len = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
136 USB_REQ_SET_CONFIGURATION,
137 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
138 kone_command_settings, 0, (char *)settings,
139 sizeof(struct kone_settings),
140 USB_CTRL_SET_TIMEOUT);
142 if (len != sizeof(struct kone_settings))
145 if (kone_check_write(usb_dev))
152 * Reads profile data from mouse and stores it in @buf
153 * @number: profile number to read
154 * On success returns 0
155 * On failure returns errno
157 static int kone_get_profile(struct usb_device *usb_dev,
158 struct kone_profile *buf, int number)
162 if (number < 1 || number > 5)
165 len = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
166 USB_REQ_CLEAR_FEATURE,
167 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
168 kone_command_profile, number, buf,
169 sizeof(struct kone_profile), USB_CTRL_SET_TIMEOUT);
171 if (len != sizeof(struct kone_profile))
178 * Writes profile data to mouse.
179 * @number: profile number to write
180 * On success returns 0
181 * On failure returns errno
183 static int kone_set_profile(struct usb_device *usb_dev,
184 struct kone_profile const *profile, int number)
188 if (number < 1 || number > 5)
191 len = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
192 USB_REQ_SET_CONFIGURATION,
193 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
194 kone_command_profile, number, (char *)profile,
195 sizeof(struct kone_profile),
196 USB_CTRL_SET_TIMEOUT);
198 if (len != sizeof(struct kone_profile))
201 if (kone_check_write(usb_dev))
208 * Reads value of "fast-clip-weight" and stores it in @result
209 * On success returns 0
210 * On failure returns errno
212 static int kone_get_weight(struct usb_device *usb_dev, int *result)
217 data = kmalloc(1, GFP_KERNEL);
221 len = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
222 USB_REQ_CLEAR_FEATURE,
223 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
224 kone_command_weight, 0, data, 1, USB_CTRL_SET_TIMEOUT);
230 *result = (int)*data;
236 * Reads firmware_version of mouse and stores it in @result
237 * On success returns 0
238 * On failure returns errno
240 static int kone_get_firmware_version(struct usb_device *usb_dev, int *result)
245 data = kmalloc(2, GFP_KERNEL);
249 len = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
250 USB_REQ_CLEAR_FEATURE,
251 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
252 kone_command_firmware_version, 0, data, 2,
253 USB_CTRL_SET_TIMEOUT);
259 *result = le16_to_cpu(*data);
264 static ssize_t kone_sysfs_read_settings(struct file *fp, struct kobject *kobj,
265 struct bin_attribute *attr, char *buf,
266 loff_t off, size_t count) {
268 container_of(kobj, struct device, kobj)->parent->parent;
269 struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev));
271 if (off >= sizeof(struct kone_settings))
274 if (off + count > sizeof(struct kone_settings))
275 count = sizeof(struct kone_settings) - off;
277 mutex_lock(&kone->kone_lock);
278 memcpy(buf, ((char const *)&kone->settings) + off, count);
279 mutex_unlock(&kone->kone_lock);
285 * Writing settings automatically activates startup_profile.
286 * This function keeps values in kone_device up to date and assumes that in
287 * case of error the old data is still valid
289 static ssize_t kone_sysfs_write_settings(struct file *fp, struct kobject *kobj,
290 struct bin_attribute *attr, char *buf,
291 loff_t off, size_t count) {
293 container_of(kobj, struct device, 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;
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 memcpy(&kone->settings, buf,
309 sizeof(struct kone_settings));
311 mutex_unlock(&kone->kone_lock);
317 * If we get here, treat settings as okay and update actual values
318 * according to startup_profile
320 kone->actual_profile = kone->settings.startup_profile;
321 kone->actual_dpi = kone->profiles[kone->actual_profile - 1].startup_dpi;
323 return sizeof(struct kone_settings);
326 static ssize_t kone_sysfs_read_profilex(struct kobject *kobj,
327 struct bin_attribute *attr, char *buf,
328 loff_t off, size_t count, int number) {
330 container_of(kobj, struct device, 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[number - 1]) + off, count);
341 mutex_unlock(&kone->kone_lock);
346 static ssize_t kone_sysfs_read_profile1(struct file *fp, struct kobject *kobj,
347 struct bin_attribute *attr, char *buf,
348 loff_t off, size_t count) {
349 return kone_sysfs_read_profilex(kobj, attr, buf, off, count, 1);
352 static ssize_t kone_sysfs_read_profile2(struct file *fp, struct kobject *kobj,
353 struct bin_attribute *attr, char *buf,
354 loff_t off, size_t count) {
355 return kone_sysfs_read_profilex(kobj, attr, buf, off, count, 2);
358 static ssize_t kone_sysfs_read_profile3(struct file *fp, struct kobject *kobj,
359 struct bin_attribute *attr, char *buf,
360 loff_t off, size_t count) {
361 return kone_sysfs_read_profilex(kobj, attr, buf, off, count, 3);
364 static ssize_t kone_sysfs_read_profile4(struct file *fp, struct kobject *kobj,
365 struct bin_attribute *attr, char *buf,
366 loff_t off, size_t count) {
367 return kone_sysfs_read_profilex(kobj, attr, buf, off, count, 4);
370 static ssize_t kone_sysfs_read_profile5(struct file *fp, struct kobject *kobj,
371 struct bin_attribute *attr, char *buf,
372 loff_t off, size_t count) {
373 return kone_sysfs_read_profilex(kobj, attr, buf, off, count, 5);
376 /* Writes data only if different to stored data */
377 static ssize_t kone_sysfs_write_profilex(struct kobject *kobj,
378 struct bin_attribute *attr, char *buf,
379 loff_t off, size_t count, int number) {
381 container_of(kobj, struct device, kobj)->parent->parent;
382 struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev));
383 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
384 struct kone_profile *profile;
385 int retval = 0, difference;
387 /* I need to get my data in one piece */
388 if (off != 0 || count != sizeof(struct kone_profile))
391 profile = &kone->profiles[number - 1];
393 mutex_lock(&kone->kone_lock);
394 difference = memcmp(buf, profile, sizeof(struct kone_profile));
396 retval = kone_set_profile(usb_dev,
397 (struct kone_profile const *)buf, number);
399 memcpy(profile, buf, sizeof(struct kone_profile));
401 mutex_unlock(&kone->kone_lock);
406 return sizeof(struct kone_profile);
409 static ssize_t kone_sysfs_write_profile1(struct file *fp, struct kobject *kobj,
410 struct bin_attribute *attr, char *buf,
411 loff_t off, size_t count) {
412 return kone_sysfs_write_profilex(kobj, attr, buf, off, count, 1);
415 static ssize_t kone_sysfs_write_profile2(struct file *fp, struct kobject *kobj,
416 struct bin_attribute *attr, char *buf,
417 loff_t off, size_t count) {
418 return kone_sysfs_write_profilex(kobj, attr, buf, off, count, 2);
421 static ssize_t kone_sysfs_write_profile3(struct file *fp, struct kobject *kobj,
422 struct bin_attribute *attr, char *buf,
423 loff_t off, size_t count) {
424 return kone_sysfs_write_profilex(kobj, attr, buf, off, count, 3);
427 static ssize_t kone_sysfs_write_profile4(struct file *fp, struct kobject *kobj,
428 struct bin_attribute *attr, char *buf,
429 loff_t off, size_t count) {
430 return kone_sysfs_write_profilex(kobj, attr, buf, off, count, 4);
433 static ssize_t kone_sysfs_write_profile5(struct file *fp, struct kobject *kobj,
434 struct bin_attribute *attr, char *buf,
435 loff_t off, size_t count) {
436 return kone_sysfs_write_profilex(kobj, attr, buf, off, count, 5);
439 static ssize_t kone_sysfs_show_actual_profile(struct device *dev,
440 struct device_attribute *attr, char *buf)
442 struct kone_device *kone =
443 hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
444 return snprintf(buf, PAGE_SIZE, "%d\n", kone->actual_profile);
447 static ssize_t kone_sysfs_show_actual_dpi(struct device *dev,
448 struct device_attribute *attr, char *buf)
450 struct kone_device *kone =
451 hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
452 return snprintf(buf, PAGE_SIZE, "%d\n", kone->actual_dpi);
455 /* weight is read each time, since we don't get informed when it's changed */
456 static ssize_t kone_sysfs_show_weight(struct device *dev,
457 struct device_attribute *attr, char *buf)
459 struct kone_device *kone;
460 struct usb_device *usb_dev;
464 dev = dev->parent->parent;
465 kone = hid_get_drvdata(dev_get_drvdata(dev));
466 usb_dev = interface_to_usbdev(to_usb_interface(dev));
468 mutex_lock(&kone->kone_lock);
469 retval = kone_get_weight(usb_dev, &weight);
470 mutex_unlock(&kone->kone_lock);
474 return snprintf(buf, PAGE_SIZE, "%d\n", weight);
477 static ssize_t kone_sysfs_show_firmware_version(struct device *dev,
478 struct device_attribute *attr, char *buf)
480 struct kone_device *kone =
481 hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
482 return snprintf(buf, PAGE_SIZE, "%d\n", kone->firmware_version);
485 static ssize_t kone_sysfs_show_tcu(struct device *dev,
486 struct device_attribute *attr, char *buf)
488 struct kone_device *kone =
489 hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
490 return snprintf(buf, PAGE_SIZE, "%d\n", kone->settings.tcu);
493 static int kone_tcu_command(struct usb_device *usb_dev, int number)
498 value = kmalloc(1, GFP_KERNEL);
504 len = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
505 USB_REQ_SET_CONFIGURATION,
506 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
507 kone_command_calibrate, 0, value, 1,
508 USB_CTRL_SET_TIMEOUT);
511 return ((len != 1) ? -EIO : 0);
515 * Calibrating the tcu is the only action that changes settings data inside the
516 * mouse, so this data needs to be reread
518 static ssize_t kone_sysfs_set_tcu(struct device *dev,
519 struct device_attribute *attr, char const *buf, size_t size)
521 struct kone_device *kone;
522 struct usb_device *usb_dev;
526 dev = dev->parent->parent;
527 kone = hid_get_drvdata(dev_get_drvdata(dev));
528 usb_dev = interface_to_usbdev(to_usb_interface(dev));
530 retval = strict_strtoul(buf, 10, &state);
534 if (state != 0 && state != 1)
537 mutex_lock(&kone->kone_lock);
539 if (state == 1) { /* state activate */
540 retval = kone_tcu_command(usb_dev, 1);
543 retval = kone_tcu_command(usb_dev, 2);
546 ssleep(5); /* tcu needs this time for calibration */
547 retval = kone_tcu_command(usb_dev, 3);
550 retval = kone_tcu_command(usb_dev, 0);
553 retval = kone_tcu_command(usb_dev, 4);
557 * Kone needs this time to settle things.
558 * Reading settings too early will result in invalid data.
559 * Roccat's driver waits 1 sec, maybe this time could be
565 /* calibration changes values in settings, so reread */
566 retval = kone_get_settings(usb_dev, &kone->settings);
568 goto exit_no_settings;
570 /* only write settings back if activation state is different */
571 if (kone->settings.tcu != state) {
572 kone->settings.tcu = state;
573 kone_set_settings_checksum(&kone->settings);
575 retval = kone_set_settings(usb_dev, &kone->settings);
577 hid_err(usb_dev, "couldn't set tcu state\n");
579 * try to reread valid settings into buffer overwriting
582 retval = kone_get_settings(usb_dev, &kone->settings);
584 goto exit_no_settings;
591 hid_err(usb_dev, "couldn't read settings\n");
593 mutex_unlock(&kone->kone_lock);
597 static ssize_t kone_sysfs_show_startup_profile(struct device *dev,
598 struct device_attribute *attr, char *buf)
600 struct kone_device *kone =
601 hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
602 return snprintf(buf, PAGE_SIZE, "%d\n", kone->settings.startup_profile);
605 static ssize_t kone_sysfs_set_startup_profile(struct device *dev,
606 struct device_attribute *attr, char const *buf, size_t size)
608 struct kone_device *kone;
609 struct usb_device *usb_dev;
611 unsigned long new_startup_profile;
613 dev = dev->parent->parent;
614 kone = hid_get_drvdata(dev_get_drvdata(dev));
615 usb_dev = interface_to_usbdev(to_usb_interface(dev));
617 retval = strict_strtoul(buf, 10, &new_startup_profile);
621 if (new_startup_profile < 1 || new_startup_profile > 5)
624 mutex_lock(&kone->kone_lock);
626 kone->settings.startup_profile = new_startup_profile;
627 kone_set_settings_checksum(&kone->settings);
629 retval = kone_set_settings(usb_dev, &kone->settings);
631 mutex_unlock(&kone->kone_lock);
636 /* changing the startup profile immediately activates this profile */
637 kone->actual_profile = new_startup_profile;
638 kone->actual_dpi = kone->profiles[kone->actual_profile - 1].startup_dpi;
643 static struct device_attribute kone_attributes[] = {
645 * Read actual dpi settings.
646 * Returns raw value for further processing. Refer to enum
647 * kone_polling_rates to get real value.
649 __ATTR(actual_dpi, 0440, kone_sysfs_show_actual_dpi, NULL),
650 __ATTR(actual_profile, 0440, kone_sysfs_show_actual_profile, NULL),
653 * The mouse can be equipped with one of four supplied weights from 5
654 * to 20 grams which are recognized and its value can be read out.
655 * This returns the raw value reported by the mouse for easy evaluation
656 * by software. Refer to enum kone_weights to get corresponding real
659 __ATTR(weight, 0440, kone_sysfs_show_weight, NULL),
662 * Prints firmware version stored in mouse as integer.
663 * The raw value reported by the mouse is returned for easy evaluation,
664 * to get the real version number the decimal point has to be shifted 2
665 * positions to the left. E.g. a value of 138 means 1.38.
667 __ATTR(firmware_version, 0440,
668 kone_sysfs_show_firmware_version, NULL),
671 * Prints state of Tracking Control Unit as number where 0 = off and
672 * 1 = on. Writing 0 deactivates tcu and writing 1 calibrates and
675 __ATTR(tcu, 0660, kone_sysfs_show_tcu, kone_sysfs_set_tcu),
677 /* Prints and takes the number of the profile the mouse starts with */
678 __ATTR(startup_profile, 0660,
679 kone_sysfs_show_startup_profile,
680 kone_sysfs_set_startup_profile),
684 static struct bin_attribute kone_bin_attributes[] = {
686 .attr = { .name = "settings", .mode = 0660 },
687 .size = sizeof(struct kone_settings),
688 .read = kone_sysfs_read_settings,
689 .write = kone_sysfs_write_settings
692 .attr = { .name = "profile1", .mode = 0660 },
693 .size = sizeof(struct kone_profile),
694 .read = kone_sysfs_read_profile1,
695 .write = kone_sysfs_write_profile1
698 .attr = { .name = "profile2", .mode = 0660 },
699 .size = sizeof(struct kone_profile),
700 .read = kone_sysfs_read_profile2,
701 .write = kone_sysfs_write_profile2
704 .attr = { .name = "profile3", .mode = 0660 },
705 .size = sizeof(struct kone_profile),
706 .read = kone_sysfs_read_profile3,
707 .write = kone_sysfs_write_profile3
710 .attr = { .name = "profile4", .mode = 0660 },
711 .size = sizeof(struct kone_profile),
712 .read = kone_sysfs_read_profile4,
713 .write = kone_sysfs_write_profile4
716 .attr = { .name = "profile5", .mode = 0660 },
717 .size = sizeof(struct kone_profile),
718 .read = kone_sysfs_read_profile5,
719 .write = kone_sysfs_write_profile5
724 static int kone_init_kone_device_struct(struct usb_device *usb_dev,
725 struct kone_device *kone)
730 mutex_init(&kone->kone_lock);
732 for (i = 0; i < 5; ++i) {
733 retval = kone_get_profile(usb_dev, &kone->profiles[i], i + 1);
738 retval = kone_get_settings(usb_dev, &kone->settings);
742 retval = kone_get_firmware_version(usb_dev, &kone->firmware_version);
746 kone->actual_profile = kone->settings.startup_profile;
747 kone->actual_dpi = kone->profiles[kone->actual_profile].startup_dpi;
753 * Since IGNORE_MOUSE quirk moved to hid-apple, there is no way to bind only to
754 * mousepart if usb_hid is compiled into the kernel and kone is compiled as
756 * Secial behaviour is bound only to mousepart since only mouseevents contain
757 * additional notifications.
759 static int kone_init_specials(struct hid_device *hdev)
761 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
762 struct usb_device *usb_dev = interface_to_usbdev(intf);
763 struct kone_device *kone;
766 if (intf->cur_altsetting->desc.bInterfaceProtocol
767 == USB_INTERFACE_PROTOCOL_MOUSE) {
769 kone = kzalloc(sizeof(*kone), GFP_KERNEL);
771 hid_err(hdev, "can't alloc device descriptor\n");
774 hid_set_drvdata(hdev, kone);
776 retval = kone_init_kone_device_struct(usb_dev, kone);
778 hid_err(hdev, "couldn't init struct kone_device\n");
782 retval = roccat_connect(kone_class, hdev);
784 hid_err(hdev, "couldn't init char dev\n");
785 /* be tolerant about not getting chrdev */
787 kone->roccat_claimed = 1;
788 kone->chrdev_minor = retval;
791 hid_set_drvdata(hdev, NULL);
800 static void kone_remove_specials(struct hid_device *hdev)
802 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
803 struct kone_device *kone;
805 if (intf->cur_altsetting->desc.bInterfaceProtocol
806 == USB_INTERFACE_PROTOCOL_MOUSE) {
807 kone = hid_get_drvdata(hdev);
808 if (kone->roccat_claimed)
809 roccat_disconnect(kone->chrdev_minor);
810 kfree(hid_get_drvdata(hdev));
814 static int kone_probe(struct hid_device *hdev, const struct hid_device_id *id)
818 retval = hid_parse(hdev);
820 hid_err(hdev, "parse failed\n");
824 retval = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
826 hid_err(hdev, "hw start failed\n");
830 retval = kone_init_specials(hdev);
832 hid_err(hdev, "couldn't install mouse\n");
844 static void kone_remove(struct hid_device *hdev)
846 kone_remove_specials(hdev);
850 /* handle special events and keep actual profile and dpi values up to date */
851 static void kone_keep_values_up_to_date(struct kone_device *kone,
852 struct kone_mouse_event const *event)
854 switch (event->event) {
855 case kone_mouse_event_switch_profile:
856 case kone_mouse_event_osd_profile:
857 kone->actual_profile = event->value;
858 kone->actual_dpi = kone->profiles[kone->actual_profile - 1].
861 case kone_mouse_event_switch_dpi:
862 case kone_mouse_event_osd_dpi:
863 kone->actual_dpi = event->value;
868 static void kone_report_to_chrdev(struct kone_device const *kone,
869 struct kone_mouse_event const *event)
871 struct kone_roccat_report roccat_report;
873 switch (event->event) {
874 case kone_mouse_event_switch_profile:
875 case kone_mouse_event_switch_dpi:
876 case kone_mouse_event_osd_profile:
877 case kone_mouse_event_osd_dpi:
878 roccat_report.event = event->event;
879 roccat_report.value = event->value;
880 roccat_report.key = 0;
881 roccat_report_event(kone->chrdev_minor,
882 (uint8_t *)&roccat_report,
883 sizeof(struct kone_roccat_report));
885 case kone_mouse_event_call_overlong_macro:
886 if (event->value == kone_keystroke_action_press) {
887 roccat_report.event = kone_mouse_event_call_overlong_macro;
888 roccat_report.value = kone->actual_profile;
889 roccat_report.key = event->macro_key;
890 roccat_report_event(kone->chrdev_minor,
891 (uint8_t *)&roccat_report,
892 sizeof(struct kone_roccat_report));
900 * Is called for keyboard- and mousepart.
901 * Only mousepart gets informations about special events in its extended event
904 static int kone_raw_event(struct hid_device *hdev, struct hid_report *report,
907 struct kone_device *kone = hid_get_drvdata(hdev);
908 struct kone_mouse_event *event = (struct kone_mouse_event *)data;
910 /* keyboard events are always processed by default handler */
911 if (size != sizeof(struct kone_mouse_event))
915 * Firmware 1.38 introduced new behaviour for tilt and special buttons.
916 * Pressed button is reported in each movement event.
917 * Workaround sends only one event per press.
919 if (memcmp(&kone->last_mouse_event.tilt, &event->tilt, 5))
920 memcpy(&kone->last_mouse_event, event,
921 sizeof(struct kone_mouse_event));
923 memset(&event->tilt, 0, 5);
925 kone_keep_values_up_to_date(kone, event);
927 if (kone->roccat_claimed)
928 kone_report_to_chrdev(kone, event);
930 return 0; /* always do further processing */
933 static const struct hid_device_id kone_devices[] = {
934 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONE) },
938 MODULE_DEVICE_TABLE(hid, kone_devices);
940 static struct hid_driver kone_driver = {
942 .id_table = kone_devices,
944 .remove = kone_remove,
945 .raw_event = kone_raw_event
948 static int __init kone_init(void)
952 /* class name has to be same as driver name */
953 kone_class = class_create(THIS_MODULE, "kone");
954 if (IS_ERR(kone_class))
955 return PTR_ERR(kone_class);
956 kone_class->dev_attrs = kone_attributes;
957 kone_class->dev_bin_attrs = kone_bin_attributes;
959 retval = hid_register_driver(&kone_driver);
961 class_destroy(kone_class);
965 static void __exit kone_exit(void)
967 class_destroy(kone_class);
968 hid_unregister_driver(&kone_driver);
971 module_init(kone_init);
972 module_exit(kone_exit);
974 MODULE_AUTHOR("Stefan Achatz");
975 MODULE_DESCRIPTION("USB Roccat Kone driver");
976 MODULE_LICENSE("GPL v2");