1 /* 2 * Roccat Kova[+] driver for Linux 3 * 4 * Copyright (c) 2011 Stefan Achatz <erazor_de@users.sourceforge.net> 5 */ 6 7 /* 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) 11 * any later version. 12 */ 13 14 /* 15 * Roccat Kova[+] is a bigger version of the Pyra with two more side buttons. 16 */ 17 18 #include <linux/device.h> 19 #include <linux/input.h> 20 #include <linux/hid.h> 21 #include <linux/module.h> 22 #include <linux/slab.h> 23 #include <linux/hid-roccat.h> 24 #include "hid-ids.h" 25 #include "hid-roccat-common.h" 26 #include "hid-roccat-kovaplus.h" 27 28 static uint profile_numbers[5] = {0, 1, 2, 3, 4}; 29 30 static struct class *kovaplus_class; 31 32 static uint kovaplus_convert_event_cpi(uint value) 33 { 34 return (value == 7 ? 4 : (value == 4 ? 3 : value)); 35 } 36 37 static void kovaplus_profile_activated(struct kovaplus_device *kovaplus, 38 uint new_profile_index) 39 { 40 if (new_profile_index >= ARRAY_SIZE(kovaplus->profile_settings)) 41 return; 42 kovaplus->actual_profile = new_profile_index; 43 kovaplus->actual_cpi = kovaplus->profile_settings[new_profile_index].cpi_startup_level; 44 kovaplus->actual_x_sensitivity = kovaplus->profile_settings[new_profile_index].sensitivity_x; 45 kovaplus->actual_y_sensitivity = kovaplus->profile_settings[new_profile_index].sensitivity_y; 46 } 47 48 static int kovaplus_send_control(struct usb_device *usb_dev, uint value, 49 enum kovaplus_control_requests request) 50 { 51 int retval; 52 struct roccat_common2_control control; 53 54 if ((request == KOVAPLUS_CONTROL_REQUEST_PROFILE_SETTINGS || 55 request == KOVAPLUS_CONTROL_REQUEST_PROFILE_BUTTONS) && 56 value > 4) 57 return -EINVAL; 58 59 control.command = ROCCAT_COMMON_COMMAND_CONTROL; 60 control.value = value; 61 control.request = request; 62 63 retval = roccat_common2_send(usb_dev, ROCCAT_COMMON_COMMAND_CONTROL, 64 &control, sizeof(struct roccat_common2_control)); 65 66 return retval; 67 } 68 69 static int kovaplus_select_profile(struct usb_device *usb_dev, uint number, 70 enum kovaplus_control_requests request) 71 { 72 return kovaplus_send_control(usb_dev, number, request); 73 } 74 75 static int kovaplus_get_profile_settings(struct usb_device *usb_dev, 76 struct kovaplus_profile_settings *buf, uint number) 77 { 78 int retval; 79 80 retval = kovaplus_select_profile(usb_dev, number, 81 KOVAPLUS_CONTROL_REQUEST_PROFILE_SETTINGS); 82 if (retval) 83 return retval; 84 85 return roccat_common2_receive(usb_dev, KOVAPLUS_COMMAND_PROFILE_SETTINGS, 86 buf, KOVAPLUS_SIZE_PROFILE_SETTINGS); 87 } 88 89 static int kovaplus_get_profile_buttons(struct usb_device *usb_dev, 90 struct kovaplus_profile_buttons *buf, int number) 91 { 92 int retval; 93 94 retval = kovaplus_select_profile(usb_dev, number, 95 KOVAPLUS_CONTROL_REQUEST_PROFILE_BUTTONS); 96 if (retval) 97 return retval; 98 99 return roccat_common2_receive(usb_dev, KOVAPLUS_COMMAND_PROFILE_BUTTONS, 100 buf, KOVAPLUS_SIZE_PROFILE_BUTTONS); 101 } 102 103 /* retval is 0-4 on success, < 0 on error */ 104 static int kovaplus_get_actual_profile(struct usb_device *usb_dev) 105 { 106 struct kovaplus_actual_profile buf; 107 int retval; 108 109 retval = roccat_common2_receive(usb_dev, KOVAPLUS_COMMAND_ACTUAL_PROFILE, 110 &buf, sizeof(struct kovaplus_actual_profile)); 111 112 return retval ? retval : buf.actual_profile; 113 } 114 115 static int kovaplus_set_actual_profile(struct usb_device *usb_dev, 116 int new_profile) 117 { 118 struct kovaplus_actual_profile buf; 119 120 buf.command = KOVAPLUS_COMMAND_ACTUAL_PROFILE; 121 buf.size = sizeof(struct kovaplus_actual_profile); 122 buf.actual_profile = new_profile; 123 124 return roccat_common2_send_with_status(usb_dev, 125 KOVAPLUS_COMMAND_ACTUAL_PROFILE, 126 &buf, sizeof(struct kovaplus_actual_profile)); 127 } 128 129 static ssize_t kovaplus_sysfs_read(struct file *fp, struct kobject *kobj, 130 char *buf, loff_t off, size_t count, 131 size_t real_size, uint command) 132 { 133 struct device *dev = kobj_to_dev(kobj)->parent->parent; 134 struct kovaplus_device *kovaplus = hid_get_drvdata(dev_get_drvdata(dev)); 135 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); 136 int retval; 137 138 if (off >= real_size) 139 return 0; 140 141 if (off != 0 || count != real_size) 142 return -EINVAL; 143 144 mutex_lock(&kovaplus->kovaplus_lock); 145 retval = roccat_common2_receive(usb_dev, command, buf, real_size); 146 mutex_unlock(&kovaplus->kovaplus_lock); 147 148 if (retval) 149 return retval; 150 151 return real_size; 152 } 153 154 static ssize_t kovaplus_sysfs_write(struct file *fp, struct kobject *kobj, 155 void const *buf, loff_t off, size_t count, 156 size_t real_size, uint command) 157 { 158 struct device *dev = kobj_to_dev(kobj)->parent->parent; 159 struct kovaplus_device *kovaplus = hid_get_drvdata(dev_get_drvdata(dev)); 160 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); 161 int retval; 162 163 if (off != 0 || count != real_size) 164 return -EINVAL; 165 166 mutex_lock(&kovaplus->kovaplus_lock); 167 retval = roccat_common2_send_with_status(usb_dev, command, 168 buf, real_size); 169 mutex_unlock(&kovaplus->kovaplus_lock); 170 171 if (retval) 172 return retval; 173 174 return real_size; 175 } 176 177 #define KOVAPLUS_SYSFS_W(thingy, THINGY) \ 178 static ssize_t kovaplus_sysfs_write_ ## thingy(struct file *fp, \ 179 struct kobject *kobj, struct bin_attribute *attr, char *buf, \ 180 loff_t off, size_t count) \ 181 { \ 182 return kovaplus_sysfs_write(fp, kobj, buf, off, count, \ 183 KOVAPLUS_SIZE_ ## THINGY, KOVAPLUS_COMMAND_ ## THINGY); \ 184 } 185 186 #define KOVAPLUS_SYSFS_R(thingy, THINGY) \ 187 static ssize_t kovaplus_sysfs_read_ ## thingy(struct file *fp, \ 188 struct kobject *kobj, struct bin_attribute *attr, char *buf, \ 189 loff_t off, size_t count) \ 190 { \ 191 return kovaplus_sysfs_read(fp, kobj, buf, off, count, \ 192 KOVAPLUS_SIZE_ ## THINGY, KOVAPLUS_COMMAND_ ## THINGY); \ 193 } 194 195 #define KOVAPLUS_SYSFS_RW(thingy, THINGY) \ 196 KOVAPLUS_SYSFS_W(thingy, THINGY) \ 197 KOVAPLUS_SYSFS_R(thingy, THINGY) 198 199 #define KOVAPLUS_BIN_ATTRIBUTE_RW(thingy, THINGY) \ 200 KOVAPLUS_SYSFS_RW(thingy, THINGY); \ 201 static struct bin_attribute bin_attr_##thingy = { \ 202 .attr = { .name = #thingy, .mode = 0660 }, \ 203 .size = KOVAPLUS_SIZE_ ## THINGY, \ 204 .read = kovaplus_sysfs_read_ ## thingy, \ 205 .write = kovaplus_sysfs_write_ ## thingy \ 206 } 207 208 #define KOVAPLUS_BIN_ATTRIBUTE_W(thingy, THINGY) \ 209 KOVAPLUS_SYSFS_W(thingy, THINGY); \ 210 static struct bin_attribute bin_attr_##thingy = { \ 211 .attr = { .name = #thingy, .mode = 0220 }, \ 212 .size = KOVAPLUS_SIZE_ ## THINGY, \ 213 .write = kovaplus_sysfs_write_ ## thingy \ 214 } 215 KOVAPLUS_BIN_ATTRIBUTE_W(control, CONTROL); 216 KOVAPLUS_BIN_ATTRIBUTE_RW(info, INFO); 217 KOVAPLUS_BIN_ATTRIBUTE_RW(profile_settings, PROFILE_SETTINGS); 218 KOVAPLUS_BIN_ATTRIBUTE_RW(profile_buttons, PROFILE_BUTTONS); 219 220 static ssize_t kovaplus_sysfs_read_profilex_settings(struct file *fp, 221 struct kobject *kobj, struct bin_attribute *attr, char *buf, 222 loff_t off, size_t count) 223 { 224 struct device *dev = kobj_to_dev(kobj)->parent->parent; 225 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); 226 ssize_t retval; 227 228 retval = kovaplus_select_profile(usb_dev, *(uint *)(attr->private), 229 KOVAPLUS_CONTROL_REQUEST_PROFILE_SETTINGS); 230 if (retval) 231 return retval; 232 233 return kovaplus_sysfs_read(fp, kobj, buf, off, count, 234 KOVAPLUS_SIZE_PROFILE_SETTINGS, 235 KOVAPLUS_COMMAND_PROFILE_SETTINGS); 236 } 237 238 static ssize_t kovaplus_sysfs_read_profilex_buttons(struct file *fp, 239 struct kobject *kobj, struct bin_attribute *attr, char *buf, 240 loff_t off, size_t count) 241 { 242 struct device *dev = kobj_to_dev(kobj)->parent->parent; 243 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); 244 ssize_t retval; 245 246 retval = kovaplus_select_profile(usb_dev, *(uint *)(attr->private), 247 KOVAPLUS_CONTROL_REQUEST_PROFILE_BUTTONS); 248 if (retval) 249 return retval; 250 251 return kovaplus_sysfs_read(fp, kobj, buf, off, count, 252 KOVAPLUS_SIZE_PROFILE_BUTTONS, 253 KOVAPLUS_COMMAND_PROFILE_BUTTONS); 254 } 255 256 #define PROFILE_ATTR(number) \ 257 static struct bin_attribute bin_attr_profile##number##_settings = { \ 258 .attr = { .name = "profile" #number "_settings", .mode = 0440 }, \ 259 .size = KOVAPLUS_SIZE_PROFILE_SETTINGS, \ 260 .read = kovaplus_sysfs_read_profilex_settings, \ 261 .private = &profile_numbers[number-1], \ 262 }; \ 263 static struct bin_attribute bin_attr_profile##number##_buttons = { \ 264 .attr = { .name = "profile" #number "_buttons", .mode = 0440 }, \ 265 .size = KOVAPLUS_SIZE_PROFILE_BUTTONS, \ 266 .read = kovaplus_sysfs_read_profilex_buttons, \ 267 .private = &profile_numbers[number-1], \ 268 }; 269 PROFILE_ATTR(1); 270 PROFILE_ATTR(2); 271 PROFILE_ATTR(3); 272 PROFILE_ATTR(4); 273 PROFILE_ATTR(5); 274 275 static ssize_t kovaplus_sysfs_show_actual_profile(struct device *dev, 276 struct device_attribute *attr, char *buf) 277 { 278 struct kovaplus_device *kovaplus = 279 hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); 280 return snprintf(buf, PAGE_SIZE, "%d\n", kovaplus->actual_profile); 281 } 282 283 static ssize_t kovaplus_sysfs_set_actual_profile(struct device *dev, 284 struct device_attribute *attr, char const *buf, size_t size) 285 { 286 struct kovaplus_device *kovaplus; 287 struct usb_device *usb_dev; 288 unsigned long profile; 289 int retval; 290 struct kovaplus_roccat_report roccat_report; 291 292 dev = dev->parent->parent; 293 kovaplus = hid_get_drvdata(dev_get_drvdata(dev)); 294 usb_dev = interface_to_usbdev(to_usb_interface(dev)); 295 296 retval = kstrtoul(buf, 10, &profile); 297 if (retval) 298 return retval; 299 300 if (profile >= 5) 301 return -EINVAL; 302 303 mutex_lock(&kovaplus->kovaplus_lock); 304 retval = kovaplus_set_actual_profile(usb_dev, profile); 305 if (retval) { 306 mutex_unlock(&kovaplus->kovaplus_lock); 307 return retval; 308 } 309 310 kovaplus_profile_activated(kovaplus, profile); 311 312 roccat_report.type = KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_PROFILE_1; 313 roccat_report.profile = profile + 1; 314 roccat_report.button = 0; 315 roccat_report.data1 = profile + 1; 316 roccat_report.data2 = 0; 317 roccat_report_event(kovaplus->chrdev_minor, 318 (uint8_t const *)&roccat_report); 319 320 mutex_unlock(&kovaplus->kovaplus_lock); 321 322 return size; 323 } 324 static DEVICE_ATTR(actual_profile, 0660, 325 kovaplus_sysfs_show_actual_profile, 326 kovaplus_sysfs_set_actual_profile); 327 328 static ssize_t kovaplus_sysfs_show_actual_cpi(struct device *dev, 329 struct device_attribute *attr, char *buf) 330 { 331 struct kovaplus_device *kovaplus = 332 hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); 333 return snprintf(buf, PAGE_SIZE, "%d\n", kovaplus->actual_cpi); 334 } 335 static DEVICE_ATTR(actual_cpi, 0440, kovaplus_sysfs_show_actual_cpi, NULL); 336 337 static ssize_t kovaplus_sysfs_show_actual_sensitivity_x(struct device *dev, 338 struct device_attribute *attr, char *buf) 339 { 340 struct kovaplus_device *kovaplus = 341 hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); 342 return snprintf(buf, PAGE_SIZE, "%d\n", kovaplus->actual_x_sensitivity); 343 } 344 static DEVICE_ATTR(actual_sensitivity_x, 0440, 345 kovaplus_sysfs_show_actual_sensitivity_x, NULL); 346 347 static ssize_t kovaplus_sysfs_show_actual_sensitivity_y(struct device *dev, 348 struct device_attribute *attr, char *buf) 349 { 350 struct kovaplus_device *kovaplus = 351 hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); 352 return snprintf(buf, PAGE_SIZE, "%d\n", kovaplus->actual_y_sensitivity); 353 } 354 static DEVICE_ATTR(actual_sensitivity_y, 0440, 355 kovaplus_sysfs_show_actual_sensitivity_y, NULL); 356 357 static ssize_t kovaplus_sysfs_show_firmware_version(struct device *dev, 358 struct device_attribute *attr, char *buf) 359 { 360 struct kovaplus_device *kovaplus; 361 struct usb_device *usb_dev; 362 struct kovaplus_info info; 363 364 dev = dev->parent->parent; 365 kovaplus = hid_get_drvdata(dev_get_drvdata(dev)); 366 usb_dev = interface_to_usbdev(to_usb_interface(dev)); 367 368 mutex_lock(&kovaplus->kovaplus_lock); 369 roccat_common2_receive(usb_dev, KOVAPLUS_COMMAND_INFO, 370 &info, KOVAPLUS_SIZE_INFO); 371 mutex_unlock(&kovaplus->kovaplus_lock); 372 373 return snprintf(buf, PAGE_SIZE, "%d\n", info.firmware_version); 374 } 375 static DEVICE_ATTR(firmware_version, 0440, 376 kovaplus_sysfs_show_firmware_version, NULL); 377 378 static struct attribute *kovaplus_attrs[] = { 379 &dev_attr_actual_cpi.attr, 380 &dev_attr_firmware_version.attr, 381 &dev_attr_actual_profile.attr, 382 &dev_attr_actual_sensitivity_x.attr, 383 &dev_attr_actual_sensitivity_y.attr, 384 NULL, 385 }; 386 387 static struct bin_attribute *kovaplus_bin_attributes[] = { 388 &bin_attr_control, 389 &bin_attr_info, 390 &bin_attr_profile_settings, 391 &bin_attr_profile_buttons, 392 &bin_attr_profile1_settings, 393 &bin_attr_profile2_settings, 394 &bin_attr_profile3_settings, 395 &bin_attr_profile4_settings, 396 &bin_attr_profile5_settings, 397 &bin_attr_profile1_buttons, 398 &bin_attr_profile2_buttons, 399 &bin_attr_profile3_buttons, 400 &bin_attr_profile4_buttons, 401 &bin_attr_profile5_buttons, 402 NULL, 403 }; 404 405 static const struct attribute_group kovaplus_group = { 406 .attrs = kovaplus_attrs, 407 .bin_attrs = kovaplus_bin_attributes, 408 }; 409 410 static const struct attribute_group *kovaplus_groups[] = { 411 &kovaplus_group, 412 NULL, 413 }; 414 415 static int kovaplus_init_kovaplus_device_struct(struct usb_device *usb_dev, 416 struct kovaplus_device *kovaplus) 417 { 418 int retval, i; 419 static uint wait = 70; /* device will freeze with just 60 */ 420 421 mutex_init(&kovaplus->kovaplus_lock); 422 423 for (i = 0; i < 5; ++i) { 424 msleep(wait); 425 retval = kovaplus_get_profile_settings(usb_dev, 426 &kovaplus->profile_settings[i], i); 427 if (retval) 428 return retval; 429 430 msleep(wait); 431 retval = kovaplus_get_profile_buttons(usb_dev, 432 &kovaplus->profile_buttons[i], i); 433 if (retval) 434 return retval; 435 } 436 437 msleep(wait); 438 retval = kovaplus_get_actual_profile(usb_dev); 439 if (retval < 0) 440 return retval; 441 kovaplus_profile_activated(kovaplus, retval); 442 443 return 0; 444 } 445 446 static int kovaplus_init_specials(struct hid_device *hdev) 447 { 448 struct usb_interface *intf = to_usb_interface(hdev->dev.parent); 449 struct usb_device *usb_dev = interface_to_usbdev(intf); 450 struct kovaplus_device *kovaplus; 451 int retval; 452 453 if (intf->cur_altsetting->desc.bInterfaceProtocol 454 == USB_INTERFACE_PROTOCOL_MOUSE) { 455 456 kovaplus = kzalloc(sizeof(*kovaplus), GFP_KERNEL); 457 if (!kovaplus) { 458 hid_err(hdev, "can't alloc device descriptor\n"); 459 return -ENOMEM; 460 } 461 hid_set_drvdata(hdev, kovaplus); 462 463 retval = kovaplus_init_kovaplus_device_struct(usb_dev, kovaplus); 464 if (retval) { 465 hid_err(hdev, "couldn't init struct kovaplus_device\n"); 466 goto exit_free; 467 } 468 469 retval = roccat_connect(kovaplus_class, hdev, 470 sizeof(struct kovaplus_roccat_report)); 471 if (retval < 0) { 472 hid_err(hdev, "couldn't init char dev\n"); 473 } else { 474 kovaplus->chrdev_minor = retval; 475 kovaplus->roccat_claimed = 1; 476 } 477 478 } else { 479 hid_set_drvdata(hdev, NULL); 480 } 481 482 return 0; 483 exit_free: 484 kfree(kovaplus); 485 return retval; 486 } 487 488 static void kovaplus_remove_specials(struct hid_device *hdev) 489 { 490 struct usb_interface *intf = to_usb_interface(hdev->dev.parent); 491 struct kovaplus_device *kovaplus; 492 493 if (intf->cur_altsetting->desc.bInterfaceProtocol 494 == USB_INTERFACE_PROTOCOL_MOUSE) { 495 kovaplus = hid_get_drvdata(hdev); 496 if (kovaplus->roccat_claimed) 497 roccat_disconnect(kovaplus->chrdev_minor); 498 kfree(kovaplus); 499 } 500 } 501 502 static int kovaplus_probe(struct hid_device *hdev, 503 const struct hid_device_id *id) 504 { 505 int retval; 506 507 retval = hid_parse(hdev); 508 if (retval) { 509 hid_err(hdev, "parse failed\n"); 510 goto exit; 511 } 512 513 retval = hid_hw_start(hdev, HID_CONNECT_DEFAULT); 514 if (retval) { 515 hid_err(hdev, "hw start failed\n"); 516 goto exit; 517 } 518 519 retval = kovaplus_init_specials(hdev); 520 if (retval) { 521 hid_err(hdev, "couldn't install mouse\n"); 522 goto exit_stop; 523 } 524 525 return 0; 526 527 exit_stop: 528 hid_hw_stop(hdev); 529 exit: 530 return retval; 531 } 532 533 static void kovaplus_remove(struct hid_device *hdev) 534 { 535 kovaplus_remove_specials(hdev); 536 hid_hw_stop(hdev); 537 } 538 539 static void kovaplus_keep_values_up_to_date(struct kovaplus_device *kovaplus, 540 u8 const *data) 541 { 542 struct kovaplus_mouse_report_button const *button_report; 543 544 if (data[0] != KOVAPLUS_MOUSE_REPORT_NUMBER_BUTTON) 545 return; 546 547 button_report = (struct kovaplus_mouse_report_button const *)data; 548 549 switch (button_report->type) { 550 case KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_PROFILE_1: 551 kovaplus_profile_activated(kovaplus, button_report->data1 - 1); 552 break; 553 case KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_CPI: 554 kovaplus->actual_cpi = kovaplus_convert_event_cpi(button_report->data1); 555 break; 556 case KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_SENSITIVITY: 557 kovaplus->actual_x_sensitivity = button_report->data1; 558 kovaplus->actual_y_sensitivity = button_report->data2; 559 break; 560 default: 561 break; 562 } 563 } 564 565 static void kovaplus_report_to_chrdev(struct kovaplus_device const *kovaplus, 566 u8 const *data) 567 { 568 struct kovaplus_roccat_report roccat_report; 569 struct kovaplus_mouse_report_button const *button_report; 570 571 if (data[0] != KOVAPLUS_MOUSE_REPORT_NUMBER_BUTTON) 572 return; 573 574 button_report = (struct kovaplus_mouse_report_button const *)data; 575 576 if (button_report->type == KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_PROFILE_2) 577 return; 578 579 roccat_report.type = button_report->type; 580 roccat_report.profile = kovaplus->actual_profile + 1; 581 582 if (roccat_report.type == KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_MACRO || 583 roccat_report.type == KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_SHORTCUT || 584 roccat_report.type == KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_QUICKLAUNCH || 585 roccat_report.type == KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_TIMER) 586 roccat_report.button = button_report->data1; 587 else 588 roccat_report.button = 0; 589 590 if (roccat_report.type == KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_CPI) 591 roccat_report.data1 = kovaplus_convert_event_cpi(button_report->data1); 592 else 593 roccat_report.data1 = button_report->data1; 594 595 roccat_report.data2 = button_report->data2; 596 597 roccat_report_event(kovaplus->chrdev_minor, 598 (uint8_t const *)&roccat_report); 599 } 600 601 static int kovaplus_raw_event(struct hid_device *hdev, 602 struct hid_report *report, u8 *data, int size) 603 { 604 struct usb_interface *intf = to_usb_interface(hdev->dev.parent); 605 struct kovaplus_device *kovaplus = hid_get_drvdata(hdev); 606 607 if (intf->cur_altsetting->desc.bInterfaceProtocol 608 != USB_INTERFACE_PROTOCOL_MOUSE) 609 return 0; 610 611 if (kovaplus == NULL) 612 return 0; 613 614 kovaplus_keep_values_up_to_date(kovaplus, data); 615 616 if (kovaplus->roccat_claimed) 617 kovaplus_report_to_chrdev(kovaplus, data); 618 619 return 0; 620 } 621 622 static const struct hid_device_id kovaplus_devices[] = { 623 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KOVAPLUS) }, 624 { } 625 }; 626 627 MODULE_DEVICE_TABLE(hid, kovaplus_devices); 628 629 static struct hid_driver kovaplus_driver = { 630 .name = "kovaplus", 631 .id_table = kovaplus_devices, 632 .probe = kovaplus_probe, 633 .remove = kovaplus_remove, 634 .raw_event = kovaplus_raw_event 635 }; 636 637 static int __init kovaplus_init(void) 638 { 639 int retval; 640 641 kovaplus_class = class_create(THIS_MODULE, "kovaplus"); 642 if (IS_ERR(kovaplus_class)) 643 return PTR_ERR(kovaplus_class); 644 kovaplus_class->dev_groups = kovaplus_groups; 645 646 retval = hid_register_driver(&kovaplus_driver); 647 if (retval) 648 class_destroy(kovaplus_class); 649 return retval; 650 } 651 652 static void __exit kovaplus_exit(void) 653 { 654 hid_unregister_driver(&kovaplus_driver); 655 class_destroy(kovaplus_class); 656 } 657 658 module_init(kovaplus_init); 659 module_exit(kovaplus_exit); 660 661 MODULE_AUTHOR("Stefan Achatz"); 662 MODULE_DESCRIPTION("USB Roccat Kova[+] driver"); 663 MODULE_LICENSE("GPL v2"); 664