123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857 |
- /*
- * Roccat Kone driver for Linux
- *
- * Copyright (c) 2010 Stefan Achatz <erazor_de@users.sourceforge.net>
- */
- /*
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- */
- /*
- * Roccat Kone is a gamer mouse which consists of a mouse part and a keyboard
- * part. The keyboard part enables the mouse to execute stored macros with mixed
- * key- and button-events.
- *
- * TODO implement on-the-fly polling-rate change
- * The windows driver has the ability to change the polling rate of the
- * device on the press of a mousebutton.
- * Is it possible to remove and reinstall the urb in raw-event- or any
- * other handler, or to defer this action to be executed somewhere else?
- *
- * TODO is it possible to overwrite group for sysfs attributes via udev?
- */
- #include <linux/device.h>
- #include <linux/input.h>
- #include <linux/hid.h>
- #include <linux/module.h>
- #include <linux/slab.h>
- #include <linux/hid-roccat.h>
- #include "hid-ids.h"
- #include "hid-roccat-common.h"
- #include "hid-roccat-kone.h"
- static uint profile_numbers[5] = {0, 1, 2, 3, 4};
- /* kone_class is used for creating sysfs attributes via roccat char device */
- static struct class *kone_class;
- static void kone_set_settings_checksum(struct kone_settings *settings)
- {
- uint16_t checksum = 0;
- unsigned char *address = (unsigned char *)settings;
- int i;
- for (i = 0; i < sizeof(struct kone_settings) - 2; ++i, ++address)
- checksum += *address;
- settings->checksum = cpu_to_le16(checksum);
- }
- /*
- * Checks success after writing data to mouse
- * On success returns 0
- * On failure returns errno
- */
- static int kone_check_write(struct usb_device *usb_dev)
- {
- int retval;
- uint8_t data;
- do {
- /*
- * Mouse needs 50 msecs until it says ok, but there are
- * 30 more msecs needed for next write to work.
- */
- msleep(80);
- retval = roccat_common_receive(usb_dev,
- kone_command_confirm_write, &data, 1);
- if (retval)
- return retval;
- /*
- * value of 3 seems to mean something like
- * "not finished yet, but it looks good"
- * So check again after a moment.
- */
- } while (data == 3);
- if (data == 1) /* everything alright */
- return 0;
- /* unknown answer */
- hid_err(usb_dev, "got retval %d when checking write\n", data);
- return -EIO;
- }
- /*
- * Reads settings from mouse and stores it in @buf
- * On success returns 0
- * On failure returns errno
- */
- static int kone_get_settings(struct usb_device *usb_dev,
- struct kone_settings *buf)
- {
- return roccat_common_receive(usb_dev, kone_command_settings, buf,
- sizeof(struct kone_settings));
- }
- /*
- * Writes settings from @buf to mouse
- * On success returns 0
- * On failure returns errno
- */
- static int kone_set_settings(struct usb_device *usb_dev,
- struct kone_settings const *settings)
- {
- int retval;
- retval = roccat_common_send(usb_dev, kone_command_settings,
- settings, sizeof(struct kone_settings));
- if (retval)
- return retval;
- return kone_check_write(usb_dev);
- }
- /*
- * Reads profile data from mouse and stores it in @buf
- * @number: profile number to read
- * On success returns 0
- * On failure returns errno
- */
- static int kone_get_profile(struct usb_device *usb_dev,
- struct kone_profile *buf, int number)
- {
- int len;
- if (number < 1 || number > 5)
- return -EINVAL;
- len = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
- USB_REQ_CLEAR_FEATURE,
- USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
- kone_command_profile, number, buf,
- sizeof(struct kone_profile), USB_CTRL_SET_TIMEOUT);
- if (len != sizeof(struct kone_profile))
- return -EIO;
- return 0;
- }
- /*
- * Writes profile data to mouse.
- * @number: profile number to write
- * On success returns 0
- * On failure returns errno
- */
- static int kone_set_profile(struct usb_device *usb_dev,
- struct kone_profile const *profile, int number)
- {
- int len;
- if (number < 1 || number > 5)
- return -EINVAL;
- len = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
- USB_REQ_SET_CONFIGURATION,
- USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
- kone_command_profile, number, (void *)profile,
- sizeof(struct kone_profile),
- USB_CTRL_SET_TIMEOUT);
- if (len != sizeof(struct kone_profile))
- return len;
- if (kone_check_write(usb_dev))
- return -EIO;
- return 0;
- }
- /*
- * Reads value of "fast-clip-weight" and stores it in @result
- * On success returns 0
- * On failure returns errno
- */
- static int kone_get_weight(struct usb_device *usb_dev, int *result)
- {
- int retval;
- uint8_t data;
- retval = roccat_common_receive(usb_dev, kone_command_weight, &data, 1);
- if (retval)
- return retval;
- *result = (int)data;
- return 0;
- }
- /*
- * Reads firmware_version of mouse and stores it in @result
- * On success returns 0
- * On failure returns errno
- */
- static int kone_get_firmware_version(struct usb_device *usb_dev, int *result)
- {
- int retval;
- uint16_t data;
- retval = roccat_common_receive(usb_dev, kone_command_firmware_version,
- &data, 2);
- if (retval)
- return retval;
- *result = le16_to_cpu(data);
- return 0;
- }
- static ssize_t kone_sysfs_read_settings(struct file *fp, struct kobject *kobj,
- struct bin_attribute *attr, char *buf,
- loff_t off, size_t count) {
- struct device *dev =
- container_of(kobj, struct device, kobj)->parent->parent;
- struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev));
- if (off >= sizeof(struct kone_settings))
- return 0;
- if (off + count > sizeof(struct kone_settings))
- count = sizeof(struct kone_settings) - off;
- mutex_lock(&kone->kone_lock);
- memcpy(buf, ((char const *)&kone->settings) + off, count);
- mutex_unlock(&kone->kone_lock);
- return count;
- }
- /*
- * Writing settings automatically activates startup_profile.
- * This function keeps values in kone_device up to date and assumes that in
- * case of error the old data is still valid
- */
- static ssize_t kone_sysfs_write_settings(struct file *fp, struct kobject *kobj,
- struct bin_attribute *attr, char *buf,
- loff_t off, size_t count) {
- struct device *dev =
- container_of(kobj, struct device, kobj)->parent->parent;
- struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev));
- struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
- int retval = 0, difference;
- /* I need to get my data in one piece */
- if (off != 0 || count != sizeof(struct kone_settings))
- return -EINVAL;
- mutex_lock(&kone->kone_lock);
- difference = memcmp(buf, &kone->settings, sizeof(struct kone_settings));
- if (difference) {
- retval = kone_set_settings(usb_dev,
- (struct kone_settings const *)buf);
- if (!retval)
- memcpy(&kone->settings, buf,
- sizeof(struct kone_settings));
- }
- mutex_unlock(&kone->kone_lock);
- if (retval)
- return retval;
- /*
- * If we get here, treat settings as okay and update actual values
- * according to startup_profile
- */
- kone->actual_profile = kone->settings.startup_profile;
- kone->actual_dpi = kone->profiles[kone->actual_profile - 1].startup_dpi;
- return sizeof(struct kone_settings);
- }
- static ssize_t kone_sysfs_read_profilex(struct file *fp,
- struct kobject *kobj, struct bin_attribute *attr,
- char *buf, loff_t off, size_t count) {
- struct device *dev =
- container_of(kobj, struct device, kobj)->parent->parent;
- struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev));
- if (off >= sizeof(struct kone_profile))
- return 0;
- if (off + count > sizeof(struct kone_profile))
- count = sizeof(struct kone_profile) - off;
- mutex_lock(&kone->kone_lock);
- memcpy(buf, ((char const *)&kone->profiles[*(uint *)(attr->private)]) + off, count);
- mutex_unlock(&kone->kone_lock);
- return count;
- }
- /* Writes data only if different to stored data */
- static ssize_t kone_sysfs_write_profilex(struct file *fp,
- struct kobject *kobj, struct bin_attribute *attr,
- char *buf, loff_t off, size_t count) {
- struct device *dev =
- container_of(kobj, struct device, kobj)->parent->parent;
- struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev));
- struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
- struct kone_profile *profile;
- int retval = 0, difference;
- /* I need to get my data in one piece */
- if (off != 0 || count != sizeof(struct kone_profile))
- return -EINVAL;
- profile = &kone->profiles[*(uint *)(attr->private)];
- mutex_lock(&kone->kone_lock);
- difference = memcmp(buf, profile, sizeof(struct kone_profile));
- if (difference) {
- retval = kone_set_profile(usb_dev,
- (struct kone_profile const *)buf,
- *(uint *)(attr->private) + 1);
- if (!retval)
- memcpy(profile, buf, sizeof(struct kone_profile));
- }
- mutex_unlock(&kone->kone_lock);
- if (retval)
- return retval;
- return sizeof(struct kone_profile);
- }
- static ssize_t kone_sysfs_show_actual_profile(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct kone_device *kone =
- hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
- return snprintf(buf, PAGE_SIZE, "%d\n", kone->actual_profile);
- }
- static ssize_t kone_sysfs_show_actual_dpi(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct kone_device *kone =
- hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
- return snprintf(buf, PAGE_SIZE, "%d\n", kone->actual_dpi);
- }
- /* weight is read each time, since we don't get informed when it's changed */
- static ssize_t kone_sysfs_show_weight(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct kone_device *kone;
- struct usb_device *usb_dev;
- int weight = 0;
- int retval;
- dev = dev->parent->parent;
- kone = hid_get_drvdata(dev_get_drvdata(dev));
- usb_dev = interface_to_usbdev(to_usb_interface(dev));
- mutex_lock(&kone->kone_lock);
- retval = kone_get_weight(usb_dev, &weight);
- mutex_unlock(&kone->kone_lock);
- if (retval)
- return retval;
- return snprintf(buf, PAGE_SIZE, "%d\n", weight);
- }
- static ssize_t kone_sysfs_show_firmware_version(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct kone_device *kone =
- hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
- return snprintf(buf, PAGE_SIZE, "%d\n", kone->firmware_version);
- }
- static ssize_t kone_sysfs_show_tcu(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct kone_device *kone =
- hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
- return snprintf(buf, PAGE_SIZE, "%d\n", kone->settings.tcu);
- }
- static int kone_tcu_command(struct usb_device *usb_dev, int number)
- {
- unsigned char value;
- value = number;
- return roccat_common_send(usb_dev, kone_command_calibrate, &value, 1);
- }
- /*
- * Calibrating the tcu is the only action that changes settings data inside the
- * mouse, so this data needs to be reread
- */
- static ssize_t kone_sysfs_set_tcu(struct device *dev,
- struct device_attribute *attr, char const *buf, size_t size)
- {
- struct kone_device *kone;
- struct usb_device *usb_dev;
- int retval;
- unsigned long state;
- dev = dev->parent->parent;
- kone = hid_get_drvdata(dev_get_drvdata(dev));
- usb_dev = interface_to_usbdev(to_usb_interface(dev));
- retval = strict_strtoul(buf, 10, &state);
- if (retval)
- return retval;
- if (state != 0 && state != 1)
- return -EINVAL;
- mutex_lock(&kone->kone_lock);
- if (state == 1) { /* state activate */
- retval = kone_tcu_command(usb_dev, 1);
- if (retval)
- goto exit_unlock;
- retval = kone_tcu_command(usb_dev, 2);
- if (retval)
- goto exit_unlock;
- ssleep(5); /* tcu needs this time for calibration */
- retval = kone_tcu_command(usb_dev, 3);
- if (retval)
- goto exit_unlock;
- retval = kone_tcu_command(usb_dev, 0);
- if (retval)
- goto exit_unlock;
- retval = kone_tcu_command(usb_dev, 4);
- if (retval)
- goto exit_unlock;
- /*
- * Kone needs this time to settle things.
- * Reading settings too early will result in invalid data.
- * Roccat's driver waits 1 sec, maybe this time could be
- * shortened.
- */
- ssleep(1);
- }
- /* calibration changes values in settings, so reread */
- retval = kone_get_settings(usb_dev, &kone->settings);
- if (retval)
- goto exit_no_settings;
- /* only write settings back if activation state is different */
- if (kone->settings.tcu != state) {
- kone->settings.tcu = state;
- kone_set_settings_checksum(&kone->settings);
- retval = kone_set_settings(usb_dev, &kone->settings);
- if (retval) {
- hid_err(usb_dev, "couldn't set tcu state\n");
- /*
- * try to reread valid settings into buffer overwriting
- * first error code
- */
- retval = kone_get_settings(usb_dev, &kone->settings);
- if (retval)
- goto exit_no_settings;
- goto exit_unlock;
- }
- }
- retval = size;
- exit_no_settings:
- hid_err(usb_dev, "couldn't read settings\n");
- exit_unlock:
- mutex_unlock(&kone->kone_lock);
- return retval;
- }
- static ssize_t kone_sysfs_show_startup_profile(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct kone_device *kone =
- hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
- return snprintf(buf, PAGE_SIZE, "%d\n", kone->settings.startup_profile);
- }
- static ssize_t kone_sysfs_set_startup_profile(struct device *dev,
- struct device_attribute *attr, char const *buf, size_t size)
- {
- struct kone_device *kone;
- struct usb_device *usb_dev;
- int retval;
- unsigned long new_startup_profile;
- dev = dev->parent->parent;
- kone = hid_get_drvdata(dev_get_drvdata(dev));
- usb_dev = interface_to_usbdev(to_usb_interface(dev));
- retval = strict_strtoul(buf, 10, &new_startup_profile);
- if (retval)
- return retval;
- if (new_startup_profile < 1 || new_startup_profile > 5)
- return -EINVAL;
- mutex_lock(&kone->kone_lock);
- kone->settings.startup_profile = new_startup_profile;
- kone_set_settings_checksum(&kone->settings);
- retval = kone_set_settings(usb_dev, &kone->settings);
- mutex_unlock(&kone->kone_lock);
- if (retval)
- return retval;
- /* changing the startup profile immediately activates this profile */
- kone->actual_profile = new_startup_profile;
- kone->actual_dpi = kone->profiles[kone->actual_profile - 1].startup_dpi;
- return size;
- }
- static struct device_attribute kone_attributes[] = {
- /*
- * Read actual dpi settings.
- * Returns raw value for further processing. Refer to enum
- * kone_polling_rates to get real value.
- */
- __ATTR(actual_dpi, 0440, kone_sysfs_show_actual_dpi, NULL),
- __ATTR(actual_profile, 0440, kone_sysfs_show_actual_profile, NULL),
- /*
- * The mouse can be equipped with one of four supplied weights from 5
- * to 20 grams which are recognized and its value can be read out.
- * This returns the raw value reported by the mouse for easy evaluation
- * by software. Refer to enum kone_weights to get corresponding real
- * weight.
- */
- __ATTR(weight, 0440, kone_sysfs_show_weight, NULL),
- /*
- * Prints firmware version stored in mouse as integer.
- * The raw value reported by the mouse is returned for easy evaluation,
- * to get the real version number the decimal point has to be shifted 2
- * positions to the left. E.g. a value of 138 means 1.38.
- */
- __ATTR(firmware_version, 0440,
- kone_sysfs_show_firmware_version, NULL),
- /*
- * Prints state of Tracking Control Unit as number where 0 = off and
- * 1 = on. Writing 0 deactivates tcu and writing 1 calibrates and
- * activates the tcu
- */
- __ATTR(tcu, 0660, kone_sysfs_show_tcu, kone_sysfs_set_tcu),
- /* Prints and takes the number of the profile the mouse starts with */
- __ATTR(startup_profile, 0660,
- kone_sysfs_show_startup_profile,
- kone_sysfs_set_startup_profile),
- __ATTR_NULL
- };
- static struct bin_attribute kone_bin_attributes[] = {
- {
- .attr = { .name = "settings", .mode = 0660 },
- .size = sizeof(struct kone_settings),
- .read = kone_sysfs_read_settings,
- .write = kone_sysfs_write_settings
- },
- {
- .attr = { .name = "profile1", .mode = 0660 },
- .size = sizeof(struct kone_profile),
- .read = kone_sysfs_read_profilex,
- .write = kone_sysfs_write_profilex,
- .private = &profile_numbers[0]
- },
- {
- .attr = { .name = "profile2", .mode = 0660 },
- .size = sizeof(struct kone_profile),
- .read = kone_sysfs_read_profilex,
- .write = kone_sysfs_write_profilex,
- .private = &profile_numbers[1]
- },
- {
- .attr = { .name = "profile3", .mode = 0660 },
- .size = sizeof(struct kone_profile),
- .read = kone_sysfs_read_profilex,
- .write = kone_sysfs_write_profilex,
- .private = &profile_numbers[2]
- },
- {
- .attr = { .name = "profile4", .mode = 0660 },
- .size = sizeof(struct kone_profile),
- .read = kone_sysfs_read_profilex,
- .write = kone_sysfs_write_profilex,
- .private = &profile_numbers[3]
- },
- {
- .attr = { .name = "profile5", .mode = 0660 },
- .size = sizeof(struct kone_profile),
- .read = kone_sysfs_read_profilex,
- .write = kone_sysfs_write_profilex,
- .private = &profile_numbers[4]
- },
- __ATTR_NULL
- };
- static int kone_init_kone_device_struct(struct usb_device *usb_dev,
- struct kone_device *kone)
- {
- uint i;
- int retval;
- mutex_init(&kone->kone_lock);
- for (i = 0; i < 5; ++i) {
- retval = kone_get_profile(usb_dev, &kone->profiles[i], i + 1);
- if (retval)
- return retval;
- }
- retval = kone_get_settings(usb_dev, &kone->settings);
- if (retval)
- return retval;
- retval = kone_get_firmware_version(usb_dev, &kone->firmware_version);
- if (retval)
- return retval;
- kone->actual_profile = kone->settings.startup_profile;
- kone->actual_dpi = kone->profiles[kone->actual_profile].startup_dpi;
- return 0;
- }
- /*
- * Since IGNORE_MOUSE quirk moved to hid-apple, there is no way to bind only to
- * mousepart if usb_hid is compiled into the kernel and kone is compiled as
- * module.
- * Secial behaviour is bound only to mousepart since only mouseevents contain
- * additional notifications.
- */
- static int kone_init_specials(struct hid_device *hdev)
- {
- struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
- struct usb_device *usb_dev = interface_to_usbdev(intf);
- struct kone_device *kone;
- int retval;
- if (intf->cur_altsetting->desc.bInterfaceProtocol
- == USB_INTERFACE_PROTOCOL_MOUSE) {
- kone = kzalloc(sizeof(*kone), GFP_KERNEL);
- if (!kone) {
- hid_err(hdev, "can't alloc device descriptor\n");
- return -ENOMEM;
- }
- hid_set_drvdata(hdev, kone);
- retval = kone_init_kone_device_struct(usb_dev, kone);
- if (retval) {
- hid_err(hdev, "couldn't init struct kone_device\n");
- goto exit_free;
- }
- retval = roccat_connect(kone_class, hdev,
- sizeof(struct kone_roccat_report));
- if (retval < 0) {
- hid_err(hdev, "couldn't init char dev\n");
- /* be tolerant about not getting chrdev */
- } else {
- kone->roccat_claimed = 1;
- kone->chrdev_minor = retval;
- }
- } else {
- hid_set_drvdata(hdev, NULL);
- }
- return 0;
- exit_free:
- kfree(kone);
- return retval;
- }
- static void kone_remove_specials(struct hid_device *hdev)
- {
- struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
- struct kone_device *kone;
- if (intf->cur_altsetting->desc.bInterfaceProtocol
- == USB_INTERFACE_PROTOCOL_MOUSE) {
- kone = hid_get_drvdata(hdev);
- if (kone->roccat_claimed)
- roccat_disconnect(kone->chrdev_minor);
- kfree(hid_get_drvdata(hdev));
- }
- }
- static int kone_probe(struct hid_device *hdev, const struct hid_device_id *id)
- {
- int retval;
- retval = hid_parse(hdev);
- if (retval) {
- hid_err(hdev, "parse failed\n");
- goto exit;
- }
- retval = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
- if (retval) {
- hid_err(hdev, "hw start failed\n");
- goto exit;
- }
- retval = kone_init_specials(hdev);
- if (retval) {
- hid_err(hdev, "couldn't install mouse\n");
- goto exit_stop;
- }
- return 0;
- exit_stop:
- hid_hw_stop(hdev);
- exit:
- return retval;
- }
- static void kone_remove(struct hid_device *hdev)
- {
- kone_remove_specials(hdev);
- hid_hw_stop(hdev);
- }
- /* handle special events and keep actual profile and dpi values up to date */
- static void kone_keep_values_up_to_date(struct kone_device *kone,
- struct kone_mouse_event const *event)
- {
- switch (event->event) {
- case kone_mouse_event_switch_profile:
- case kone_mouse_event_osd_profile:
- kone->actual_profile = event->value;
- kone->actual_dpi = kone->profiles[kone->actual_profile - 1].
- startup_dpi;
- break;
- case kone_mouse_event_switch_dpi:
- case kone_mouse_event_osd_dpi:
- kone->actual_dpi = event->value;
- break;
- }
- }
- static void kone_report_to_chrdev(struct kone_device const *kone,
- struct kone_mouse_event const *event)
- {
- struct kone_roccat_report roccat_report;
- switch (event->event) {
- case kone_mouse_event_switch_profile:
- case kone_mouse_event_switch_dpi:
- case kone_mouse_event_osd_profile:
- case kone_mouse_event_osd_dpi:
- roccat_report.event = event->event;
- roccat_report.value = event->value;
- roccat_report.key = 0;
- roccat_report_event(kone->chrdev_minor,
- (uint8_t *)&roccat_report);
- break;
- case kone_mouse_event_call_overlong_macro:
- if (event->value == kone_keystroke_action_press) {
- roccat_report.event = kone_mouse_event_call_overlong_macro;
- roccat_report.value = kone->actual_profile;
- roccat_report.key = event->macro_key;
- roccat_report_event(kone->chrdev_minor,
- (uint8_t *)&roccat_report);
- }
- break;
- }
- }
- /*
- * Is called for keyboard- and mousepart.
- * Only mousepart gets informations about special events in its extended event
- * structure.
- */
- static int kone_raw_event(struct hid_device *hdev, struct hid_report *report,
- u8 *data, int size)
- {
- struct kone_device *kone = hid_get_drvdata(hdev);
- struct kone_mouse_event *event = (struct kone_mouse_event *)data;
- /* keyboard events are always processed by default handler */
- if (size != sizeof(struct kone_mouse_event))
- return 0;
- /*
- * Firmware 1.38 introduced new behaviour for tilt and special buttons.
- * Pressed button is reported in each movement event.
- * Workaround sends only one event per press.
- */
- if (memcmp(&kone->last_mouse_event.tilt, &event->tilt, 5))
- memcpy(&kone->last_mouse_event, event,
- sizeof(struct kone_mouse_event));
- else
- memset(&event->tilt, 0, 5);
- kone_keep_values_up_to_date(kone, event);
- if (kone->roccat_claimed)
- kone_report_to_chrdev(kone, event);
- return 0; /* always do further processing */
- }
- static const struct hid_device_id kone_devices[] = {
- { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONE) },
- { }
- };
- MODULE_DEVICE_TABLE(hid, kone_devices);
- static struct hid_driver kone_driver = {
- .name = "kone",
- .id_table = kone_devices,
- .probe = kone_probe,
- .remove = kone_remove,
- .raw_event = kone_raw_event
- };
- static int __init kone_init(void)
- {
- int retval;
- /* class name has to be same as driver name */
- kone_class = class_create(THIS_MODULE, "kone");
- if (IS_ERR(kone_class))
- return PTR_ERR(kone_class);
- kone_class->dev_attrs = kone_attributes;
- kone_class->dev_bin_attrs = kone_bin_attributes;
- retval = hid_register_driver(&kone_driver);
- if (retval)
- class_destroy(kone_class);
- return retval;
- }
- static void __exit kone_exit(void)
- {
- hid_unregister_driver(&kone_driver);
- class_destroy(kone_class);
- }
- module_init(kone_init);
- module_exit(kone_exit);
- MODULE_AUTHOR("Stefan Achatz");
- MODULE_DESCRIPTION("USB Roccat Kone driver");
- MODULE_LICENSE("GPL v2");
|