aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hid
diff options
context:
space:
mode:
authorStefan Achatz <erazor_de@users.sourceforge.net>2010-11-26 14:57:33 -0500
committerJiri Kosina <jkosina@suse.cz>2011-01-07 19:11:00 -0500
commit5012aada506cb8b570e46579077c0ec5b82ebd5d (patch)
treecf2d49567af63b16f7cdbef80ae5662938bd539c /drivers/hid
parentc97415a72521071c235e0879f9a600014afd87b1 (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')
-rw-r--r--drivers/hid/hid-roccat-kone.c298
-rw-r--r--drivers/hid/hid-roccat-pyra.c273
-rw-r--r--drivers/hid/hid-roccat.c17
-rw-r--r--drivers/hid/hid-roccat.h5
4 files changed, 209 insertions, 384 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 */
39static struct class *kone_class;
40
38static void kone_set_settings_checksum(struct kone_settings *settings) 41static 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)
261static ssize_t kone_sysfs_read_settings(struct file *fp, struct kobject *kobj, 264static 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,
285static ssize_t kone_sysfs_write_settings(struct file *fp, struct kobject *kobj, 289static 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,
321static ssize_t kone_sysfs_read_profilex(struct kobject *kobj, 326static 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,
371static ssize_t kone_sysfs_write_profilex(struct kobject *kobj, 377static 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,
432static ssize_t kone_sysfs_show_actual_profile(struct device *dev, 439static 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
439static ssize_t kone_sysfs_show_actual_dpi(struct device *dev, 447static 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,
447static ssize_t kone_sysfs_show_weight(struct device *dev, 456static 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,
464static ssize_t kone_sysfs_show_firmware_version(struct device *dev, 477static 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
471static ssize_t kone_sysfs_show_tcu(struct device *dev, 485static 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)
503static ssize_t kone_sysfs_set_tcu(struct device *dev, 518static 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:
578static ssize_t kone_sysfs_show_startup_profile(struct device *dev, 597static 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
585static ssize_t kone_sysfs_set_startup_profile(struct device *dev, 605static 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/* 643static 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.
624static DEVICE_ATTR(actual_dpi, 0440, kone_sysfs_show_actual_dpi, NULL); 648 */
625 649 __ATTR(actual_dpi, 0440, kone_sysfs_show_actual_dpi, NULL),
626static 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 */
634static 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 */
642static 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 */
649static 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 */
652static DEVICE_ATTR(startup_profile, 0660,
653 kone_sysfs_show_startup_profile,
654 kone_sysfs_set_startup_profile);
655
656static 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
666static struct attribute_group kone_attribute_group = {
667 .attrs = kone_attributes
668};
669
670static 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
677static 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
684static 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
691static 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
698static 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
705static struct bin_attribute kone_profile5_attr = { 684static 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
712static 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
746exit_7:
747 sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile4_attr);
748exit_6:
749 sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile3_attr);
750exit_5:
751 sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile2_attr);
752exit_4:
753 sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile1_attr);
754exit_3:
755 sysfs_remove_bin_file(&intf->dev.kobj, &kone_settings_attr);
756exit_2:
757 sysfs_remove_group(&intf->dev.kobj, &kone_attribute_group);
758exit_1:
759 return retval;
760}
761
762static 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
773static int kone_init_kone_device_struct(struct usb_device *usb_dev, 724static 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
856static void kone_remove_specials(struct hid_device *hdev) 800static 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
1005static int __init kone_init(void) 948static 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
1010static void __exit kone_exit(void) 965static 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
diff --git a/drivers/hid/hid-roccat-pyra.c b/drivers/hid/hid-roccat-pyra.c
index e7b4affe2664..7273e1e9093d 100644
--- a/drivers/hid/hid-roccat-pyra.c
+++ b/drivers/hid/hid-roccat-pyra.c
@@ -27,6 +27,9 @@
27#include "hid-roccat.h" 27#include "hid-roccat.h"
28#include "hid-roccat-pyra.h" 28#include "hid-roccat-pyra.h"
29 29
30/* pyra_class is used for creating sysfs attributes via roccat char device */
31static struct class *pyra_class;
32
30static void profile_activated(struct pyra_device *pyra, 33static void profile_activated(struct pyra_device *pyra,
31 unsigned int new_profile) 34 unsigned int new_profile)
32{ 35{
@@ -222,7 +225,8 @@ static ssize_t pyra_sysfs_read_profilex_settings(struct file *fp,
222 struct kobject *kobj, struct bin_attribute *attr, char *buf, 225 struct kobject *kobj, struct bin_attribute *attr, char *buf,
223 loff_t off, size_t count, int number) 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 struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev)); 230 struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev));
227 231
228 if (off >= sizeof(struct pyra_profile_settings)) 232 if (off >= sizeof(struct pyra_profile_settings))
@@ -283,7 +287,8 @@ static ssize_t pyra_sysfs_read_profilex_buttons(struct file *fp,
283 struct kobject *kobj, struct bin_attribute *attr, char *buf, 287 struct kobject *kobj, struct bin_attribute *attr, char *buf,
284 loff_t off, size_t count, int number) 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 struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev)); 292 struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev));
288 293
289 if (off >= sizeof(struct pyra_profile_buttons)) 294 if (off >= sizeof(struct pyra_profile_buttons))
@@ -344,7 +349,8 @@ static ssize_t pyra_sysfs_write_profile_settings(struct file *fp,
344 struct kobject *kobj, struct bin_attribute *attr, char *buf, 349 struct kobject *kobj, struct bin_attribute *attr, char *buf,
345 loff_t off, size_t count) 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 struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev)); 354 struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev));
349 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); 355 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
350 int retval = 0; 356 int retval = 0;
@@ -380,7 +386,8 @@ static ssize_t pyra_sysfs_write_profile_buttons(struct file *fp,
380 struct kobject *kobj, struct bin_attribute *attr, char *buf, 386 struct kobject *kobj, struct bin_attribute *attr, char *buf,
381 loff_t off, size_t count) 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 struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev)); 391 struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev));
385 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); 392 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
386 int retval = 0; 393 int retval = 0;
@@ -416,7 +423,8 @@ static ssize_t pyra_sysfs_read_settings(struct file *fp,
416 struct kobject *kobj, struct bin_attribute *attr, char *buf, 423 struct kobject *kobj, struct bin_attribute *attr, char *buf,
417 loff_t off, size_t count) 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 struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev)); 428 struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev));
421 429
422 if (off >= sizeof(struct pyra_settings)) 430 if (off >= sizeof(struct pyra_settings))
@@ -436,7 +444,8 @@ static ssize_t pyra_sysfs_write_settings(struct file *fp,
436 struct kobject *kobj, struct bin_attribute *attr, char *buf, 444 struct kobject *kobj, struct bin_attribute *attr, char *buf,
437 loff_t off, size_t count) 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 struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev)); 449 struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev));
441 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); 450 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
442 int retval = 0; 451 int retval = 0;
@@ -468,255 +477,115 @@ static ssize_t pyra_sysfs_write_settings(struct file *fp,
468static ssize_t pyra_sysfs_show_actual_cpi(struct device *dev, 477static ssize_t pyra_sysfs_show_actual_cpi(struct device *dev,
469 struct device_attribute *attr, char *buf) 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 return snprintf(buf, PAGE_SIZE, "%d\n", pyra->actual_cpi); 482 return snprintf(buf, PAGE_SIZE, "%d\n", pyra->actual_cpi);
473} 483}
474 484
475static ssize_t pyra_sysfs_show_actual_profile(struct device *dev, 485static ssize_t pyra_sysfs_show_actual_profile(struct device *dev,
476 struct device_attribute *attr, char *buf) 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 return snprintf(buf, PAGE_SIZE, "%d\n", pyra->actual_profile); 490 return snprintf(buf, PAGE_SIZE, "%d\n", pyra->actual_profile);
480} 491}
481 492
482static ssize_t pyra_sysfs_show_firmware_version(struct device *dev, 493static ssize_t pyra_sysfs_show_firmware_version(struct device *dev,
483 struct device_attribute *attr, char *buf) 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 return snprintf(buf, PAGE_SIZE, "%d\n", pyra->firmware_version); 498 return snprintf(buf, PAGE_SIZE, "%d\n", pyra->firmware_version);
487} 499}
488 500
489static ssize_t pyra_sysfs_show_startup_profile(struct device *dev, 501static ssize_t pyra_sysfs_show_startup_profile(struct device *dev,
490 struct device_attribute *attr, char *buf) 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 return snprintf(buf, PAGE_SIZE, "%d\n", pyra->settings.startup_profile); 506 return snprintf(buf, PAGE_SIZE, "%d\n", pyra->settings.startup_profile);
494} 507}
495 508
496static DEVICE_ATTR(actual_cpi, 0440, pyra_sysfs_show_actual_cpi, NULL); 509static struct device_attribute pyra_attributes[] = {
497 510 __ATTR(actual_cpi, 0440, pyra_sysfs_show_actual_cpi, NULL),
498static DEVICE_ATTR(actual_profile, 0440, pyra_sysfs_show_actual_profile, NULL); 511 __ATTR(actual_profile, 0440, pyra_sysfs_show_actual_profile, NULL),
499 512 __ATTR(firmware_version, 0440,
500static DEVICE_ATTR(firmware_version, 0440, 513 pyra_sysfs_show_firmware_version, NULL),
501 pyra_sysfs_show_firmware_version, NULL); 514 __ATTR(startup_profile, 0440,
502 515 pyra_sysfs_show_startup_profile, NULL),
503static DEVICE_ATTR(startup_profile, 0440, 516 __ATTR_NULL
504 pyra_sysfs_show_startup_profile, NULL);
505
506static 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
512};
513
514static struct attribute_group pyra_attribute_group = {
515 .attrs = pyra_attributes
516}; 517};
517 518
518static struct bin_attribute pyra_profile_settings_attr = { 519static struct bin_attribute pyra_bin_attributes[] = {
520 {
519 .attr = { .name = "profile_settings", .mode = 0220 }, 521 .attr = { .name = "profile_settings", .mode = 0220 },
520 .size = sizeof(struct pyra_profile_settings), 522 .size = sizeof(struct pyra_profile_settings),
521 .write = pyra_sysfs_write_profile_settings 523 .write = pyra_sysfs_write_profile_settings
522}; 524 },
523 525 {
524static struct bin_attribute pyra_profile1_settings_attr = {
525 .attr = { .name = "profile1_settings", .mode = 0440 }, 526 .attr = { .name = "profile1_settings", .mode = 0440 },
526 .size = sizeof(struct pyra_profile_settings), 527 .size = sizeof(struct pyra_profile_settings),
527 .read = pyra_sysfs_read_profile1_settings 528 .read = pyra_sysfs_read_profile1_settings
528}; 529 },
529 530 {
530static struct bin_attribute pyra_profile2_settings_attr = {
531 .attr = { .name = "profile2_settings", .mode = 0440 }, 531 .attr = { .name = "profile2_settings", .mode = 0440 },
532 .size = sizeof(struct pyra_profile_settings), 532 .size = sizeof(struct pyra_profile_settings),
533 .read = pyra_sysfs_read_profile2_settings 533 .read = pyra_sysfs_read_profile2_settings
534}; 534 },
535 535 {
536static struct bin_attribute pyra_profile3_settings_attr = {
537 .attr = { .name = "profile3_settings", .mode = 0440 }, 536 .attr = { .name = "profile3_settings", .mode = 0440 },
538 .size = sizeof(struct pyra_profile_settings), 537 .size = sizeof(struct pyra_profile_settings),
539 .read = pyra_sysfs_read_profile3_settings 538 .read = pyra_sysfs_read_profile3_settings
540}; 539 },
541 540 {
542static struct bin_attribute pyra_profile4_settings_attr = {
543 .attr = { .name = "profile4_settings", .mode = 0440 }, 541 .attr = { .name = "profile4_settings", .mode = 0440 },
544 .size = sizeof(struct pyra_profile_settings), 542 .size = sizeof(struct pyra_profile_settings),
545 .read = pyra_sysfs_read_profile4_settings 543 .read = pyra_sysfs_read_profile4_settings
546}; 544 },
547 545 {
548static struct bin_attribute pyra_profile5_settings_attr = {
549 .attr = { .name = "profile5_settings", .mode = 0440 }, 546 .attr = { .name = "profile5_settings", .mode = 0440 },
550 .size = sizeof(struct pyra_profile_settings), 547 .size = sizeof(struct pyra_profile_settings),
551 .read = pyra_sysfs_read_profile5_settings 548 .read = pyra_sysfs_read_profile5_settings
552}; 549 },
553 550 {
554static struct bin_attribute pyra_profile_buttons_attr = {
555 .attr = { .name = "profile_buttons", .mode = 0220 }, 551 .attr = { .name = "profile_buttons", .mode = 0220 },
556 .size = sizeof(struct pyra_profile_buttons), 552 .size = sizeof(struct pyra_profile_buttons),
557 .write = pyra_sysfs_write_profile_buttons 553 .write = pyra_sysfs_write_profile_buttons
558}; 554 },
559 555 {
560static struct bin_attribute pyra_profile1_buttons_attr = {
561 .attr = { .name = "profile1_buttons", .mode = 0440 }, 556 .attr = { .name = "profile1_buttons", .mode = 0440 },
562 .size = sizeof(struct pyra_profile_buttons), 557 .size = sizeof(struct pyra_profile_buttons),
563 .read = pyra_sysfs_read_profile1_buttons 558 .read = pyra_sysfs_read_profile1_buttons
564}; 559 },
565 560 {
566static struct bin_attribute pyra_profile2_buttons_attr = {
567 .attr = { .name = "profile2_buttons", .mode = 0440 }, 561 .attr = { .name = "profile2_buttons", .mode = 0440 },
568 .size = sizeof(struct pyra_profile_buttons), 562 .size = sizeof(struct pyra_profile_buttons),
569 .read = pyra_sysfs_read_profile2_buttons 563 .read = pyra_sysfs_read_profile2_buttons
570}; 564 },
571 565 {
572static struct bin_attribute pyra_profile3_buttons_attr = {
573 .attr = { .name = "profile3_buttons", .mode = 0440 }, 566 .attr = { .name = "profile3_buttons", .mode = 0440 },
574 .size = sizeof(struct pyra_profile_buttons), 567 .size = sizeof(struct pyra_profile_buttons),
575 .read = pyra_sysfs_read_profile3_buttons 568 .read = pyra_sysfs_read_profile3_buttons
576}; 569 },
577 570 {
578static struct bin_attribute pyra_profile4_buttons_attr = {
579 .attr = { .name = "profile4_buttons", .mode = 0440 }, 571 .attr = { .name = "profile4_buttons", .mode = 0440 },
580 .size = sizeof(struct pyra_profile_buttons), 572 .size = sizeof(struct pyra_profile_buttons),
581 .read = pyra_sysfs_read_profile4_buttons 573 .read = pyra_sysfs_read_profile4_buttons
582}; 574 },
583 575 {
584static struct bin_attribute pyra_profile5_buttons_attr = {
585 .attr = { .name = "profile5_buttons", .mode = 0440 }, 576 .attr = { .name = "profile5_buttons", .mode = 0440 },
586 .size = sizeof(struct pyra_profile_buttons), 577 .size = sizeof(struct pyra_profile_buttons),
587 .read = pyra_sysfs_read_profile5_buttons 578 .read = pyra_sysfs_read_profile5_buttons
588}; 579 },
589 580 {
590static struct bin_attribute pyra_settings_attr = {
591 .attr = { .name = "settings", .mode = 0660 }, 581 .attr = { .name = "settings", .mode = 0660 },
592 .size = sizeof(struct pyra_settings), 582 .size = sizeof(struct pyra_settings),
593 .read = pyra_sysfs_read_settings, 583 .read = pyra_sysfs_read_settings,
594 .write = pyra_sysfs_write_settings 584 .write = pyra_sysfs_write_settings
585 },
586 __ATTR_NULL
595}; 587};
596 588
597static 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
672exit_14:
673 sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile5_buttons_attr);
674exit_13:
675 sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile4_buttons_attr);
676exit_12:
677 sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile3_buttons_attr);
678exit_11:
679 sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile2_buttons_attr);
680exit_10:
681 sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile1_buttons_attr);
682exit_9:
683 sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile_buttons_attr);
684exit_8:
685 sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile5_settings_attr);
686exit_7:
687 sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile4_settings_attr);
688exit_6:
689 sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile3_settings_attr);
690exit_5:
691 sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile2_settings_attr);
692exit_4:
693 sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile1_settings_attr);
694exit_3:
695 sysfs_remove_bin_file(&intf->dev.kobj, &pyra_profile_settings_attr);
696exit_2:
697 sysfs_remove_group(&intf->dev.kobj, &pyra_attribute_group);
698exit_1:
699 return retval;
700}
701
702static 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
720static int pyra_init_pyra_device_struct(struct usb_device *usb_dev, 589static int pyra_init_pyra_device_struct(struct usb_device *usb_dev,
721 struct pyra_device *pyra) 590 struct pyra_device *pyra)
722{ 591{
@@ -780,19 +649,13 @@ static int pyra_init_specials(struct hid_device *hdev)
780 goto exit_free; 649 goto exit_free;
781 } 650 }
782 651
783 retval = roccat_connect(hdev); 652 retval = roccat_connect(pyra_class, hdev);
784 if (retval < 0) { 653 if (retval < 0) {
785 hid_err(hdev, "couldn't init char dev\n"); 654 hid_err(hdev, "couldn't init char dev\n");
786 } else { 655 } else {
787 pyra->chrdev_minor = retval; 656 pyra->chrdev_minor = retval;
788 pyra->roccat_claimed = 1; 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 } else { 659 } else {
797 hid_set_drvdata(hdev, NULL); 660 hid_set_drvdata(hdev, NULL);
798 } 661 }
@@ -810,7 +673,6 @@ static void pyra_remove_specials(struct hid_device *hdev)
810 673
811 if (intf->cur_altsetting->desc.bInterfaceProtocol 674 if (intf->cur_altsetting->desc.bInterfaceProtocol
812 == USB_INTERFACE_PROTOCOL_MOUSE) { 675 == USB_INTERFACE_PROTOCOL_MOUSE) {
813 pyra_remove_sysfs_attributes(intf);
814 pyra = hid_get_drvdata(hdev); 676 pyra = hid_get_drvdata(hdev);
815 if (pyra->roccat_claimed) 677 if (pyra->roccat_claimed)
816 roccat_disconnect(pyra->chrdev_minor); 678 roccat_disconnect(pyra->chrdev_minor);
@@ -950,11 +812,24 @@ static struct hid_driver pyra_driver = {
950 812
951static int __init pyra_init(void) 813static 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
956static void __exit pyra_exit(void) 830static void __exit pyra_exit(void)
957{ 831{
832 class_destroy(pyra_class);
958 hid_unregister_driver(&pyra_driver); 833 hid_unregister_driver(&pyra_driver);
959} 834}
960 835
diff --git a/drivers/hid/hid-roccat.c b/drivers/hid/hid-roccat.c
index 4bc7a93dc1f5..a14c579ea781 100644
--- a/drivers/hid/hid-roccat.c
+++ b/drivers/hid/hid-roccat.c
@@ -67,7 +67,6 @@ struct roccat_reader {
67}; 67};
68 68
69static int roccat_major; 69static int roccat_major;
70static struct class *roccat_class;
71static struct cdev roccat_cdev; 70static struct cdev roccat_cdev;
72 71
73static struct roccat_device *devices[ROCCAT_MAX_DEVICES]; 72static struct roccat_device *devices[ROCCAT_MAX_DEVICES];
@@ -289,12 +288,14 @@ EXPORT_SYMBOL_GPL(roccat_report_event);
289 288
290/* 289/*
291 * roccat_connect() - create a char device for special event output 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 * @hid: the hid device the char device should be connected to. 293 * @hid: the hid device the char device should be connected to.
293 * 294 *
294 * Return value is minor device number in Range [0, ROCCAT_MAX_DEVICES] on 295 * Return value is minor device number in Range [0, ROCCAT_MAX_DEVICES] on
295 * success, a negative error code on failure. 296 * success, a negative error code on failure.
296 */ 297 */
297int roccat_connect(struct hid_device *hid) 298int roccat_connect(struct class *klass, struct hid_device *hid)
298{ 299{
299 unsigned int minor; 300 unsigned int minor;
300 struct roccat_device *device; 301 struct roccat_device *device;
@@ -320,7 +321,7 @@ int roccat_connect(struct hid_device *hid)
320 return -EINVAL; 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 MKDEV(roccat_major, minor), NULL, 325 MKDEV(roccat_major, minor), NULL,
325 "%s%s%d", "roccat", hid->driver->name, minor); 326 "%s%s%d", "roccat", hid->driver->name, minor);
326 327
@@ -361,7 +362,7 @@ void roccat_disconnect(int minor)
361 362
362 device->exist = 0; /* TODO exist maybe not needed */ 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 if (device->open) { 367 if (device->open) {
367 hid_hw_close(device->hid); 368 hid_hw_close(device->hid);
@@ -396,13 +397,6 @@ static int __init roccat_init(void)
396 return retval; 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 cdev_init(&roccat_cdev, &roccat_ops); 400 cdev_init(&roccat_cdev, &roccat_ops);
407 cdev_add(&roccat_cdev, dev_id, ROCCAT_MAX_DEVICES); 401 cdev_add(&roccat_cdev, dev_id, ROCCAT_MAX_DEVICES);
408 402
@@ -414,7 +408,6 @@ static void __exit roccat_exit(void)
414 dev_t dev_id = MKDEV(roccat_major, 0); 408 dev_t dev_id = MKDEV(roccat_major, 0);
415 409
416 cdev_del(&roccat_cdev); 410 cdev_del(&roccat_cdev);
417 class_destroy(roccat_class);
418 unregister_chrdev_region(dev_id, ROCCAT_MAX_DEVICES); 411 unregister_chrdev_region(dev_id, ROCCAT_MAX_DEVICES);
419} 412}
420 413
diff --git a/drivers/hid/hid-roccat.h b/drivers/hid/hid-roccat.h
index 09e864e9f79d..5784281d613f 100644
--- a/drivers/hid/hid-roccat.h
+++ b/drivers/hid/hid-roccat.h
@@ -16,11 +16,12 @@
16#include <linux/types.h> 16#include <linux/types.h>
17 17
18#if defined(CONFIG_HID_ROCCAT) || defined(CONFIG_HID_ROCCAT_MODULE) 18#if defined(CONFIG_HID_ROCCAT) || defined(CONFIG_HID_ROCCAT_MODULE)
19int roccat_connect(struct hid_device *hid); 19int roccat_connect(struct class *klass, struct hid_device *hid);
20void roccat_disconnect(int minor); 20void roccat_disconnect(int minor);
21int roccat_report_event(int minor, u8 const *data, int len); 21int roccat_report_event(int minor, u8 const *data, int len);
22#else 22#else
23static inline int roccat_connect(struct hid_device *hid) { return -1; } 23static inline int roccat_connect(struct class *klass,
24 struct hid_device *hid) { return -1; }
24static inline void roccat_disconnect(int minor) {} 25static inline void roccat_disconnect(int minor) {}
25static inline int roccat_report_event(int minor, u8 const *data, int len) 26static inline int roccat_report_event(int minor, u8 const *data, int len)
26{ 27{