0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <linux/device.h>
0016 #include <linux/input.h>
0017 #include <linux/hid.h>
0018 #include <linux/module.h>
0019 #include <linux/slab.h>
0020 #include <linux/hid-roccat.h>
0021 #include "hid-ids.h"
0022 #include "hid-roccat-common.h"
0023 #include "hid-roccat-kovaplus.h"
0024
0025 static uint profile_numbers[5] = {0, 1, 2, 3, 4};
0026
0027 static struct class *kovaplus_class;
0028
0029 static uint kovaplus_convert_event_cpi(uint value)
0030 {
0031 return (value == 7 ? 4 : (value == 4 ? 3 : value));
0032 }
0033
0034 static void kovaplus_profile_activated(struct kovaplus_device *kovaplus,
0035 uint new_profile_index)
0036 {
0037 if (new_profile_index >= ARRAY_SIZE(kovaplus->profile_settings))
0038 return;
0039 kovaplus->actual_profile = new_profile_index;
0040 kovaplus->actual_cpi = kovaplus->profile_settings[new_profile_index].cpi_startup_level;
0041 kovaplus->actual_x_sensitivity = kovaplus->profile_settings[new_profile_index].sensitivity_x;
0042 kovaplus->actual_y_sensitivity = kovaplus->profile_settings[new_profile_index].sensitivity_y;
0043 }
0044
0045 static int kovaplus_send_control(struct usb_device *usb_dev, uint value,
0046 enum kovaplus_control_requests request)
0047 {
0048 int retval;
0049 struct roccat_common2_control control;
0050
0051 if ((request == KOVAPLUS_CONTROL_REQUEST_PROFILE_SETTINGS ||
0052 request == KOVAPLUS_CONTROL_REQUEST_PROFILE_BUTTONS) &&
0053 value > 4)
0054 return -EINVAL;
0055
0056 control.command = ROCCAT_COMMON_COMMAND_CONTROL;
0057 control.value = value;
0058 control.request = request;
0059
0060 retval = roccat_common2_send(usb_dev, ROCCAT_COMMON_COMMAND_CONTROL,
0061 &control, sizeof(struct roccat_common2_control));
0062
0063 return retval;
0064 }
0065
0066 static int kovaplus_select_profile(struct usb_device *usb_dev, uint number,
0067 enum kovaplus_control_requests request)
0068 {
0069 return kovaplus_send_control(usb_dev, number, request);
0070 }
0071
0072 static int kovaplus_get_profile_settings(struct usb_device *usb_dev,
0073 struct kovaplus_profile_settings *buf, uint number)
0074 {
0075 int retval;
0076
0077 retval = kovaplus_select_profile(usb_dev, number,
0078 KOVAPLUS_CONTROL_REQUEST_PROFILE_SETTINGS);
0079 if (retval)
0080 return retval;
0081
0082 return roccat_common2_receive(usb_dev, KOVAPLUS_COMMAND_PROFILE_SETTINGS,
0083 buf, KOVAPLUS_SIZE_PROFILE_SETTINGS);
0084 }
0085
0086 static int kovaplus_get_profile_buttons(struct usb_device *usb_dev,
0087 struct kovaplus_profile_buttons *buf, int number)
0088 {
0089 int retval;
0090
0091 retval = kovaplus_select_profile(usb_dev, number,
0092 KOVAPLUS_CONTROL_REQUEST_PROFILE_BUTTONS);
0093 if (retval)
0094 return retval;
0095
0096 return roccat_common2_receive(usb_dev, KOVAPLUS_COMMAND_PROFILE_BUTTONS,
0097 buf, KOVAPLUS_SIZE_PROFILE_BUTTONS);
0098 }
0099
0100
0101 static int kovaplus_get_actual_profile(struct usb_device *usb_dev)
0102 {
0103 struct kovaplus_actual_profile buf;
0104 int retval;
0105
0106 retval = roccat_common2_receive(usb_dev, KOVAPLUS_COMMAND_ACTUAL_PROFILE,
0107 &buf, sizeof(struct kovaplus_actual_profile));
0108
0109 return retval ? retval : buf.actual_profile;
0110 }
0111
0112 static int kovaplus_set_actual_profile(struct usb_device *usb_dev,
0113 int new_profile)
0114 {
0115 struct kovaplus_actual_profile buf;
0116
0117 buf.command = KOVAPLUS_COMMAND_ACTUAL_PROFILE;
0118 buf.size = sizeof(struct kovaplus_actual_profile);
0119 buf.actual_profile = new_profile;
0120
0121 return roccat_common2_send_with_status(usb_dev,
0122 KOVAPLUS_COMMAND_ACTUAL_PROFILE,
0123 &buf, sizeof(struct kovaplus_actual_profile));
0124 }
0125
0126 static ssize_t kovaplus_sysfs_read(struct file *fp, struct kobject *kobj,
0127 char *buf, loff_t off, size_t count,
0128 size_t real_size, uint command)
0129 {
0130 struct device *dev = kobj_to_dev(kobj)->parent->parent;
0131 struct kovaplus_device *kovaplus = hid_get_drvdata(dev_get_drvdata(dev));
0132 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
0133 int retval;
0134
0135 if (off >= real_size)
0136 return 0;
0137
0138 if (off != 0 || count != real_size)
0139 return -EINVAL;
0140
0141 mutex_lock(&kovaplus->kovaplus_lock);
0142 retval = roccat_common2_receive(usb_dev, command, buf, real_size);
0143 mutex_unlock(&kovaplus->kovaplus_lock);
0144
0145 if (retval)
0146 return retval;
0147
0148 return real_size;
0149 }
0150
0151 static ssize_t kovaplus_sysfs_write(struct file *fp, struct kobject *kobj,
0152 void const *buf, loff_t off, size_t count,
0153 size_t real_size, uint command)
0154 {
0155 struct device *dev = kobj_to_dev(kobj)->parent->parent;
0156 struct kovaplus_device *kovaplus = hid_get_drvdata(dev_get_drvdata(dev));
0157 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
0158 int retval;
0159
0160 if (off != 0 || count != real_size)
0161 return -EINVAL;
0162
0163 mutex_lock(&kovaplus->kovaplus_lock);
0164 retval = roccat_common2_send_with_status(usb_dev, command,
0165 buf, real_size);
0166 mutex_unlock(&kovaplus->kovaplus_lock);
0167
0168 if (retval)
0169 return retval;
0170
0171 return real_size;
0172 }
0173
0174 #define KOVAPLUS_SYSFS_W(thingy, THINGY) \
0175 static ssize_t kovaplus_sysfs_write_ ## thingy(struct file *fp, \
0176 struct kobject *kobj, struct bin_attribute *attr, char *buf, \
0177 loff_t off, size_t count) \
0178 { \
0179 return kovaplus_sysfs_write(fp, kobj, buf, off, count, \
0180 KOVAPLUS_SIZE_ ## THINGY, KOVAPLUS_COMMAND_ ## THINGY); \
0181 }
0182
0183 #define KOVAPLUS_SYSFS_R(thingy, THINGY) \
0184 static ssize_t kovaplus_sysfs_read_ ## thingy(struct file *fp, \
0185 struct kobject *kobj, struct bin_attribute *attr, char *buf, \
0186 loff_t off, size_t count) \
0187 { \
0188 return kovaplus_sysfs_read(fp, kobj, buf, off, count, \
0189 KOVAPLUS_SIZE_ ## THINGY, KOVAPLUS_COMMAND_ ## THINGY); \
0190 }
0191
0192 #define KOVAPLUS_SYSFS_RW(thingy, THINGY) \
0193 KOVAPLUS_SYSFS_W(thingy, THINGY) \
0194 KOVAPLUS_SYSFS_R(thingy, THINGY)
0195
0196 #define KOVAPLUS_BIN_ATTRIBUTE_RW(thingy, THINGY) \
0197 KOVAPLUS_SYSFS_RW(thingy, THINGY); \
0198 static struct bin_attribute bin_attr_##thingy = { \
0199 .attr = { .name = #thingy, .mode = 0660 }, \
0200 .size = KOVAPLUS_SIZE_ ## THINGY, \
0201 .read = kovaplus_sysfs_read_ ## thingy, \
0202 .write = kovaplus_sysfs_write_ ## thingy \
0203 }
0204
0205 #define KOVAPLUS_BIN_ATTRIBUTE_W(thingy, THINGY) \
0206 KOVAPLUS_SYSFS_W(thingy, THINGY); \
0207 static struct bin_attribute bin_attr_##thingy = { \
0208 .attr = { .name = #thingy, .mode = 0220 }, \
0209 .size = KOVAPLUS_SIZE_ ## THINGY, \
0210 .write = kovaplus_sysfs_write_ ## thingy \
0211 }
0212 KOVAPLUS_BIN_ATTRIBUTE_W(control, CONTROL);
0213 KOVAPLUS_BIN_ATTRIBUTE_RW(info, INFO);
0214 KOVAPLUS_BIN_ATTRIBUTE_RW(profile_settings, PROFILE_SETTINGS);
0215 KOVAPLUS_BIN_ATTRIBUTE_RW(profile_buttons, PROFILE_BUTTONS);
0216
0217 static ssize_t kovaplus_sysfs_read_profilex_settings(struct file *fp,
0218 struct kobject *kobj, struct bin_attribute *attr, char *buf,
0219 loff_t off, size_t count)
0220 {
0221 struct device *dev = kobj_to_dev(kobj)->parent->parent;
0222 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
0223 ssize_t retval;
0224
0225 retval = kovaplus_select_profile(usb_dev, *(uint *)(attr->private),
0226 KOVAPLUS_CONTROL_REQUEST_PROFILE_SETTINGS);
0227 if (retval)
0228 return retval;
0229
0230 return kovaplus_sysfs_read(fp, kobj, buf, off, count,
0231 KOVAPLUS_SIZE_PROFILE_SETTINGS,
0232 KOVAPLUS_COMMAND_PROFILE_SETTINGS);
0233 }
0234
0235 static ssize_t kovaplus_sysfs_read_profilex_buttons(struct file *fp,
0236 struct kobject *kobj, struct bin_attribute *attr, char *buf,
0237 loff_t off, size_t count)
0238 {
0239 struct device *dev = kobj_to_dev(kobj)->parent->parent;
0240 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
0241 ssize_t retval;
0242
0243 retval = kovaplus_select_profile(usb_dev, *(uint *)(attr->private),
0244 KOVAPLUS_CONTROL_REQUEST_PROFILE_BUTTONS);
0245 if (retval)
0246 return retval;
0247
0248 return kovaplus_sysfs_read(fp, kobj, buf, off, count,
0249 KOVAPLUS_SIZE_PROFILE_BUTTONS,
0250 KOVAPLUS_COMMAND_PROFILE_BUTTONS);
0251 }
0252
0253 #define PROFILE_ATTR(number) \
0254 static struct bin_attribute bin_attr_profile##number##_settings = { \
0255 .attr = { .name = "profile" #number "_settings", .mode = 0440 }, \
0256 .size = KOVAPLUS_SIZE_PROFILE_SETTINGS, \
0257 .read = kovaplus_sysfs_read_profilex_settings, \
0258 .private = &profile_numbers[number-1], \
0259 }; \
0260 static struct bin_attribute bin_attr_profile##number##_buttons = { \
0261 .attr = { .name = "profile" #number "_buttons", .mode = 0440 }, \
0262 .size = KOVAPLUS_SIZE_PROFILE_BUTTONS, \
0263 .read = kovaplus_sysfs_read_profilex_buttons, \
0264 .private = &profile_numbers[number-1], \
0265 };
0266 PROFILE_ATTR(1);
0267 PROFILE_ATTR(2);
0268 PROFILE_ATTR(3);
0269 PROFILE_ATTR(4);
0270 PROFILE_ATTR(5);
0271
0272 static ssize_t kovaplus_sysfs_show_actual_profile(struct device *dev,
0273 struct device_attribute *attr, char *buf)
0274 {
0275 struct kovaplus_device *kovaplus =
0276 hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
0277 return snprintf(buf, PAGE_SIZE, "%d\n", kovaplus->actual_profile);
0278 }
0279
0280 static ssize_t kovaplus_sysfs_set_actual_profile(struct device *dev,
0281 struct device_attribute *attr, char const *buf, size_t size)
0282 {
0283 struct kovaplus_device *kovaplus;
0284 struct usb_device *usb_dev;
0285 unsigned long profile;
0286 int retval;
0287 struct kovaplus_roccat_report roccat_report;
0288
0289 dev = dev->parent->parent;
0290 kovaplus = hid_get_drvdata(dev_get_drvdata(dev));
0291 usb_dev = interface_to_usbdev(to_usb_interface(dev));
0292
0293 retval = kstrtoul(buf, 10, &profile);
0294 if (retval)
0295 return retval;
0296
0297 if (profile >= 5)
0298 return -EINVAL;
0299
0300 mutex_lock(&kovaplus->kovaplus_lock);
0301 retval = kovaplus_set_actual_profile(usb_dev, profile);
0302 if (retval) {
0303 mutex_unlock(&kovaplus->kovaplus_lock);
0304 return retval;
0305 }
0306
0307 kovaplus_profile_activated(kovaplus, profile);
0308
0309 roccat_report.type = KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_PROFILE_1;
0310 roccat_report.profile = profile + 1;
0311 roccat_report.button = 0;
0312 roccat_report.data1 = profile + 1;
0313 roccat_report.data2 = 0;
0314 roccat_report_event(kovaplus->chrdev_minor,
0315 (uint8_t const *)&roccat_report);
0316
0317 mutex_unlock(&kovaplus->kovaplus_lock);
0318
0319 return size;
0320 }
0321 static DEVICE_ATTR(actual_profile, 0660,
0322 kovaplus_sysfs_show_actual_profile,
0323 kovaplus_sysfs_set_actual_profile);
0324
0325 static ssize_t kovaplus_sysfs_show_actual_cpi(struct device *dev,
0326 struct device_attribute *attr, char *buf)
0327 {
0328 struct kovaplus_device *kovaplus =
0329 hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
0330 return snprintf(buf, PAGE_SIZE, "%d\n", kovaplus->actual_cpi);
0331 }
0332 static DEVICE_ATTR(actual_cpi, 0440, kovaplus_sysfs_show_actual_cpi, NULL);
0333
0334 static ssize_t kovaplus_sysfs_show_actual_sensitivity_x(struct device *dev,
0335 struct device_attribute *attr, char *buf)
0336 {
0337 struct kovaplus_device *kovaplus =
0338 hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
0339 return snprintf(buf, PAGE_SIZE, "%d\n", kovaplus->actual_x_sensitivity);
0340 }
0341 static DEVICE_ATTR(actual_sensitivity_x, 0440,
0342 kovaplus_sysfs_show_actual_sensitivity_x, NULL);
0343
0344 static ssize_t kovaplus_sysfs_show_actual_sensitivity_y(struct device *dev,
0345 struct device_attribute *attr, char *buf)
0346 {
0347 struct kovaplus_device *kovaplus =
0348 hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
0349 return snprintf(buf, PAGE_SIZE, "%d\n", kovaplus->actual_y_sensitivity);
0350 }
0351 static DEVICE_ATTR(actual_sensitivity_y, 0440,
0352 kovaplus_sysfs_show_actual_sensitivity_y, NULL);
0353
0354 static ssize_t kovaplus_sysfs_show_firmware_version(struct device *dev,
0355 struct device_attribute *attr, char *buf)
0356 {
0357 struct kovaplus_device *kovaplus;
0358 struct usb_device *usb_dev;
0359 struct kovaplus_info info;
0360
0361 dev = dev->parent->parent;
0362 kovaplus = hid_get_drvdata(dev_get_drvdata(dev));
0363 usb_dev = interface_to_usbdev(to_usb_interface(dev));
0364
0365 mutex_lock(&kovaplus->kovaplus_lock);
0366 roccat_common2_receive(usb_dev, KOVAPLUS_COMMAND_INFO,
0367 &info, KOVAPLUS_SIZE_INFO);
0368 mutex_unlock(&kovaplus->kovaplus_lock);
0369
0370 return snprintf(buf, PAGE_SIZE, "%d\n", info.firmware_version);
0371 }
0372 static DEVICE_ATTR(firmware_version, 0440,
0373 kovaplus_sysfs_show_firmware_version, NULL);
0374
0375 static struct attribute *kovaplus_attrs[] = {
0376 &dev_attr_actual_cpi.attr,
0377 &dev_attr_firmware_version.attr,
0378 &dev_attr_actual_profile.attr,
0379 &dev_attr_actual_sensitivity_x.attr,
0380 &dev_attr_actual_sensitivity_y.attr,
0381 NULL,
0382 };
0383
0384 static struct bin_attribute *kovaplus_bin_attributes[] = {
0385 &bin_attr_control,
0386 &bin_attr_info,
0387 &bin_attr_profile_settings,
0388 &bin_attr_profile_buttons,
0389 &bin_attr_profile1_settings,
0390 &bin_attr_profile2_settings,
0391 &bin_attr_profile3_settings,
0392 &bin_attr_profile4_settings,
0393 &bin_attr_profile5_settings,
0394 &bin_attr_profile1_buttons,
0395 &bin_attr_profile2_buttons,
0396 &bin_attr_profile3_buttons,
0397 &bin_attr_profile4_buttons,
0398 &bin_attr_profile5_buttons,
0399 NULL,
0400 };
0401
0402 static const struct attribute_group kovaplus_group = {
0403 .attrs = kovaplus_attrs,
0404 .bin_attrs = kovaplus_bin_attributes,
0405 };
0406
0407 static const struct attribute_group *kovaplus_groups[] = {
0408 &kovaplus_group,
0409 NULL,
0410 };
0411
0412 static int kovaplus_init_kovaplus_device_struct(struct usb_device *usb_dev,
0413 struct kovaplus_device *kovaplus)
0414 {
0415 int retval, i;
0416 static uint wait = 70;
0417
0418 mutex_init(&kovaplus->kovaplus_lock);
0419
0420 for (i = 0; i < 5; ++i) {
0421 msleep(wait);
0422 retval = kovaplus_get_profile_settings(usb_dev,
0423 &kovaplus->profile_settings[i], i);
0424 if (retval)
0425 return retval;
0426
0427 msleep(wait);
0428 retval = kovaplus_get_profile_buttons(usb_dev,
0429 &kovaplus->profile_buttons[i], i);
0430 if (retval)
0431 return retval;
0432 }
0433
0434 msleep(wait);
0435 retval = kovaplus_get_actual_profile(usb_dev);
0436 if (retval < 0)
0437 return retval;
0438 kovaplus_profile_activated(kovaplus, retval);
0439
0440 return 0;
0441 }
0442
0443 static int kovaplus_init_specials(struct hid_device *hdev)
0444 {
0445 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
0446 struct usb_device *usb_dev = interface_to_usbdev(intf);
0447 struct kovaplus_device *kovaplus;
0448 int retval;
0449
0450 if (intf->cur_altsetting->desc.bInterfaceProtocol
0451 == USB_INTERFACE_PROTOCOL_MOUSE) {
0452
0453 kovaplus = kzalloc(sizeof(*kovaplus), GFP_KERNEL);
0454 if (!kovaplus) {
0455 hid_err(hdev, "can't alloc device descriptor\n");
0456 return -ENOMEM;
0457 }
0458 hid_set_drvdata(hdev, kovaplus);
0459
0460 retval = kovaplus_init_kovaplus_device_struct(usb_dev, kovaplus);
0461 if (retval) {
0462 hid_err(hdev, "couldn't init struct kovaplus_device\n");
0463 goto exit_free;
0464 }
0465
0466 retval = roccat_connect(kovaplus_class, hdev,
0467 sizeof(struct kovaplus_roccat_report));
0468 if (retval < 0) {
0469 hid_err(hdev, "couldn't init char dev\n");
0470 } else {
0471 kovaplus->chrdev_minor = retval;
0472 kovaplus->roccat_claimed = 1;
0473 }
0474
0475 } else {
0476 hid_set_drvdata(hdev, NULL);
0477 }
0478
0479 return 0;
0480 exit_free:
0481 kfree(kovaplus);
0482 return retval;
0483 }
0484
0485 static void kovaplus_remove_specials(struct hid_device *hdev)
0486 {
0487 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
0488 struct kovaplus_device *kovaplus;
0489
0490 if (intf->cur_altsetting->desc.bInterfaceProtocol
0491 == USB_INTERFACE_PROTOCOL_MOUSE) {
0492 kovaplus = hid_get_drvdata(hdev);
0493 if (kovaplus->roccat_claimed)
0494 roccat_disconnect(kovaplus->chrdev_minor);
0495 kfree(kovaplus);
0496 }
0497 }
0498
0499 static int kovaplus_probe(struct hid_device *hdev,
0500 const struct hid_device_id *id)
0501 {
0502 int retval;
0503
0504 if (!hid_is_usb(hdev))
0505 return -EINVAL;
0506
0507 retval = hid_parse(hdev);
0508 if (retval) {
0509 hid_err(hdev, "parse failed\n");
0510 goto exit;
0511 }
0512
0513 retval = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
0514 if (retval) {
0515 hid_err(hdev, "hw start failed\n");
0516 goto exit;
0517 }
0518
0519 retval = kovaplus_init_specials(hdev);
0520 if (retval) {
0521 hid_err(hdev, "couldn't install mouse\n");
0522 goto exit_stop;
0523 }
0524
0525 return 0;
0526
0527 exit_stop:
0528 hid_hw_stop(hdev);
0529 exit:
0530 return retval;
0531 }
0532
0533 static void kovaplus_remove(struct hid_device *hdev)
0534 {
0535 kovaplus_remove_specials(hdev);
0536 hid_hw_stop(hdev);
0537 }
0538
0539 static void kovaplus_keep_values_up_to_date(struct kovaplus_device *kovaplus,
0540 u8 const *data)
0541 {
0542 struct kovaplus_mouse_report_button const *button_report;
0543
0544 if (data[0] != KOVAPLUS_MOUSE_REPORT_NUMBER_BUTTON)
0545 return;
0546
0547 button_report = (struct kovaplus_mouse_report_button const *)data;
0548
0549 switch (button_report->type) {
0550 case KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_PROFILE_1:
0551 kovaplus_profile_activated(kovaplus, button_report->data1 - 1);
0552 break;
0553 case KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_CPI:
0554 kovaplus->actual_cpi = kovaplus_convert_event_cpi(button_report->data1);
0555 break;
0556 case KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_SENSITIVITY:
0557 kovaplus->actual_x_sensitivity = button_report->data1;
0558 kovaplus->actual_y_sensitivity = button_report->data2;
0559 break;
0560 default:
0561 break;
0562 }
0563 }
0564
0565 static void kovaplus_report_to_chrdev(struct kovaplus_device const *kovaplus,
0566 u8 const *data)
0567 {
0568 struct kovaplus_roccat_report roccat_report;
0569 struct kovaplus_mouse_report_button const *button_report;
0570
0571 if (data[0] != KOVAPLUS_MOUSE_REPORT_NUMBER_BUTTON)
0572 return;
0573
0574 button_report = (struct kovaplus_mouse_report_button const *)data;
0575
0576 if (button_report->type == KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_PROFILE_2)
0577 return;
0578
0579 roccat_report.type = button_report->type;
0580 roccat_report.profile = kovaplus->actual_profile + 1;
0581
0582 if (roccat_report.type == KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_MACRO ||
0583 roccat_report.type == KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_SHORTCUT ||
0584 roccat_report.type == KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_QUICKLAUNCH ||
0585 roccat_report.type == KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_TIMER)
0586 roccat_report.button = button_report->data1;
0587 else
0588 roccat_report.button = 0;
0589
0590 if (roccat_report.type == KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_CPI)
0591 roccat_report.data1 = kovaplus_convert_event_cpi(button_report->data1);
0592 else
0593 roccat_report.data1 = button_report->data1;
0594
0595 roccat_report.data2 = button_report->data2;
0596
0597 roccat_report_event(kovaplus->chrdev_minor,
0598 (uint8_t const *)&roccat_report);
0599 }
0600
0601 static int kovaplus_raw_event(struct hid_device *hdev,
0602 struct hid_report *report, u8 *data, int size)
0603 {
0604 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
0605 struct kovaplus_device *kovaplus = hid_get_drvdata(hdev);
0606
0607 if (intf->cur_altsetting->desc.bInterfaceProtocol
0608 != USB_INTERFACE_PROTOCOL_MOUSE)
0609 return 0;
0610
0611 if (kovaplus == NULL)
0612 return 0;
0613
0614 kovaplus_keep_values_up_to_date(kovaplus, data);
0615
0616 if (kovaplus->roccat_claimed)
0617 kovaplus_report_to_chrdev(kovaplus, data);
0618
0619 return 0;
0620 }
0621
0622 static const struct hid_device_id kovaplus_devices[] = {
0623 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KOVAPLUS) },
0624 { }
0625 };
0626
0627 MODULE_DEVICE_TABLE(hid, kovaplus_devices);
0628
0629 static struct hid_driver kovaplus_driver = {
0630 .name = "kovaplus",
0631 .id_table = kovaplus_devices,
0632 .probe = kovaplus_probe,
0633 .remove = kovaplus_remove,
0634 .raw_event = kovaplus_raw_event
0635 };
0636
0637 static int __init kovaplus_init(void)
0638 {
0639 int retval;
0640
0641 kovaplus_class = class_create(THIS_MODULE, "kovaplus");
0642 if (IS_ERR(kovaplus_class))
0643 return PTR_ERR(kovaplus_class);
0644 kovaplus_class->dev_groups = kovaplus_groups;
0645
0646 retval = hid_register_driver(&kovaplus_driver);
0647 if (retval)
0648 class_destroy(kovaplus_class);
0649 return retval;
0650 }
0651
0652 static void __exit kovaplus_exit(void)
0653 {
0654 hid_unregister_driver(&kovaplus_driver);
0655 class_destroy(kovaplus_class);
0656 }
0657
0658 module_init(kovaplus_init);
0659 module_exit(kovaplus_exit);
0660
0661 MODULE_AUTHOR("Stefan Achatz");
0662 MODULE_DESCRIPTION("USB Roccat Kova[+] driver");
0663 MODULE_LICENSE("GPL v2");