Commit 5012aada506cb8b570e46579077c0ec5b82ebd5d
Committed by
Jiri Kosina
1 parent
c97415a725
Exists in
master
and in
39 other branches
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>
Showing 4 changed files with 209 additions and 384 deletions Side-by-side Diff
drivers/hid/hid-roccat-kone.c
... | ... | @@ -35,6 +35,9 @@ |
35 | 35 | #include "hid-roccat.h" |
36 | 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 | 41 | static void kone_set_settings_checksum(struct kone_settings *settings) |
39 | 42 | { |
40 | 43 | uint16_t checksum = 0; |
... | ... | @@ -261,7 +264,8 @@ |
261 | 264 | static ssize_t kone_sysfs_read_settings(struct file *fp, struct kobject *kobj, |
262 | 265 | struct bin_attribute *attr, char *buf, |
263 | 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 | 269 | struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); |
266 | 270 | |
267 | 271 | if (off >= sizeof(struct kone_settings)) |
... | ... | @@ -285,7 +289,8 @@ |
285 | 289 | static ssize_t kone_sysfs_write_settings(struct file *fp, struct kobject *kobj, |
286 | 290 | struct bin_attribute *attr, char *buf, |
287 | 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 | 294 | struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); |
290 | 295 | struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); |
291 | 296 | int retval = 0, difference; |
... | ... | @@ -321,7 +326,8 @@ |
321 | 326 | static ssize_t kone_sysfs_read_profilex(struct kobject *kobj, |
322 | 327 | struct bin_attribute *attr, char *buf, |
323 | 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 | 331 | struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); |
326 | 332 | |
327 | 333 | if (off >= sizeof(struct kone_profile)) |
... | ... | @@ -371,7 +377,8 @@ |
371 | 377 | static ssize_t kone_sysfs_write_profilex(struct kobject *kobj, |
372 | 378 | struct bin_attribute *attr, char *buf, |
373 | 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 | 382 | struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); |
376 | 383 | struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); |
377 | 384 | struct kone_profile *profile; |
378 | 385 | |
... | ... | @@ -432,14 +439,16 @@ |
432 | 439 | static ssize_t kone_sysfs_show_actual_profile(struct device *dev, |
433 | 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 | 444 | return snprintf(buf, PAGE_SIZE, "%d\n", kone->actual_profile); |
437 | 445 | } |
438 | 446 | |
439 | 447 | static ssize_t kone_sysfs_show_actual_dpi(struct device *dev, |
440 | 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 | 452 | return snprintf(buf, PAGE_SIZE, "%d\n", kone->actual_dpi); |
444 | 453 | } |
445 | 454 | |
446 | 455 | |
... | ... | @@ -447,11 +456,15 @@ |
447 | 456 | static ssize_t kone_sysfs_show_weight(struct device *dev, |
448 | 457 | struct device_attribute *attr, char *buf) |
449 | 458 | { |
450 | - struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); | |
451 | - struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); | |
459 | + struct kone_device *kone; | |
460 | + struct usb_device *usb_dev; | |
452 | 461 | int weight = 0; |
453 | 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 | 468 | mutex_lock(&kone->kone_lock); |
456 | 469 | retval = kone_get_weight(usb_dev, &weight); |
457 | 470 | mutex_unlock(&kone->kone_lock); |
458 | 471 | |
... | ... | @@ -464,14 +477,16 @@ |
464 | 477 | static ssize_t kone_sysfs_show_firmware_version(struct device *dev, |
465 | 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 | 482 | return snprintf(buf, PAGE_SIZE, "%d\n", kone->firmware_version); |
469 | 483 | } |
470 | 484 | |
471 | 485 | static ssize_t kone_sysfs_show_tcu(struct device *dev, |
472 | 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 | 490 | return snprintf(buf, PAGE_SIZE, "%d\n", kone->settings.tcu); |
476 | 491 | } |
477 | 492 | |
478 | 493 | |
... | ... | @@ -503,11 +518,15 @@ |
503 | 518 | static ssize_t kone_sysfs_set_tcu(struct device *dev, |
504 | 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)); | |
507 | - struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); | |
521 | + struct kone_device *kone; | |
522 | + struct usb_device *usb_dev; | |
508 | 523 | int retval; |
509 | 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 | 530 | retval = strict_strtoul(buf, 10, &state); |
512 | 531 | if (retval) |
513 | 532 | return retval; |
514 | 533 | |
515 | 534 | |
... | ... | @@ -578,18 +597,23 @@ |
578 | 597 | static ssize_t kone_sysfs_show_startup_profile(struct device *dev, |
579 | 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 | 602 | return snprintf(buf, PAGE_SIZE, "%d\n", kone->settings.startup_profile); |
583 | 603 | } |
584 | 604 | |
585 | 605 | static ssize_t kone_sysfs_set_startup_profile(struct device *dev, |
586 | 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)); | |
589 | - struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); | |
608 | + struct kone_device *kone; | |
609 | + struct usb_device *usb_dev; | |
590 | 610 | int retval; |
591 | 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 | 617 | retval = strict_strtoul(buf, 10, &new_startup_profile); |
594 | 618 | if (retval) |
595 | 619 | return retval; |
596 | 620 | |
597 | 621 | |
598 | 622 | |
599 | 623 | |
600 | 624 | |
601 | 625 | |
... | ... | @@ -616,160 +640,87 @@ |
616 | 640 | return size; |
617 | 641 | } |
618 | 642 | |
619 | -/* | |
620 | - * Read actual dpi settings. | |
621 | - * Returns raw value for further processing. Refer to enum kone_polling_rates to | |
622 | - * get real value. | |
623 | - */ | |
624 | -static DEVICE_ATTR(actual_dpi, 0440, kone_sysfs_show_actual_dpi, NULL); | |
643 | +static struct device_attribute kone_attributes[] = { | |
644 | + /* | |
645 | + * Read actual dpi settings. | |
646 | + * Returns raw value for further processing. Refer to enum | |
647 | + * kone_polling_rates to get real value. | |
648 | + */ | |
649 | + __ATTR(actual_dpi, 0440, kone_sysfs_show_actual_dpi, NULL), | |
650 | + __ATTR(actual_profile, 0440, kone_sysfs_show_actual_profile, NULL), | |
625 | 651 | |
626 | -static DEVICE_ATTR(actual_profile, 0440, kone_sysfs_show_actual_profile, NULL); | |
652 | + /* | |
653 | + * The mouse can be equipped with one of four supplied weights from 5 | |
654 | + * to 20 grams which are recognized and its value can be read out. | |
655 | + * This returns the raw value reported by the mouse for easy evaluation | |
656 | + * by software. Refer to enum kone_weights to get corresponding real | |
657 | + * weight. | |
658 | + */ | |
659 | + __ATTR(weight, 0440, kone_sysfs_show_weight, NULL), | |
627 | 660 | |
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); | |
661 | + /* | |
662 | + * Prints firmware version stored in mouse as integer. | |
663 | + * The raw value reported by the mouse is returned for easy evaluation, | |
664 | + * to get the real version number the decimal point has to be shifted 2 | |
665 | + * positions to the left. E.g. a value of 138 means 1.38. | |
666 | + */ | |
667 | + __ATTR(firmware_version, 0440, | |
668 | + kone_sysfs_show_firmware_version, NULL), | |
635 | 669 | |
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); | |
670 | + /* | |
671 | + * Prints state of Tracking Control Unit as number where 0 = off and | |
672 | + * 1 = on. Writing 0 deactivates tcu and writing 1 calibrates and | |
673 | + * activates the tcu | |
674 | + */ | |
675 | + __ATTR(tcu, 0660, kone_sysfs_show_tcu, kone_sysfs_set_tcu), | |
644 | 676 | |
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 | |
677 | + /* Prints and takes the number of the profile the mouse starts with */ | |
678 | + __ATTR(startup_profile, 0660, | |
679 | + kone_sysfs_show_startup_profile, | |
680 | + kone_sysfs_set_startup_profile), | |
681 | + __ATTR_NULL | |
664 | 682 | }; |
665 | 683 | |
666 | -static struct attribute_group kone_attribute_group = { | |
667 | - .attrs = kone_attributes | |
684 | +static struct bin_attribute kone_bin_attributes[] = { | |
685 | + { | |
686 | + .attr = { .name = "settings", .mode = 0660 }, | |
687 | + .size = sizeof(struct kone_settings), | |
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 | |
668 | 722 | }; |
669 | 723 | |
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 | - | |
677 | -static struct bin_attribute kone_profile1_attr = { | |
678 | - .attr = { .name = "profile1", .mode = 0660 }, | |
679 | - .size = sizeof(struct kone_profile), | |
680 | - .read = kone_sysfs_read_profile1, | |
681 | - .write = kone_sysfs_write_profile1 | |
682 | -}; | |
683 | - | |
684 | -static struct bin_attribute kone_profile2_attr = { | |
685 | - .attr = { .name = "profile2", .mode = 0660 }, | |
686 | - .size = sizeof(struct kone_profile), | |
687 | - .read = kone_sysfs_read_profile2, | |
688 | - .write = kone_sysfs_write_profile2 | |
689 | -}; | |
690 | - | |
691 | -static struct bin_attribute kone_profile3_attr = { | |
692 | - .attr = { .name = "profile3", .mode = 0660 }, | |
693 | - .size = sizeof(struct kone_profile), | |
694 | - .read = kone_sysfs_read_profile3, | |
695 | - .write = kone_sysfs_write_profile3 | |
696 | -}; | |
697 | - | |
698 | -static struct bin_attribute kone_profile4_attr = { | |
699 | - .attr = { .name = "profile4", .mode = 0660 }, | |
700 | - .size = sizeof(struct kone_profile), | |
701 | - .read = kone_sysfs_read_profile4, | |
702 | - .write = kone_sysfs_write_profile4 | |
703 | -}; | |
704 | - | |
705 | -static struct bin_attribute kone_profile5_attr = { | |
706 | - .attr = { .name = "profile5", .mode = 0660 }, | |
707 | - .size = sizeof(struct kone_profile), | |
708 | - .read = kone_sysfs_read_profile5, | |
709 | - .write = kone_sysfs_write_profile5 | |
710 | -}; | |
711 | - | |
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 | 724 | static int kone_init_kone_device_struct(struct usb_device *usb_dev, |
774 | 725 | struct kone_device *kone) |
775 | 726 | { |
... | ... | @@ -828,7 +779,7 @@ |
828 | 779 | goto exit_free; |
829 | 780 | } |
830 | 781 | |
831 | - retval = roccat_connect(hdev); | |
782 | + retval = roccat_connect(kone_class, hdev); | |
832 | 783 | if (retval < 0) { |
833 | 784 | hid_err(hdev, "couldn't init char dev\n"); |
834 | 785 | /* be tolerant about not getting chrdev */ |
... | ... | @@ -836,12 +787,6 @@ |
836 | 787 | kone->roccat_claimed = 1; |
837 | 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 | 790 | } else { |
846 | 791 | hid_set_drvdata(hdev, NULL); |
847 | 792 | } |
... | ... | @@ -852,7 +797,6 @@ |
852 | 797 | return retval; |
853 | 798 | } |
854 | 799 | |
855 | - | |
856 | 800 | static void kone_remove_specials(struct hid_device *hdev) |
857 | 801 | { |
858 | 802 | struct usb_interface *intf = to_usb_interface(hdev->dev.parent); |
... | ... | @@ -860,7 +804,6 @@ |
860 | 804 | |
861 | 805 | if (intf->cur_altsetting->desc.bInterfaceProtocol |
862 | 806 | == USB_INTERFACE_PROTOCOL_MOUSE) { |
863 | - kone_remove_sysfs_attributes(intf); | |
864 | 807 | kone = hid_get_drvdata(hdev); |
865 | 808 | if (kone->roccat_claimed) |
866 | 809 | roccat_disconnect(kone->chrdev_minor); |
867 | 810 | |
... | ... | @@ -1004,11 +947,24 @@ |
1004 | 947 | |
1005 | 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 | 965 | static void __exit kone_exit(void) |
1011 | 966 | { |
967 | + class_destroy(kone_class); | |
1012 | 968 | hid_unregister_driver(&kone_driver); |
1013 | 969 | } |
1014 | 970 |
drivers/hid/hid-roccat-pyra.c
... | ... | @@ -27,6 +27,9 @@ |
27 | 27 | #include "hid-roccat.h" |
28 | 28 | #include "hid-roccat-pyra.h" |
29 | 29 | |
30 | +/* pyra_class is used for creating sysfs attributes via roccat char device */ | |
31 | +static struct class *pyra_class; | |
32 | + | |
30 | 33 | static void profile_activated(struct pyra_device *pyra, |
31 | 34 | unsigned int new_profile) |
32 | 35 | { |
... | ... | @@ -222,7 +225,8 @@ |
222 | 225 | struct kobject *kobj, struct bin_attribute *attr, char *buf, |
223 | 226 | loff_t off, size_t count, int number) |
224 | 227 | { |
225 | - struct device *dev = container_of(kobj, struct device, kobj); | |
228 | + struct device *dev = | |
229 | + container_of(kobj, struct device, kobj)->parent->parent; | |
226 | 230 | struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev)); |
227 | 231 | |
228 | 232 | if (off >= sizeof(struct pyra_profile_settings)) |
... | ... | @@ -283,7 +287,8 @@ |
283 | 287 | struct kobject *kobj, struct bin_attribute *attr, char *buf, |
284 | 288 | loff_t off, size_t count, int number) |
285 | 289 | { |
286 | - struct device *dev = container_of(kobj, struct device, kobj); | |
290 | + struct device *dev = | |
291 | + container_of(kobj, struct device, kobj)->parent->parent; | |
287 | 292 | struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev)); |
288 | 293 | |
289 | 294 | if (off >= sizeof(struct pyra_profile_buttons)) |
... | ... | @@ -344,7 +349,8 @@ |
344 | 349 | struct kobject *kobj, struct bin_attribute *attr, char *buf, |
345 | 350 | loff_t off, size_t count) |
346 | 351 | { |
347 | - struct device *dev = container_of(kobj, struct device, kobj); | |
352 | + struct device *dev = | |
353 | + container_of(kobj, struct device, kobj)->parent->parent; | |
348 | 354 | struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev)); |
349 | 355 | struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); |
350 | 356 | int retval = 0; |
... | ... | @@ -380,7 +386,8 @@ |
380 | 386 | struct kobject *kobj, struct bin_attribute *attr, char *buf, |
381 | 387 | loff_t off, size_t count) |
382 | 388 | { |
383 | - struct device *dev = container_of(kobj, struct device, kobj); | |
389 | + struct device *dev = | |
390 | + container_of(kobj, struct device, kobj)->parent->parent; | |
384 | 391 | struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev)); |
385 | 392 | struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); |
386 | 393 | int retval = 0; |
... | ... | @@ -416,7 +423,8 @@ |
416 | 423 | struct kobject *kobj, struct bin_attribute *attr, char *buf, |
417 | 424 | loff_t off, size_t count) |
418 | 425 | { |
419 | - struct device *dev = container_of(kobj, struct device, kobj); | |
426 | + struct device *dev = | |
427 | + container_of(kobj, struct device, kobj)->parent->parent; | |
420 | 428 | struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev)); |
421 | 429 | |
422 | 430 | if (off >= sizeof(struct pyra_settings)) |
... | ... | @@ -436,7 +444,8 @@ |
436 | 444 | struct kobject *kobj, struct bin_attribute *attr, char *buf, |
437 | 445 | loff_t off, size_t count) |
438 | 446 | { |
439 | - struct device *dev = container_of(kobj, struct device, kobj); | |
447 | + struct device *dev = | |
448 | + container_of(kobj, struct device, kobj)->parent->parent; | |
440 | 449 | struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev)); |
441 | 450 | struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); |
442 | 451 | int retval = 0; |
443 | 452 | |
444 | 453 | |
445 | 454 | |
446 | 455 | |
447 | 456 | |
448 | 457 | |
449 | 458 | |
450 | 459 | |
451 | 460 | |
452 | 461 | |
453 | 462 | |
454 | 463 | |
455 | 464 | |
456 | 465 | |
457 | 466 | |
458 | 467 | |
459 | 468 | |
460 | 469 | |
461 | 470 | |
... | ... | @@ -468,255 +477,115 @@ |
468 | 477 | static ssize_t pyra_sysfs_show_actual_cpi(struct device *dev, |
469 | 478 | struct device_attribute *attr, char *buf) |
470 | 479 | { |
471 | - struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev)); | |
480 | + struct pyra_device *pyra = | |
481 | + hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); | |
472 | 482 | return snprintf(buf, PAGE_SIZE, "%d\n", pyra->actual_cpi); |
473 | 483 | } |
474 | 484 | |
475 | 485 | static ssize_t pyra_sysfs_show_actual_profile(struct device *dev, |
476 | 486 | struct device_attribute *attr, char *buf) |
477 | 487 | { |
478 | - struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev)); | |
488 | + struct pyra_device *pyra = | |
489 | + hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); | |
479 | 490 | return snprintf(buf, PAGE_SIZE, "%d\n", pyra->actual_profile); |
480 | 491 | } |
481 | 492 | |
482 | 493 | static ssize_t pyra_sysfs_show_firmware_version(struct device *dev, |
483 | 494 | struct device_attribute *attr, char *buf) |
484 | 495 | { |
485 | - struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev)); | |
496 | + struct pyra_device *pyra = | |
497 | + hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); | |
486 | 498 | return snprintf(buf, PAGE_SIZE, "%d\n", pyra->firmware_version); |
487 | 499 | } |
488 | 500 | |
489 | 501 | static ssize_t pyra_sysfs_show_startup_profile(struct device *dev, |
490 | 502 | struct device_attribute *attr, char *buf) |
491 | 503 | { |
492 | - struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev)); | |
504 | + struct pyra_device *pyra = | |
505 | + hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); | |
493 | 506 | return snprintf(buf, PAGE_SIZE, "%d\n", pyra->settings.startup_profile); |
494 | 507 | } |
495 | 508 | |
496 | -static DEVICE_ATTR(actual_cpi, 0440, pyra_sysfs_show_actual_cpi, NULL); | |
497 | - | |
498 | -static DEVICE_ATTR(actual_profile, 0440, pyra_sysfs_show_actual_profile, NULL); | |
499 | - | |
500 | -static DEVICE_ATTR(firmware_version, 0440, | |
501 | - pyra_sysfs_show_firmware_version, NULL); | |
502 | - | |
503 | -static DEVICE_ATTR(startup_profile, 0440, | |
504 | - pyra_sysfs_show_startup_profile, NULL); | |
505 | - | |
506 | -static struct attribute *pyra_attributes[] = { | |
507 | - &dev_attr_actual_cpi.attr, | |
508 | - &dev_attr_actual_profile.attr, | |
509 | - &dev_attr_firmware_version.attr, | |
510 | - &dev_attr_startup_profile.attr, | |
511 | - NULL | |
509 | +static struct device_attribute pyra_attributes[] = { | |
510 | + __ATTR(actual_cpi, 0440, pyra_sysfs_show_actual_cpi, NULL), | |
511 | + __ATTR(actual_profile, 0440, pyra_sysfs_show_actual_profile, NULL), | |
512 | + __ATTR(firmware_version, 0440, | |
513 | + pyra_sysfs_show_firmware_version, NULL), | |
514 | + __ATTR(startup_profile, 0440, | |
515 | + pyra_sysfs_show_startup_profile, NULL), | |
516 | + __ATTR_NULL | |
512 | 517 | }; |
513 | 518 | |
514 | -static struct attribute_group pyra_attribute_group = { | |
515 | - .attrs = pyra_attributes | |
516 | -}; | |
517 | - | |
518 | -static struct bin_attribute pyra_profile_settings_attr = { | |
519 | +static struct bin_attribute pyra_bin_attributes[] = { | |
520 | + { | |
519 | 521 | .attr = { .name = "profile_settings", .mode = 0220 }, |
520 | 522 | .size = sizeof(struct pyra_profile_settings), |
521 | 523 | .write = pyra_sysfs_write_profile_settings |
522 | -}; | |
523 | - | |
524 | -static struct bin_attribute pyra_profile1_settings_attr = { | |
524 | + }, | |
525 | + { | |
525 | 526 | .attr = { .name = "profile1_settings", .mode = 0440 }, |
526 | 527 | .size = sizeof(struct pyra_profile_settings), |
527 | 528 | .read = pyra_sysfs_read_profile1_settings |
528 | -}; | |
529 | - | |
530 | -static struct bin_attribute pyra_profile2_settings_attr = { | |
529 | + }, | |
530 | + { | |
531 | 531 | .attr = { .name = "profile2_settings", .mode = 0440 }, |
532 | 532 | .size = sizeof(struct pyra_profile_settings), |
533 | 533 | .read = pyra_sysfs_read_profile2_settings |
534 | -}; | |
535 | - | |
536 | -static struct bin_attribute pyra_profile3_settings_attr = { | |
534 | + }, | |
535 | + { | |
537 | 536 | .attr = { .name = "profile3_settings", .mode = 0440 }, |
538 | 537 | .size = sizeof(struct pyra_profile_settings), |
539 | 538 | .read = pyra_sysfs_read_profile3_settings |
540 | -}; | |
541 | - | |
542 | -static struct bin_attribute pyra_profile4_settings_attr = { | |
539 | + }, | |
540 | + { | |
543 | 541 | .attr = { .name = "profile4_settings", .mode = 0440 }, |
544 | 542 | .size = sizeof(struct pyra_profile_settings), |
545 | 543 | .read = pyra_sysfs_read_profile4_settings |
546 | -}; | |
547 | - | |
548 | -static struct bin_attribute pyra_profile5_settings_attr = { | |
544 | + }, | |
545 | + { | |
549 | 546 | .attr = { .name = "profile5_settings", .mode = 0440 }, |
550 | 547 | .size = sizeof(struct pyra_profile_settings), |
551 | 548 | .read = pyra_sysfs_read_profile5_settings |
552 | -}; | |
553 | - | |
554 | -static struct bin_attribute pyra_profile_buttons_attr = { | |
549 | + }, | |
550 | + { | |
555 | 551 | .attr = { .name = "profile_buttons", .mode = 0220 }, |
556 | 552 | .size = sizeof(struct pyra_profile_buttons), |
557 | 553 | .write = pyra_sysfs_write_profile_buttons |
558 | -}; | |
559 | - | |
560 | -static struct bin_attribute pyra_profile1_buttons_attr = { | |
554 | + }, | |
555 | + { | |
561 | 556 | .attr = { .name = "profile1_buttons", .mode = 0440 }, |
562 | 557 | .size = sizeof(struct pyra_profile_buttons), |
563 | 558 | .read = pyra_sysfs_read_profile1_buttons |
564 | -}; | |
565 | - | |
566 | -static struct bin_attribute pyra_profile2_buttons_attr = { | |
559 | + }, | |
560 | + { | |
567 | 561 | .attr = { .name = "profile2_buttons", .mode = 0440 }, |
568 | 562 | .size = sizeof(struct pyra_profile_buttons), |
569 | 563 | .read = pyra_sysfs_read_profile2_buttons |
570 | -}; | |
571 | - | |
572 | -static struct bin_attribute pyra_profile3_buttons_attr = { | |
564 | + }, | |
565 | + { | |
573 | 566 | .attr = { .name = "profile3_buttons", .mode = 0440 }, |
574 | 567 | .size = sizeof(struct pyra_profile_buttons), |
575 | 568 | .read = pyra_sysfs_read_profile3_buttons |
576 | -}; | |
577 | - | |
578 | -static struct bin_attribute pyra_profile4_buttons_attr = { | |
569 | + }, | |
570 | + { | |
579 | 571 | .attr = { .name = "profile4_buttons", .mode = 0440 }, |
580 | 572 | .size = sizeof(struct pyra_profile_buttons), |
581 | 573 | .read = pyra_sysfs_read_profile4_buttons |
582 | -}; | |
583 | - | |
584 | -static struct bin_attribute pyra_profile5_buttons_attr = { | |
574 | + }, | |
575 | + { | |
585 | 576 | .attr = { .name = "profile5_buttons", .mode = 0440 }, |
586 | 577 | .size = sizeof(struct pyra_profile_buttons), |
587 | 578 | .read = pyra_sysfs_read_profile5_buttons |
588 | -}; | |
589 | - | |
590 | -static struct bin_attribute pyra_settings_attr = { | |
579 | + }, | |
580 | + { | |
591 | 581 | .attr = { .name = "settings", .mode = 0660 }, |
592 | 582 | .size = sizeof(struct pyra_settings), |
593 | 583 | .read = pyra_sysfs_read_settings, |
594 | 584 | .write = pyra_sysfs_write_settings |
585 | + }, | |
586 | + __ATTR_NULL | |
595 | 587 | }; |
596 | 588 | |
597 | -static int pyra_create_sysfs_attributes(struct usb_interface *intf) | |
598 | -{ | |
599 | - int retval; | |
600 | - | |
601 | - retval = sysfs_create_group(&intf->dev.kobj, &pyra_attribute_group); | |
602 | - if (retval) | |
603 | - goto exit_1; | |
604 | - | |
605 | - retval = sysfs_create_bin_file(&intf->dev.kobj, | |
606 | - &pyra_profile_settings_attr); | |
607 | - if (retval) | |
608 | - goto exit_2; | |
609 | - | |
610 | - retval = sysfs_create_bin_file(&intf->dev.kobj, | |
611 | - &pyra_profile1_settings_attr); | |
612 | - if (retval) | |
613 | - goto exit_3; | |
614 | - | |
615 | - retval = sysfs_create_bin_file(&intf->dev.kobj, | |
616 | - &pyra_profile2_settings_attr); | |
617 | - if (retval) | |
618 | - goto exit_4; | |
619 | - | |
620 | - retval = sysfs_create_bin_file(&intf->dev.kobj, | |
621 | - &pyra_profile3_settings_attr); | |
622 | - if (retval) | |
623 | - goto exit_5; | |
624 | - | |
625 | - retval = sysfs_create_bin_file(&intf->dev.kobj, | |
626 | - &pyra_profile4_settings_attr); | |
627 | - if (retval) | |
628 | - goto exit_6; | |
629 | - | |
630 | - retval = sysfs_create_bin_file(&intf->dev.kobj, | |
631 | - &pyra_profile5_settings_attr); | |
632 | - if (retval) | |
633 | - goto exit_7; | |
634 | - | |
635 | - retval = sysfs_create_bin_file(&intf->dev.kobj, | |
636 | - &pyra_profile_buttons_attr); | |
637 | - if (retval) | |
638 | - goto exit_8; | |
639 | - | |
640 | - retval = sysfs_create_bin_file(&intf->dev.kobj, | |
641 | - &pyra_profile1_buttons_attr); | |
642 | - if (retval) | |
643 | - goto exit_9; | |
644 | - | |
645 | - retval = sysfs_create_bin_file(&intf->dev.kobj, | |
646 | - &pyra_profile2_buttons_attr); | |
647 | - if (retval) | |
648 | - goto exit_10; | |
649 | - | |
650 | - retval = sysfs_create_bin_file(&intf->dev.kobj, | |
651 | - &pyra_profile3_buttons_attr); | |
652 | - if (retval) | |
653 | - goto exit_11; | |
654 | - | |
655 | - retval = sysfs_create_bin_file(&intf->dev.kobj, | |
656 | - &pyra_profile4_buttons_attr); | |
657 | - if (retval) | |
658 | - goto exit_12; | |
659 | - | |
660 | - retval = sysfs_create_bin_file(&intf->dev.kobj, | |
661 | - &pyra_profile5_buttons_attr); | |
662 | - if (retval) | |
663 | - goto exit_13; | |
664 | - | |
665 | - retval = sysfs_create_bin_file(&intf->dev.kobj, | |
666 | - &pyra_settings_attr); | |
667 | - if (retval) | |
668 | - goto exit_14; | |
669 | - | |
670 | - return 0; | |
671 | - | |
672 | -exit_14: | |
673 | - sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile5_buttons_attr); | |
674 | -exit_13: | |
675 | - sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile4_buttons_attr); | |
676 | -exit_12: | |
677 | - sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile3_buttons_attr); | |
678 | -exit_11: | |
679 | - sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile2_buttons_attr); | |
680 | -exit_10: | |
681 | - sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile1_buttons_attr); | |
682 | -exit_9: | |
683 | - sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile_buttons_attr); | |
684 | -exit_8: | |
685 | - sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile5_settings_attr); | |
686 | -exit_7: | |
687 | - sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile4_settings_attr); | |
688 | -exit_6: | |
689 | - sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile3_settings_attr); | |
690 | -exit_5: | |
691 | - sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile2_settings_attr); | |
692 | -exit_4: | |
693 | - sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile1_settings_attr); | |
694 | -exit_3: | |
695 | - sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile_settings_attr); | |
696 | -exit_2: | |
697 | - sysfs_remove_group(&intf->dev.kobj, &pyra_attribute_group); | |
698 | -exit_1: | |
699 | - return retval; | |
700 | -} | |
701 | - | |
702 | -static void pyra_remove_sysfs_attributes(struct usb_interface *intf) | |
703 | -{ | |
704 | - sysfs_remove_bin_file(&intf->dev.kobj, &pyra_settings_attr); | |
705 | - sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile5_buttons_attr); | |
706 | - sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile4_buttons_attr); | |
707 | - sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile3_buttons_attr); | |
708 | - sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile2_buttons_attr); | |
709 | - sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile1_buttons_attr); | |
710 | - sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile_buttons_attr); | |
711 | - sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile5_settings_attr); | |
712 | - sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile4_settings_attr); | |
713 | - sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile3_settings_attr); | |
714 | - sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile2_settings_attr); | |
715 | - sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile1_settings_attr); | |
716 | - sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile_settings_attr); | |
717 | - sysfs_remove_group(&intf->dev.kobj, &pyra_attribute_group); | |
718 | -} | |
719 | - | |
720 | 589 | static int pyra_init_pyra_device_struct(struct usb_device *usb_dev, |
721 | 590 | struct pyra_device *pyra) |
722 | 591 | { |
723 | 592 | |
... | ... | @@ -780,19 +649,13 @@ |
780 | 649 | goto exit_free; |
781 | 650 | } |
782 | 651 | |
783 | - retval = roccat_connect(hdev); | |
652 | + retval = roccat_connect(pyra_class, hdev); | |
784 | 653 | if (retval < 0) { |
785 | 654 | hid_err(hdev, "couldn't init char dev\n"); |
786 | 655 | } else { |
787 | 656 | pyra->chrdev_minor = retval; |
788 | 657 | pyra->roccat_claimed = 1; |
789 | 658 | } |
790 | - | |
791 | - retval = pyra_create_sysfs_attributes(intf); | |
792 | - if (retval) { | |
793 | - hid_err(hdev, "cannot create sysfs files\n"); | |
794 | - goto exit_free; | |
795 | - } | |
796 | 659 | } else { |
797 | 660 | hid_set_drvdata(hdev, NULL); |
798 | 661 | } |
... | ... | @@ -810,7 +673,6 @@ |
810 | 673 | |
811 | 674 | if (intf->cur_altsetting->desc.bInterfaceProtocol |
812 | 675 | == USB_INTERFACE_PROTOCOL_MOUSE) { |
813 | - pyra_remove_sysfs_attributes(intf); | |
814 | 676 | pyra = hid_get_drvdata(hdev); |
815 | 677 | if (pyra->roccat_claimed) |
816 | 678 | roccat_disconnect(pyra->chrdev_minor); |
817 | 679 | |
... | ... | @@ -950,11 +812,24 @@ |
950 | 812 | |
951 | 813 | static int __init pyra_init(void) |
952 | 814 | { |
953 | - return hid_register_driver(&pyra_driver); | |
815 | + int retval; | |
816 | + | |
817 | + /* class name has to be same as driver name */ | |
818 | + pyra_class = class_create(THIS_MODULE, "pyra"); | |
819 | + if (IS_ERR(pyra_class)) | |
820 | + return PTR_ERR(pyra_class); | |
821 | + pyra_class->dev_attrs = pyra_attributes; | |
822 | + pyra_class->dev_bin_attrs = pyra_bin_attributes; | |
823 | + | |
824 | + retval = hid_register_driver(&pyra_driver); | |
825 | + if (retval) | |
826 | + class_destroy(pyra_class); | |
827 | + return retval; | |
954 | 828 | } |
955 | 829 | |
956 | 830 | static void __exit pyra_exit(void) |
957 | 831 | { |
832 | + class_destroy(pyra_class); | |
958 | 833 | hid_unregister_driver(&pyra_driver); |
959 | 834 | } |
960 | 835 |
drivers/hid/hid-roccat.c
... | ... | @@ -67,7 +67,6 @@ |
67 | 67 | }; |
68 | 68 | |
69 | 69 | static int roccat_major; |
70 | -static struct class *roccat_class; | |
71 | 70 | static struct cdev roccat_cdev; |
72 | 71 | |
73 | 72 | static struct roccat_device *devices[ROCCAT_MAX_DEVICES]; |
74 | 73 | |
... | ... | @@ -289,12 +288,14 @@ |
289 | 288 | |
290 | 289 | /* |
291 | 290 | * roccat_connect() - create a char device for special event output |
291 | + * @class: the class thats used to create the device. Meant to hold device | |
292 | + * specific sysfs attributes. | |
292 | 293 | * @hid: the hid device the char device should be connected to. |
293 | 294 | * |
294 | 295 | * Return value is minor device number in Range [0, ROCCAT_MAX_DEVICES] on |
295 | 296 | * success, a negative error code on failure. |
296 | 297 | */ |
297 | -int roccat_connect(struct hid_device *hid) | |
298 | +int roccat_connect(struct class *klass, struct hid_device *hid) | |
298 | 299 | { |
299 | 300 | unsigned int minor; |
300 | 301 | struct roccat_device *device; |
... | ... | @@ -320,7 +321,7 @@ |
320 | 321 | return -EINVAL; |
321 | 322 | } |
322 | 323 | |
323 | - device->dev = device_create(roccat_class, &hid->dev, | |
324 | + device->dev = device_create(klass, &hid->dev, | |
324 | 325 | MKDEV(roccat_major, minor), NULL, |
325 | 326 | "%s%s%d", "roccat", hid->driver->name, minor); |
326 | 327 | |
... | ... | @@ -361,7 +362,7 @@ |
361 | 362 | |
362 | 363 | device->exist = 0; /* TODO exist maybe not needed */ |
363 | 364 | |
364 | - device_destroy(roccat_class, MKDEV(roccat_major, minor)); | |
365 | + device_destroy(device->dev->class, MKDEV(roccat_major, minor)); | |
365 | 366 | |
366 | 367 | if (device->open) { |
367 | 368 | hid_hw_close(device->hid); |
... | ... | @@ -396,13 +397,6 @@ |
396 | 397 | return retval; |
397 | 398 | } |
398 | 399 | |
399 | - roccat_class = class_create(THIS_MODULE, "roccat"); | |
400 | - if (IS_ERR(roccat_class)) { | |
401 | - retval = PTR_ERR(roccat_class); | |
402 | - unregister_chrdev_region(dev_id, ROCCAT_MAX_DEVICES); | |
403 | - return retval; | |
404 | - } | |
405 | - | |
406 | 400 | cdev_init(&roccat_cdev, &roccat_ops); |
407 | 401 | cdev_add(&roccat_cdev, dev_id, ROCCAT_MAX_DEVICES); |
408 | 402 | |
... | ... | @@ -414,7 +408,6 @@ |
414 | 408 | dev_t dev_id = MKDEV(roccat_major, 0); |
415 | 409 | |
416 | 410 | cdev_del(&roccat_cdev); |
417 | - class_destroy(roccat_class); | |
418 | 411 | unregister_chrdev_region(dev_id, ROCCAT_MAX_DEVICES); |
419 | 412 | } |
420 | 413 |
drivers/hid/hid-roccat.h
... | ... | @@ -16,11 +16,12 @@ |
16 | 16 | #include <linux/types.h> |
17 | 17 | |
18 | 18 | #if defined(CONFIG_HID_ROCCAT) || defined(CONFIG_HID_ROCCAT_MODULE) |
19 | -int roccat_connect(struct hid_device *hid); | |
19 | +int roccat_connect(struct class *klass, struct hid_device *hid); | |
20 | 20 | void roccat_disconnect(int minor); |
21 | 21 | int roccat_report_event(int minor, u8 const *data, int len); |
22 | 22 | #else |
23 | -static inline int roccat_connect(struct hid_device *hid) { return -1; } | |
23 | +static inline int roccat_connect(struct class *klass, | |
24 | + struct hid_device *hid) { return -1; } | |
24 | 25 | static inline void roccat_disconnect(int minor) {} |
25 | 26 | static inline int roccat_report_event(int minor, u8 const *data, int len) |
26 | 27 | { |