diff options
author | Stefan Achatz <erazor_de@users.sourceforge.net> | 2010-11-26 14:57:33 -0500 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2011-01-07 19:11:00 -0500 |
commit | 5012aada506cb8b570e46579077c0ec5b82ebd5d (patch) | |
tree | cf2d49567af63b16f7cdbef80ae5662938bd539c /drivers/hid/hid-roccat-kone.c | |
parent | c97415a72521071c235e0879f9a600014afd87b1 (diff) |
HID: roccat: use class for char device for sysfs attribute creation
Adding sysfs attributes to an already created device raises no userland
notification. Now the device drivers associate the devices attributes
with a class and use this for roccat event char device creation.
Signed-off-by: Stefan Achatz <erazor_de@users.sourceforge.net>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers/hid/hid-roccat-kone.c')
-rw-r--r-- | drivers/hid/hid-roccat-kone.c | 298 |
1 files changed, 127 insertions, 171 deletions
diff --git a/drivers/hid/hid-roccat-kone.c b/drivers/hid/hid-roccat-kone.c index 73199de2e37f..648d28e5f3f0 100644 --- a/drivers/hid/hid-roccat-kone.c +++ b/drivers/hid/hid-roccat-kone.c | |||
@@ -35,6 +35,9 @@ | |||
35 | #include "hid-roccat.h" | 35 | #include "hid-roccat.h" |
36 | #include "hid-roccat-kone.h" | 36 | #include "hid-roccat-kone.h" |
37 | 37 | ||
38 | /* kone_class is used for creating sysfs attributes via roccat char device */ | ||
39 | static struct class *kone_class; | ||
40 | |||
38 | static void kone_set_settings_checksum(struct kone_settings *settings) | 41 | static void kone_set_settings_checksum(struct kone_settings *settings) |
39 | { | 42 | { |
40 | uint16_t checksum = 0; | 43 | uint16_t checksum = 0; |
@@ -261,7 +264,8 @@ static int kone_get_firmware_version(struct usb_device *usb_dev, int *result) | |||
261 | static ssize_t kone_sysfs_read_settings(struct file *fp, struct kobject *kobj, | 264 | static ssize_t kone_sysfs_read_settings(struct file *fp, struct kobject *kobj, |
262 | struct bin_attribute *attr, char *buf, | 265 | struct bin_attribute *attr, char *buf, |
263 | loff_t off, size_t count) { | 266 | loff_t off, size_t count) { |
264 | struct device *dev = container_of(kobj, struct device, kobj); | 267 | struct device *dev = |
268 | container_of(kobj, struct device, kobj)->parent->parent; | ||
265 | struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); | 269 | struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); |
266 | 270 | ||
267 | if (off >= sizeof(struct kone_settings)) | 271 | if (off >= sizeof(struct kone_settings)) |
@@ -285,7 +289,8 @@ static ssize_t kone_sysfs_read_settings(struct file *fp, struct kobject *kobj, | |||
285 | static ssize_t kone_sysfs_write_settings(struct file *fp, struct kobject *kobj, | 289 | static ssize_t kone_sysfs_write_settings(struct file *fp, struct kobject *kobj, |
286 | struct bin_attribute *attr, char *buf, | 290 | struct bin_attribute *attr, char *buf, |
287 | loff_t off, size_t count) { | 291 | loff_t off, size_t count) { |
288 | struct device *dev = container_of(kobj, struct device, kobj); | 292 | struct device *dev = |
293 | container_of(kobj, struct device, kobj)->parent->parent; | ||
289 | struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); | 294 | struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); |
290 | struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); | 295 | struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); |
291 | int retval = 0, difference; | 296 | int retval = 0, difference; |
@@ -321,7 +326,8 @@ static ssize_t kone_sysfs_write_settings(struct file *fp, struct kobject *kobj, | |||
321 | static ssize_t kone_sysfs_read_profilex(struct kobject *kobj, | 326 | static ssize_t kone_sysfs_read_profilex(struct kobject *kobj, |
322 | struct bin_attribute *attr, char *buf, | 327 | struct bin_attribute *attr, char *buf, |
323 | loff_t off, size_t count, int number) { | 328 | loff_t off, size_t count, int number) { |
324 | struct device *dev = container_of(kobj, struct device, kobj); | 329 | struct device *dev = |
330 | container_of(kobj, struct device, kobj)->parent->parent; | ||
325 | struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); | 331 | struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); |
326 | 332 | ||
327 | if (off >= sizeof(struct kone_profile)) | 333 | if (off >= sizeof(struct kone_profile)) |
@@ -371,7 +377,8 @@ static ssize_t kone_sysfs_read_profile5(struct file *fp, struct kobject *kobj, | |||
371 | static ssize_t kone_sysfs_write_profilex(struct kobject *kobj, | 377 | static ssize_t kone_sysfs_write_profilex(struct kobject *kobj, |
372 | struct bin_attribute *attr, char *buf, | 378 | struct bin_attribute *attr, char *buf, |
373 | loff_t off, size_t count, int number) { | 379 | loff_t off, size_t count, int number) { |
374 | struct device *dev = container_of(kobj, struct device, kobj); | 380 | struct device *dev = |
381 | container_of(kobj, struct device, kobj)->parent->parent; | ||
375 | struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); | 382 | struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); |
376 | struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); | 383 | struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); |
377 | struct kone_profile *profile; | 384 | struct kone_profile *profile; |
@@ -432,14 +439,16 @@ static ssize_t kone_sysfs_write_profile5(struct file *fp, struct kobject *kobj, | |||
432 | static ssize_t kone_sysfs_show_actual_profile(struct device *dev, | 439 | static ssize_t kone_sysfs_show_actual_profile(struct device *dev, |
433 | struct device_attribute *attr, char *buf) | 440 | struct device_attribute *attr, char *buf) |
434 | { | 441 | { |
435 | struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); | 442 | struct kone_device *kone = |
443 | hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); | ||
436 | return snprintf(buf, PAGE_SIZE, "%d\n", kone->actual_profile); | 444 | return snprintf(buf, PAGE_SIZE, "%d\n", kone->actual_profile); |
437 | } | 445 | } |
438 | 446 | ||
439 | static ssize_t kone_sysfs_show_actual_dpi(struct device *dev, | 447 | static ssize_t kone_sysfs_show_actual_dpi(struct device *dev, |
440 | struct device_attribute *attr, char *buf) | 448 | struct device_attribute *attr, char *buf) |
441 | { | 449 | { |
442 | struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); | 450 | struct kone_device *kone = |
451 | hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); | ||
443 | return snprintf(buf, PAGE_SIZE, "%d\n", kone->actual_dpi); | 452 | return snprintf(buf, PAGE_SIZE, "%d\n", kone->actual_dpi); |
444 | } | 453 | } |
445 | 454 | ||
@@ -447,11 +456,15 @@ static ssize_t kone_sysfs_show_actual_dpi(struct device *dev, | |||
447 | static ssize_t kone_sysfs_show_weight(struct device *dev, | 456 | static ssize_t kone_sysfs_show_weight(struct device *dev, |
448 | struct device_attribute *attr, char *buf) | 457 | struct device_attribute *attr, char *buf) |
449 | { | 458 | { |
450 | struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); | 459 | struct kone_device *kone; |
451 | struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); | 460 | struct usb_device *usb_dev; |
452 | int weight = 0; | 461 | int weight = 0; |
453 | int retval; | 462 | int retval; |
454 | 463 | ||
464 | dev = dev->parent->parent; | ||
465 | kone = hid_get_drvdata(dev_get_drvdata(dev)); | ||
466 | usb_dev = interface_to_usbdev(to_usb_interface(dev)); | ||
467 | |||
455 | mutex_lock(&kone->kone_lock); | 468 | mutex_lock(&kone->kone_lock); |
456 | retval = kone_get_weight(usb_dev, &weight); | 469 | retval = kone_get_weight(usb_dev, &weight); |
457 | mutex_unlock(&kone->kone_lock); | 470 | mutex_unlock(&kone->kone_lock); |
@@ -464,14 +477,16 @@ static ssize_t kone_sysfs_show_weight(struct device *dev, | |||
464 | static ssize_t kone_sysfs_show_firmware_version(struct device *dev, | 477 | static ssize_t kone_sysfs_show_firmware_version(struct device *dev, |
465 | struct device_attribute *attr, char *buf) | 478 | struct device_attribute *attr, char *buf) |
466 | { | 479 | { |
467 | struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); | 480 | struct kone_device *kone = |
481 | hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); | ||
468 | return snprintf(buf, PAGE_SIZE, "%d\n", kone->firmware_version); | 482 | return snprintf(buf, PAGE_SIZE, "%d\n", kone->firmware_version); |
469 | } | 483 | } |
470 | 484 | ||
471 | static ssize_t kone_sysfs_show_tcu(struct device *dev, | 485 | static ssize_t kone_sysfs_show_tcu(struct device *dev, |
472 | struct device_attribute *attr, char *buf) | 486 | struct device_attribute *attr, char *buf) |
473 | { | 487 | { |
474 | struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); | 488 | struct kone_device *kone = |
489 | hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); | ||
475 | return snprintf(buf, PAGE_SIZE, "%d\n", kone->settings.tcu); | 490 | return snprintf(buf, PAGE_SIZE, "%d\n", kone->settings.tcu); |
476 | } | 491 | } |
477 | 492 | ||
@@ -503,11 +518,15 @@ static int kone_tcu_command(struct usb_device *usb_dev, int number) | |||
503 | static ssize_t kone_sysfs_set_tcu(struct device *dev, | 518 | static ssize_t kone_sysfs_set_tcu(struct device *dev, |
504 | struct device_attribute *attr, char const *buf, size_t size) | 519 | struct device_attribute *attr, char const *buf, size_t size) |
505 | { | 520 | { |
506 | struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); | 521 | struct kone_device *kone; |
507 | struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); | 522 | struct usb_device *usb_dev; |
508 | int retval; | 523 | int retval; |
509 | unsigned long state; | 524 | unsigned long state; |
510 | 525 | ||
526 | dev = dev->parent->parent; | ||
527 | kone = hid_get_drvdata(dev_get_drvdata(dev)); | ||
528 | usb_dev = interface_to_usbdev(to_usb_interface(dev)); | ||
529 | |||
511 | retval = strict_strtoul(buf, 10, &state); | 530 | retval = strict_strtoul(buf, 10, &state); |
512 | if (retval) | 531 | if (retval) |
513 | return retval; | 532 | return retval; |
@@ -578,18 +597,23 @@ exit_unlock: | |||
578 | static ssize_t kone_sysfs_show_startup_profile(struct device *dev, | 597 | static ssize_t kone_sysfs_show_startup_profile(struct device *dev, |
579 | struct device_attribute *attr, char *buf) | 598 | struct device_attribute *attr, char *buf) |
580 | { | 599 | { |
581 | struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); | 600 | struct kone_device *kone = |
601 | hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); | ||
582 | return snprintf(buf, PAGE_SIZE, "%d\n", kone->settings.startup_profile); | 602 | return snprintf(buf, PAGE_SIZE, "%d\n", kone->settings.startup_profile); |
583 | } | 603 | } |
584 | 604 | ||
585 | static ssize_t kone_sysfs_set_startup_profile(struct device *dev, | 605 | static ssize_t kone_sysfs_set_startup_profile(struct device *dev, |
586 | struct device_attribute *attr, char const *buf, size_t size) | 606 | struct device_attribute *attr, char const *buf, size_t size) |
587 | { | 607 | { |
588 | struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); | 608 | struct kone_device *kone; |
589 | struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); | 609 | struct usb_device *usb_dev; |
590 | int retval; | 610 | int retval; |
591 | unsigned long new_startup_profile; | 611 | unsigned long new_startup_profile; |
592 | 612 | ||
613 | dev = dev->parent->parent; | ||
614 | kone = hid_get_drvdata(dev_get_drvdata(dev)); | ||
615 | usb_dev = interface_to_usbdev(to_usb_interface(dev)); | ||
616 | |||
593 | retval = strict_strtoul(buf, 10, &new_startup_profile); | 617 | retval = strict_strtoul(buf, 10, &new_startup_profile); |
594 | if (retval) | 618 | if (retval) |
595 | return retval; | 619 | return retval; |
@@ -616,160 +640,87 @@ static ssize_t kone_sysfs_set_startup_profile(struct device *dev, | |||
616 | return size; | 640 | return size; |
617 | } | 641 | } |
618 | 642 | ||
619 | /* | 643 | static struct device_attribute kone_attributes[] = { |
620 | * Read actual dpi settings. | 644 | /* |
621 | * Returns raw value for further processing. Refer to enum kone_polling_rates to | 645 | * Read actual dpi settings. |
622 | * get real value. | 646 | * Returns raw value for further processing. Refer to enum |
623 | */ | 647 | * kone_polling_rates to get real value. |
624 | static DEVICE_ATTR(actual_dpi, 0440, kone_sysfs_show_actual_dpi, NULL); | 648 | */ |
625 | 649 | __ATTR(actual_dpi, 0440, kone_sysfs_show_actual_dpi, NULL), | |
626 | static DEVICE_ATTR(actual_profile, 0440, kone_sysfs_show_actual_profile, NULL); | 650 | __ATTR(actual_profile, 0440, kone_sysfs_show_actual_profile, NULL), |
627 | |||
628 | /* | ||
629 | * The mouse can be equipped with one of four supplied weights from 5 to 20 | ||
630 | * grams which are recognized and its value can be read out. | ||
631 | * This returns the raw value reported by the mouse for easy evaluation by | ||
632 | * software. Refer to enum kone_weights to get corresponding real weight. | ||
633 | */ | ||
634 | static DEVICE_ATTR(weight, 0440, kone_sysfs_show_weight, NULL); | ||
635 | |||
636 | /* | ||
637 | * Prints firmware version stored in mouse as integer. | ||
638 | * The raw value reported by the mouse is returned for easy evaluation, to get | ||
639 | * the real version number the decimal point has to be shifted 2 positions to | ||
640 | * the left. E.g. a value of 138 means 1.38. | ||
641 | */ | ||
642 | static DEVICE_ATTR(firmware_version, 0440, | ||
643 | kone_sysfs_show_firmware_version, NULL); | ||
644 | |||
645 | /* | ||
646 | * Prints state of Tracking Control Unit as number where 0 = off and 1 = on | ||
647 | * Writing 0 deactivates tcu and writing 1 calibrates and activates the tcu | ||
648 | */ | ||
649 | static DEVICE_ATTR(tcu, 0660, kone_sysfs_show_tcu, kone_sysfs_set_tcu); | ||
650 | |||
651 | /* Prints and takes the number of the profile the mouse starts with */ | ||
652 | static DEVICE_ATTR(startup_profile, 0660, | ||
653 | kone_sysfs_show_startup_profile, | ||
654 | kone_sysfs_set_startup_profile); | ||
655 | |||
656 | static struct attribute *kone_attributes[] = { | ||
657 | &dev_attr_actual_dpi.attr, | ||
658 | &dev_attr_actual_profile.attr, | ||
659 | &dev_attr_weight.attr, | ||
660 | &dev_attr_firmware_version.attr, | ||
661 | &dev_attr_tcu.attr, | ||
662 | &dev_attr_startup_profile.attr, | ||
663 | NULL | ||
664 | }; | ||
665 | |||
666 | static struct attribute_group kone_attribute_group = { | ||
667 | .attrs = kone_attributes | ||
668 | }; | ||
669 | |||
670 | static struct bin_attribute kone_settings_attr = { | ||
671 | .attr = { .name = "settings", .mode = 0660 }, | ||
672 | .size = sizeof(struct kone_settings), | ||
673 | .read = kone_sysfs_read_settings, | ||
674 | .write = kone_sysfs_write_settings | ||
675 | }; | ||
676 | 651 | ||
677 | static struct bin_attribute kone_profile1_attr = { | 652 | /* |
678 | .attr = { .name = "profile1", .mode = 0660 }, | 653 | * The mouse can be equipped with one of four supplied weights from 5 |
679 | .size = sizeof(struct kone_profile), | 654 | * to 20 grams which are recognized and its value can be read out. |
680 | .read = kone_sysfs_read_profile1, | 655 | * This returns the raw value reported by the mouse for easy evaluation |
681 | .write = kone_sysfs_write_profile1 | 656 | * by software. Refer to enum kone_weights to get corresponding real |
682 | }; | 657 | * weight. |
658 | */ | ||
659 | __ATTR(weight, 0440, kone_sysfs_show_weight, NULL), | ||
683 | 660 | ||
684 | static struct bin_attribute kone_profile2_attr = { | 661 | /* |
685 | .attr = { .name = "profile2", .mode = 0660 }, | 662 | * Prints firmware version stored in mouse as integer. |
686 | .size = sizeof(struct kone_profile), | 663 | * The raw value reported by the mouse is returned for easy evaluation, |
687 | .read = kone_sysfs_read_profile2, | 664 | * to get the real version number the decimal point has to be shifted 2 |
688 | .write = kone_sysfs_write_profile2 | 665 | * positions to the left. E.g. a value of 138 means 1.38. |
689 | }; | 666 | */ |
667 | __ATTR(firmware_version, 0440, | ||
668 | kone_sysfs_show_firmware_version, NULL), | ||
690 | 669 | ||
691 | static struct bin_attribute kone_profile3_attr = { | 670 | /* |
692 | .attr = { .name = "profile3", .mode = 0660 }, | 671 | * Prints state of Tracking Control Unit as number where 0 = off and |
693 | .size = sizeof(struct kone_profile), | 672 | * 1 = on. Writing 0 deactivates tcu and writing 1 calibrates and |
694 | .read = kone_sysfs_read_profile3, | 673 | * activates the tcu |
695 | .write = kone_sysfs_write_profile3 | 674 | */ |
696 | }; | 675 | __ATTR(tcu, 0660, kone_sysfs_show_tcu, kone_sysfs_set_tcu), |
697 | 676 | ||
698 | static struct bin_attribute kone_profile4_attr = { | 677 | /* Prints and takes the number of the profile the mouse starts with */ |
699 | .attr = { .name = "profile4", .mode = 0660 }, | 678 | __ATTR(startup_profile, 0660, |
700 | .size = sizeof(struct kone_profile), | 679 | kone_sysfs_show_startup_profile, |
701 | .read = kone_sysfs_read_profile4, | 680 | kone_sysfs_set_startup_profile), |
702 | .write = kone_sysfs_write_profile4 | 681 | __ATTR_NULL |
703 | }; | 682 | }; |
704 | 683 | ||
705 | static struct bin_attribute kone_profile5_attr = { | 684 | static struct bin_attribute kone_bin_attributes[] = { |
706 | .attr = { .name = "profile5", .mode = 0660 }, | 685 | { |
707 | .size = sizeof(struct kone_profile), | 686 | .attr = { .name = "settings", .mode = 0660 }, |
708 | .read = kone_sysfs_read_profile5, | 687 | .size = sizeof(struct kone_settings), |
709 | .write = kone_sysfs_write_profile5 | 688 | .read = kone_sysfs_read_settings, |
689 | .write = kone_sysfs_write_settings | ||
690 | }, | ||
691 | { | ||
692 | .attr = { .name = "profile1", .mode = 0660 }, | ||
693 | .size = sizeof(struct kone_profile), | ||
694 | .read = kone_sysfs_read_profile1, | ||
695 | .write = kone_sysfs_write_profile1 | ||
696 | }, | ||
697 | { | ||
698 | .attr = { .name = "profile2", .mode = 0660 }, | ||
699 | .size = sizeof(struct kone_profile), | ||
700 | .read = kone_sysfs_read_profile2, | ||
701 | .write = kone_sysfs_write_profile2 | ||
702 | }, | ||
703 | { | ||
704 | .attr = { .name = "profile3", .mode = 0660 }, | ||
705 | .size = sizeof(struct kone_profile), | ||
706 | .read = kone_sysfs_read_profile3, | ||
707 | .write = kone_sysfs_write_profile3 | ||
708 | }, | ||
709 | { | ||
710 | .attr = { .name = "profile4", .mode = 0660 }, | ||
711 | .size = sizeof(struct kone_profile), | ||
712 | .read = kone_sysfs_read_profile4, | ||
713 | .write = kone_sysfs_write_profile4 | ||
714 | }, | ||
715 | { | ||
716 | .attr = { .name = "profile5", .mode = 0660 }, | ||
717 | .size = sizeof(struct kone_profile), | ||
718 | .read = kone_sysfs_read_profile5, | ||
719 | .write = kone_sysfs_write_profile5 | ||
720 | }, | ||
721 | __ATTR_NULL | ||
710 | }; | 722 | }; |
711 | 723 | ||
712 | static int kone_create_sysfs_attributes(struct usb_interface *intf) | ||
713 | { | ||
714 | int retval; | ||
715 | |||
716 | retval = sysfs_create_group(&intf->dev.kobj, &kone_attribute_group); | ||
717 | if (retval) | ||
718 | goto exit_1; | ||
719 | |||
720 | retval = sysfs_create_bin_file(&intf->dev.kobj, &kone_settings_attr); | ||
721 | if (retval) | ||
722 | goto exit_2; | ||
723 | |||
724 | retval = sysfs_create_bin_file(&intf->dev.kobj, &kone_profile1_attr); | ||
725 | if (retval) | ||
726 | goto exit_3; | ||
727 | |||
728 | retval = sysfs_create_bin_file(&intf->dev.kobj, &kone_profile2_attr); | ||
729 | if (retval) | ||
730 | goto exit_4; | ||
731 | |||
732 | retval = sysfs_create_bin_file(&intf->dev.kobj, &kone_profile3_attr); | ||
733 | if (retval) | ||
734 | goto exit_5; | ||
735 | |||
736 | retval = sysfs_create_bin_file(&intf->dev.kobj, &kone_profile4_attr); | ||
737 | if (retval) | ||
738 | goto exit_6; | ||
739 | |||
740 | retval = sysfs_create_bin_file(&intf->dev.kobj, &kone_profile5_attr); | ||
741 | if (retval) | ||
742 | goto exit_7; | ||
743 | |||
744 | return 0; | ||
745 | |||
746 | exit_7: | ||
747 | sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile4_attr); | ||
748 | exit_6: | ||
749 | sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile3_attr); | ||
750 | exit_5: | ||
751 | sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile2_attr); | ||
752 | exit_4: | ||
753 | sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile1_attr); | ||
754 | exit_3: | ||
755 | sysfs_remove_bin_file(&intf->dev.kobj, &kone_settings_attr); | ||
756 | exit_2: | ||
757 | sysfs_remove_group(&intf->dev.kobj, &kone_attribute_group); | ||
758 | exit_1: | ||
759 | return retval; | ||
760 | } | ||
761 | |||
762 | static void kone_remove_sysfs_attributes(struct usb_interface *intf) | ||
763 | { | ||
764 | sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile5_attr); | ||
765 | sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile4_attr); | ||
766 | sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile3_attr); | ||
767 | sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile2_attr); | ||
768 | sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile1_attr); | ||
769 | sysfs_remove_bin_file(&intf->dev.kobj, &kone_settings_attr); | ||
770 | sysfs_remove_group(&intf->dev.kobj, &kone_attribute_group); | ||
771 | } | ||
772 | |||
773 | static int kone_init_kone_device_struct(struct usb_device *usb_dev, | 724 | static int kone_init_kone_device_struct(struct usb_device *usb_dev, |
774 | struct kone_device *kone) | 725 | struct kone_device *kone) |
775 | { | 726 | { |
@@ -828,7 +779,7 @@ static int kone_init_specials(struct hid_device *hdev) | |||
828 | goto exit_free; | 779 | goto exit_free; |
829 | } | 780 | } |
830 | 781 | ||
831 | retval = roccat_connect(hdev); | 782 | retval = roccat_connect(kone_class, hdev); |
832 | if (retval < 0) { | 783 | if (retval < 0) { |
833 | hid_err(hdev, "couldn't init char dev\n"); | 784 | hid_err(hdev, "couldn't init char dev\n"); |
834 | /* be tolerant about not getting chrdev */ | 785 | /* be tolerant about not getting chrdev */ |
@@ -836,12 +787,6 @@ static int kone_init_specials(struct hid_device *hdev) | |||
836 | kone->roccat_claimed = 1; | 787 | kone->roccat_claimed = 1; |
837 | kone->chrdev_minor = retval; | 788 | kone->chrdev_minor = retval; |
838 | } | 789 | } |
839 | |||
840 | retval = kone_create_sysfs_attributes(intf); | ||
841 | if (retval) { | ||
842 | hid_err(hdev, "cannot create sysfs files\n"); | ||
843 | goto exit_free; | ||
844 | } | ||
845 | } else { | 790 | } else { |
846 | hid_set_drvdata(hdev, NULL); | 791 | hid_set_drvdata(hdev, NULL); |
847 | } | 792 | } |
@@ -852,7 +797,6 @@ exit_free: | |||
852 | return retval; | 797 | return retval; |
853 | } | 798 | } |
854 | 799 | ||
855 | |||
856 | static void kone_remove_specials(struct hid_device *hdev) | 800 | static void kone_remove_specials(struct hid_device *hdev) |
857 | { | 801 | { |
858 | struct usb_interface *intf = to_usb_interface(hdev->dev.parent); | 802 | struct usb_interface *intf = to_usb_interface(hdev->dev.parent); |
@@ -860,7 +804,6 @@ static void kone_remove_specials(struct hid_device *hdev) | |||
860 | 804 | ||
861 | if (intf->cur_altsetting->desc.bInterfaceProtocol | 805 | if (intf->cur_altsetting->desc.bInterfaceProtocol |
862 | == USB_INTERFACE_PROTOCOL_MOUSE) { | 806 | == USB_INTERFACE_PROTOCOL_MOUSE) { |
863 | kone_remove_sysfs_attributes(intf); | ||
864 | kone = hid_get_drvdata(hdev); | 807 | kone = hid_get_drvdata(hdev); |
865 | if (kone->roccat_claimed) | 808 | if (kone->roccat_claimed) |
866 | roccat_disconnect(kone->chrdev_minor); | 809 | roccat_disconnect(kone->chrdev_minor); |
@@ -1004,11 +947,24 @@ static struct hid_driver kone_driver = { | |||
1004 | 947 | ||
1005 | static int __init kone_init(void) | 948 | static int __init kone_init(void) |
1006 | { | 949 | { |
1007 | return hid_register_driver(&kone_driver); | 950 | int retval; |
951 | |||
952 | /* class name has to be same as driver name */ | ||
953 | kone_class = class_create(THIS_MODULE, "kone"); | ||
954 | if (IS_ERR(kone_class)) | ||
955 | return PTR_ERR(kone_class); | ||
956 | kone_class->dev_attrs = kone_attributes; | ||
957 | kone_class->dev_bin_attrs = kone_bin_attributes; | ||
958 | |||
959 | retval = hid_register_driver(&kone_driver); | ||
960 | if (retval) | ||
961 | class_destroy(kone_class); | ||
962 | return retval; | ||
1008 | } | 963 | } |
1009 | 964 | ||
1010 | static void __exit kone_exit(void) | 965 | static void __exit kone_exit(void) |
1011 | { | 966 | { |
967 | class_destroy(kone_class); | ||
1012 | hid_unregister_driver(&kone_driver); | 968 | hid_unregister_driver(&kone_driver); |
1013 | } | 969 | } |
1014 | 970 | ||