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 implement notification mechanism for overlong macro execution
26 * If user wants to execute an overlong macro only the names of macroset
27 * and macro are given. Should userland tap hidraw or is there an
28 * additional streaming mechanism?
30 * TODO is it possible to overwrite group for sysfs attributes via udev?
33 #include <linux/device.h>
34 #include <linux/input.h>
35 #include <linux/hid.h>
36 #include <linux/usb.h>
37 #include <linux/module.h>
39 #include "hid-roccat-kone.h"
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 dev_err(&usb_dev->dev, "got retval %d when checking write\n",
104 * Reads settings from mouse and stores it in @buf
105 * @buf has to be alloced with GFP_KERNEL
106 * On success returns 0
107 * On failure returns errno
109 static int kone_get_settings(struct usb_device *usb_dev,
110 struct kone_settings *buf)
114 len = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
115 USB_REQ_CLEAR_FEATURE,
116 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
117 kone_command_settings, 0, buf,
118 sizeof(struct kone_settings), USB_CTRL_SET_TIMEOUT);
120 if (len != sizeof(struct kone_settings))
127 * Writes settings from @buf to mouse
128 * On success returns 0
129 * On failure returns errno
131 static int kone_set_settings(struct usb_device *usb_dev,
132 struct kone_settings const *settings)
136 len = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
137 USB_REQ_SET_CONFIGURATION,
138 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
139 kone_command_settings, 0, (char *)settings,
140 sizeof(struct kone_settings),
141 USB_CTRL_SET_TIMEOUT);
143 if (len != sizeof(struct kone_settings))
146 if (kone_check_write(usb_dev))
153 * Reads profile data from mouse and stores it in @buf
154 * @number: profile number to read
155 * On success returns 0
156 * On failure returns errno
158 static int kone_get_profile(struct usb_device *usb_dev,
159 struct kone_profile *buf, int number)
163 if (number < 1 || number > 5)
166 len = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
167 USB_REQ_CLEAR_FEATURE,
168 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
169 kone_command_profile, number, buf,
170 sizeof(struct kone_profile), USB_CTRL_SET_TIMEOUT);
172 if (len != sizeof(struct kone_profile))
179 * Writes profile data to mouse.
180 * @number: profile number to write
181 * On success returns 0
182 * On failure returns errno
184 static int kone_set_profile(struct usb_device *usb_dev,
185 struct kone_profile const *profile, int number)
189 if (number < 1 || number > 5)
192 len = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
193 USB_REQ_SET_CONFIGURATION,
194 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
195 kone_command_profile, number, (char *)profile,
196 sizeof(struct kone_profile),
197 USB_CTRL_SET_TIMEOUT);
199 if (len != sizeof(struct kone_profile))
202 if (kone_check_write(usb_dev))
209 * Reads value of "fast-clip-weight" and stores it in @result
210 * On success returns 0
211 * On failure returns errno
213 static int kone_get_weight(struct usb_device *usb_dev, int *result)
218 data = kmalloc(1, GFP_KERNEL);
222 len = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
223 USB_REQ_CLEAR_FEATURE,
224 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
225 kone_command_weight, 0, data, 1, USB_CTRL_SET_TIMEOUT);
231 *result = (int)*data;
237 * Reads firmware_version of mouse and stores it in @result
238 * On success returns 0
239 * On failure returns errno
241 static int kone_get_firmware_version(struct usb_device *usb_dev, int *result)
246 data = kmalloc(2, GFP_KERNEL);
250 len = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
251 USB_REQ_CLEAR_FEATURE,
252 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
253 kone_command_firmware_version, 0, data, 2,
254 USB_CTRL_SET_TIMEOUT);
260 *result = le16_to_cpu(*data);
265 static ssize_t kone_sysfs_read_settings(struct kobject *kobj,
266 struct bin_attribute *attr, char *buf,
267 loff_t off, size_t count) {
268 struct device *dev = container_of(kobj, struct device, kobj);
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, &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 kobject *kobj,
290 struct bin_attribute *attr, char *buf,
291 loff_t off, size_t count) {
292 struct device *dev = container_of(kobj, struct device, kobj);
293 struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev));
294 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
295 int retval = 0, difference;
297 /* I need to get my data in one piece */
298 if (off != 0 || count != sizeof(struct kone_settings))
301 mutex_lock(&kone->kone_lock);
302 difference = memcmp(buf, &kone->settings, sizeof(struct kone_settings));
304 retval = kone_set_settings(usb_dev,
305 (struct kone_settings const *)buf);
307 memcpy(&kone->settings, buf,
308 sizeof(struct kone_settings));
310 mutex_unlock(&kone->kone_lock);
316 * If we get here, treat settings as okay and update actual values
317 * according to startup_profile
319 kone->actual_profile = kone->settings.startup_profile;
320 kone->actual_dpi = kone->profiles[kone->actual_profile - 1].startup_dpi;
322 return sizeof(struct kone_settings);
325 static ssize_t kone_sysfs_read_profilex(struct kobject *kobj,
326 struct bin_attribute *attr, char *buf,
327 loff_t off, size_t count, int number) {
328 struct device *dev = container_of(kobj, struct device, kobj);
329 struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev));
331 if (off >= sizeof(struct kone_profile))
334 if (off + count > sizeof(struct kone_profile))
335 count = sizeof(struct kone_profile) - off;
337 mutex_lock(&kone->kone_lock);
338 memcpy(buf, &kone->profiles[number - 1], sizeof(struct kone_profile));
339 mutex_unlock(&kone->kone_lock);
344 static ssize_t kone_sysfs_read_profile1(struct kobject *kobj,
345 struct bin_attribute *attr, char *buf,
346 loff_t off, size_t count) {
347 return kone_sysfs_read_profilex(kobj, attr, buf, off, count, 1);
350 static ssize_t kone_sysfs_read_profile2(struct kobject *kobj,
351 struct bin_attribute *attr, char *buf,
352 loff_t off, size_t count) {
353 return kone_sysfs_read_profilex(kobj, attr, buf, off, count, 2);
356 static ssize_t kone_sysfs_read_profile3(struct kobject *kobj,
357 struct bin_attribute *attr, char *buf,
358 loff_t off, size_t count) {
359 return kone_sysfs_read_profilex(kobj, attr, buf, off, count, 3);
362 static ssize_t kone_sysfs_read_profile4(struct kobject *kobj,
363 struct bin_attribute *attr, char *buf,
364 loff_t off, size_t count) {
365 return kone_sysfs_read_profilex(kobj, attr, buf, off, count, 4);
368 static ssize_t kone_sysfs_read_profile5(struct kobject *kobj,
369 struct bin_attribute *attr, char *buf,
370 loff_t off, size_t count) {
371 return kone_sysfs_read_profilex(kobj, attr, buf, off, count, 5);
374 /* Writes data only if different to stored data */
375 static ssize_t kone_sysfs_write_profilex(struct kobject *kobj,
376 struct bin_attribute *attr, char *buf,
377 loff_t off, size_t count, int number) {
378 struct device *dev = container_of(kobj, struct device, kobj);
379 struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev));
380 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
381 struct kone_profile *profile;
382 int retval = 0, difference;
384 /* I need to get my data in one piece */
385 if (off != 0 || count != sizeof(struct kone_profile))
388 profile = &kone->profiles[number - 1];
390 mutex_lock(&kone->kone_lock);
391 difference = memcmp(buf, profile, sizeof(struct kone_profile));
393 retval = kone_set_profile(usb_dev,
394 (struct kone_profile const *)buf, number);
396 memcpy(profile, buf, sizeof(struct kone_profile));
398 mutex_unlock(&kone->kone_lock);
403 return sizeof(struct kone_profile);
406 static ssize_t kone_sysfs_write_profile1(struct kobject *kobj,
407 struct bin_attribute *attr, char *buf,
408 loff_t off, size_t count) {
409 return kone_sysfs_write_profilex(kobj, attr, buf, off, count, 1);
412 static ssize_t kone_sysfs_write_profile2(struct kobject *kobj,
413 struct bin_attribute *attr, char *buf,
414 loff_t off, size_t count) {
415 return kone_sysfs_write_profilex(kobj, attr, buf, off, count, 2);
418 static ssize_t kone_sysfs_write_profile3(struct kobject *kobj,
419 struct bin_attribute *attr, char *buf,
420 loff_t off, size_t count) {
421 return kone_sysfs_write_profilex(kobj, attr, buf, off, count, 3);
424 static ssize_t kone_sysfs_write_profile4(struct kobject *kobj,
425 struct bin_attribute *attr, char *buf,
426 loff_t off, size_t count) {
427 return kone_sysfs_write_profilex(kobj, attr, buf, off, count, 4);
430 static ssize_t kone_sysfs_write_profile5(struct kobject *kobj,
431 struct bin_attribute *attr, char *buf,
432 loff_t off, size_t count) {
433 return kone_sysfs_write_profilex(kobj, attr, buf, off, count, 5);
436 static ssize_t kone_sysfs_show_actual_profile(struct device *dev,
437 struct device_attribute *attr, char *buf)
439 struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev));
440 return snprintf(buf, PAGE_SIZE, "%d\n", kone->actual_profile);
443 static ssize_t kone_sysfs_show_actual_dpi(struct device *dev,
444 struct device_attribute *attr, char *buf)
446 struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev));
447 return snprintf(buf, PAGE_SIZE, "%d\n", kone->actual_dpi);
450 /* weight is read each time, since we don't get informed when it's changed */
451 static ssize_t kone_sysfs_show_weight(struct device *dev,
452 struct device_attribute *attr, char *buf)
454 struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev));
455 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
459 mutex_lock(&kone->kone_lock);
460 retval = kone_get_weight(usb_dev, &weight);
461 mutex_unlock(&kone->kone_lock);
465 return snprintf(buf, PAGE_SIZE, "%d\n", weight);
468 static ssize_t kone_sysfs_show_firmware_version(struct device *dev,
469 struct device_attribute *attr, char *buf)
471 struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev));
472 return snprintf(buf, PAGE_SIZE, "%d\n", kone->firmware_version);
475 static ssize_t kone_sysfs_show_tcu(struct device *dev,
476 struct device_attribute *attr, char *buf)
478 struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev));
479 return snprintf(buf, PAGE_SIZE, "%d\n", kone->settings.tcu);
482 static int kone_tcu_command(struct usb_device *usb_dev, int number)
487 value = kmalloc(1, GFP_KERNEL);
493 len = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
494 USB_REQ_SET_CONFIGURATION,
495 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
496 kone_command_calibrate, 0, value, 1,
497 USB_CTRL_SET_TIMEOUT);
500 return ((len != 1) ? -EIO : 0);
504 * Calibrating the tcu is the only action that changes settings data inside the
505 * mouse, so this data needs to be reread
507 static ssize_t kone_sysfs_set_tcu(struct device *dev,
508 struct device_attribute *attr, char const *buf, size_t size)
510 struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev));
511 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
515 retval = strict_strtoul(buf, 10, &state);
519 if (state != 0 && state != 1)
522 mutex_lock(&kone->kone_lock);
524 if (state == 1) { /* state activate */
525 retval = kone_tcu_command(usb_dev, 1);
528 retval = kone_tcu_command(usb_dev, 2);
531 ssleep(5); /* tcu needs this time for calibration */
532 retval = kone_tcu_command(usb_dev, 3);
535 retval = kone_tcu_command(usb_dev, 0);
538 retval = kone_tcu_command(usb_dev, 4);
542 * Kone needs this time to settle things.
543 * Reading settings too early will result in invalid data.
544 * Roccat's driver waits 1 sec, maybe this time could be
550 /* calibration changes values in settings, so reread */
551 retval = kone_get_settings(usb_dev, &kone->settings);
553 goto exit_no_settings;
555 /* only write settings back if activation state is different */
556 if (kone->settings.tcu != state) {
557 kone->settings.tcu = state;
558 kone_set_settings_checksum(&kone->settings);
560 retval = kone_set_settings(usb_dev, &kone->settings);
562 dev_err(&usb_dev->dev, "couldn't set tcu state\n");
564 * try to reread valid settings into buffer overwriting
567 retval = kone_get_settings(usb_dev, &kone->settings);
569 goto exit_no_settings;
576 dev_err(&usb_dev->dev, "couldn't read settings\n");
578 mutex_unlock(&kone->kone_lock);
582 static ssize_t kone_sysfs_show_startup_profile(struct device *dev,
583 struct device_attribute *attr, char *buf)
585 struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev));
586 return snprintf(buf, PAGE_SIZE, "%d\n", kone->settings.startup_profile);
589 static ssize_t kone_sysfs_set_startup_profile(struct device *dev,
590 struct device_attribute *attr, char const *buf, size_t size)
592 struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev));
593 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
595 unsigned long new_startup_profile;
597 retval = strict_strtoul(buf, 10, &new_startup_profile);
601 if (new_startup_profile < 1 || new_startup_profile > 5)
604 mutex_lock(&kone->kone_lock);
606 kone->settings.startup_profile = new_startup_profile;
607 kone_set_settings_checksum(&kone->settings);
609 retval = kone_set_settings(usb_dev, &kone->settings);
611 mutex_unlock(&kone->kone_lock);
616 /* changing the startup profile immediately activates this profile */
617 kone->actual_profile = new_startup_profile;
618 kone->actual_dpi = kone->profiles[kone->actual_profile - 1].startup_dpi;
624 * This file is used by userland software to find devices that are handled by
625 * this driver. This provides a consistent way for actual and older kernels
626 * where this driver replaced usbhid instead of generic-usb.
627 * Driver capabilities are determined by version number.
629 static ssize_t kone_sysfs_show_driver_version(struct device *dev,
630 struct device_attribute *attr, char *buf)
632 return snprintf(buf, PAGE_SIZE, DRIVER_VERSION "\n");
636 * Read actual dpi settings.
637 * Returns raw value for further processing. Refer to enum kone_polling_rates to
640 static DEVICE_ATTR(actual_dpi, 0440, kone_sysfs_show_actual_dpi, NULL);
642 static DEVICE_ATTR(actual_profile, 0440, kone_sysfs_show_actual_profile, NULL);
645 * The mouse can be equipped with one of four supplied weights from 5 to 20
646 * grams which are recognized and its value can be read out.
647 * This returns the raw value reported by the mouse for easy evaluation by
648 * software. Refer to enum kone_weights to get corresponding real weight.
650 static DEVICE_ATTR(weight, 0440, kone_sysfs_show_weight, NULL);
653 * Prints firmware version stored in mouse as integer.
654 * The raw value reported by the mouse is returned for easy evaluation, to get
655 * the real version number the decimal point has to be shifted 2 positions to
656 * the left. E.g. a value of 138 means 1.38.
658 static DEVICE_ATTR(firmware_version, 0440,
659 kone_sysfs_show_firmware_version, NULL);
662 * Prints state of Tracking Control Unit as number where 0 = off and 1 = on
663 * Writing 0 deactivates tcu and writing 1 calibrates and activates the tcu
665 static DEVICE_ATTR(tcu, 0660, kone_sysfs_show_tcu, kone_sysfs_set_tcu);
667 /* Prints and takes the number of the profile the mouse starts with */
668 static DEVICE_ATTR(startup_profile, 0660,
669 kone_sysfs_show_startup_profile,
670 kone_sysfs_set_startup_profile);
672 static DEVICE_ATTR(kone_driver_version, 0440,
673 kone_sysfs_show_driver_version, NULL);
675 static struct attribute *kone_attributes[] = {
676 &dev_attr_actual_dpi.attr,
677 &dev_attr_actual_profile.attr,
678 &dev_attr_weight.attr,
679 &dev_attr_firmware_version.attr,
681 &dev_attr_startup_profile.attr,
682 &dev_attr_kone_driver_version.attr,
686 static struct attribute_group kone_attribute_group = {
687 .attrs = kone_attributes
690 static struct bin_attribute kone_settings_attr = {
691 .attr = { .name = "settings", .mode = 0660 },
692 .size = sizeof(struct kone_settings),
693 .read = kone_sysfs_read_settings,
694 .write = kone_sysfs_write_settings
697 static struct bin_attribute kone_profile1_attr = {
698 .attr = { .name = "profile1", .mode = 0660 },
699 .size = sizeof(struct kone_profile),
700 .read = kone_sysfs_read_profile1,
701 .write = kone_sysfs_write_profile1
704 static struct bin_attribute kone_profile2_attr = {
705 .attr = { .name = "profile2", .mode = 0660 },
706 .size = sizeof(struct kone_profile),
707 .read = kone_sysfs_read_profile2,
708 .write = kone_sysfs_write_profile2
711 static struct bin_attribute kone_profile3_attr = {
712 .attr = { .name = "profile3", .mode = 0660 },
713 .size = sizeof(struct kone_profile),
714 .read = kone_sysfs_read_profile3,
715 .write = kone_sysfs_write_profile3
718 static struct bin_attribute kone_profile4_attr = {
719 .attr = { .name = "profile4", .mode = 0660 },
720 .size = sizeof(struct kone_profile),
721 .read = kone_sysfs_read_profile4,
722 .write = kone_sysfs_write_profile4
725 static struct bin_attribute kone_profile5_attr = {
726 .attr = { .name = "profile5", .mode = 0660 },
727 .size = sizeof(struct kone_profile),
728 .read = kone_sysfs_read_profile5,
729 .write = kone_sysfs_write_profile5
732 static int kone_create_sysfs_attributes(struct usb_interface *intf)
736 retval = sysfs_create_group(&intf->dev.kobj, &kone_attribute_group);
740 retval = sysfs_create_bin_file(&intf->dev.kobj, &kone_settings_attr);
744 retval = sysfs_create_bin_file(&intf->dev.kobj, &kone_profile1_attr);
748 retval = sysfs_create_bin_file(&intf->dev.kobj, &kone_profile2_attr);
752 retval = sysfs_create_bin_file(&intf->dev.kobj, &kone_profile3_attr);
756 retval = sysfs_create_bin_file(&intf->dev.kobj, &kone_profile4_attr);
760 retval = sysfs_create_bin_file(&intf->dev.kobj, &kone_profile5_attr);
767 sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile4_attr);
769 sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile3_attr);
771 sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile2_attr);
773 sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile1_attr);
775 sysfs_remove_bin_file(&intf->dev.kobj, &kone_settings_attr);
777 sysfs_remove_group(&intf->dev.kobj, &kone_attribute_group);
782 static void kone_remove_sysfs_attributes(struct usb_interface *intf)
784 sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile5_attr);
785 sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile4_attr);
786 sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile3_attr);
787 sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile2_attr);
788 sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile1_attr);
789 sysfs_remove_bin_file(&intf->dev.kobj, &kone_settings_attr);
790 sysfs_remove_group(&intf->dev.kobj, &kone_attribute_group);
793 static int kone_init_kone_device_struct(struct usb_device *usb_dev,
794 struct kone_device *kone)
799 mutex_init(&kone->kone_lock);
801 for (i = 0; i < 5; ++i) {
802 retval = kone_get_profile(usb_dev, &kone->profiles[i], i + 1);
807 retval = kone_get_settings(usb_dev, &kone->settings);
811 retval = kone_get_firmware_version(usb_dev, &kone->firmware_version);
815 kone->actual_profile = kone->settings.startup_profile;
816 kone->actual_dpi = kone->profiles[kone->actual_profile].startup_dpi;
822 * Since IGNORE_MOUSE quirk moved to hid-apple, there is no way to bind only to
823 * mousepart if usb_hid is compiled into the kernel and kone is compiled as
825 * Secial behaviour is bound only to mousepart since only mouseevents contain
826 * additional notifications.
828 static int kone_init_specials(struct hid_device *hdev)
830 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
831 struct usb_device *usb_dev = interface_to_usbdev(intf);
832 struct kone_device *kone;
835 if (intf->cur_altsetting->desc.bInterfaceProtocol
836 == USB_INTERFACE_PROTOCOL_MOUSE) {
838 kone = kzalloc(sizeof(*kone), GFP_KERNEL);
840 dev_err(&hdev->dev, "can't alloc device descriptor\n");
843 hid_set_drvdata(hdev, kone);
845 retval = kone_init_kone_device_struct(usb_dev, kone);
848 "couldn't init struct kone_device\n");
851 retval = kone_create_sysfs_attributes(intf);
853 dev_err(&hdev->dev, "cannot create sysfs files\n");
857 hid_set_drvdata(hdev, NULL);
867 static void kone_remove_specials(struct hid_device *hdev)
869 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
871 if (intf->cur_altsetting->desc.bInterfaceProtocol
872 == USB_INTERFACE_PROTOCOL_MOUSE) {
873 kone_remove_sysfs_attributes(intf);
874 kfree(hid_get_drvdata(hdev));
878 static int kone_probe(struct hid_device *hdev, const struct hid_device_id *id)
882 retval = hid_parse(hdev);
884 dev_err(&hdev->dev, "parse failed\n");
888 retval = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
890 dev_err(&hdev->dev, "hw start failed\n");
894 retval = kone_init_specials(hdev);
896 dev_err(&hdev->dev, "couldn't install mouse\n");
908 static void kone_remove(struct hid_device *hdev)
910 kone_remove_specials(hdev);
915 * Is called for keyboard- and mousepart.
916 * Only mousepart gets informations about special events in its extended event
919 static int kone_raw_event(struct hid_device *hdev, struct hid_report *report,
922 struct kone_device *kone = hid_get_drvdata(hdev);
923 struct kone_mouse_event *event = (struct kone_mouse_event *)data;
925 /* keyboard events are always processed by default handler */
926 if (size != sizeof(struct kone_mouse_event))
930 * Firmware 1.38 introduced new behaviour for tilt buttons.
931 * Pressed tilt button is reported in each movement event.
932 * Workaround sends only one event per press.
934 if (kone->last_tilt_state == event->tilt)
937 kone->last_tilt_state = event->tilt;
940 * handle special events and keep actual profile and dpi values
943 switch (event->event) {
944 case kone_mouse_event_osd_dpi:
945 dev_dbg(&hdev->dev, "osd dpi event. actual dpi %d\n",
947 return 1; /* return 1 if event was handled */
948 case kone_mouse_event_switch_dpi:
949 kone->actual_dpi = event->value;
950 dev_dbg(&hdev->dev, "switched dpi to %d\n", event->value);
952 case kone_mouse_event_osd_profile:
953 dev_dbg(&hdev->dev, "osd profile event. actual profile %d\n",
956 case kone_mouse_event_switch_profile:
957 kone->actual_profile = event->value;
958 kone->actual_dpi = kone->profiles[kone->actual_profile - 1].
960 dev_dbg(&hdev->dev, "switched profile to %d\n", event->value);
962 case kone_mouse_event_call_overlong_macro:
963 dev_dbg(&hdev->dev, "overlong macro called, button %d %s/%s\n",
965 kone->profiles[kone->actual_profile - 1].
966 button_infos[event->macro_key].macro_set_name,
967 kone->profiles[kone->actual_profile - 1].
968 button_infos[event->macro_key].macro_name
973 return 0; /* do further processing */
976 static const struct hid_device_id kone_devices[] = {
977 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONE) },
981 MODULE_DEVICE_TABLE(hid, kone_devices);
983 static struct hid_driver kone_driver = {
985 .id_table = kone_devices,
987 .remove = kone_remove,
988 .raw_event = kone_raw_event
991 static int kone_init(void)
993 return hid_register_driver(&kone_driver);
996 static void kone_exit(void)
998 hid_unregister_driver(&kone_driver);
1001 module_init(kone_init);
1002 module_exit(kone_exit);
1004 MODULE_AUTHOR(DRIVER_AUTHOR);
1005 MODULE_DESCRIPTION(DRIVER_DESC);
1006 MODULE_LICENSE(DRIVER_LICENSE);