Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

HID: roccat: generalize some common code

Reduced some duplicate code by moving it to hid-roccat-common.

Signed-off-by: Stefan Achatz <erazor_de@users.sourceforge.net>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>

authored by

Stefan Achatz and committed by
Jiri Kosina
71304f5a 14fc4290

+167 -333
+53
drivers/hid/hid-roccat-common.c
··· 122 122 } 123 123 EXPORT_SYMBOL_GPL(roccat_common2_send_with_status); 124 124 125 + int roccat_common2_device_init_struct(struct usb_device *usb_dev, 126 + struct roccat_common2_device *dev) 127 + { 128 + mutex_init(&dev->lock); 129 + return 0; 130 + } 131 + EXPORT_SYMBOL_GPL(roccat_common2_device_init_struct); 132 + 133 + ssize_t roccat_common2_sysfs_read(struct file *fp, struct kobject *kobj, 134 + char *buf, loff_t off, size_t count, 135 + size_t real_size, uint command) 136 + { 137 + struct device *dev = 138 + container_of(kobj, struct device, kobj)->parent->parent; 139 + struct roccat_common2_device *roccat_dev = hid_get_drvdata(dev_get_drvdata(dev)); 140 + struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); 141 + int retval; 142 + 143 + if (off >= real_size) 144 + return 0; 145 + 146 + if (off != 0 || count != real_size) 147 + return -EINVAL; 148 + 149 + mutex_lock(&roccat_dev->lock); 150 + retval = roccat_common2_receive(usb_dev, command, buf, real_size); 151 + mutex_unlock(&roccat_dev->lock); 152 + 153 + return retval ? retval : real_size; 154 + } 155 + EXPORT_SYMBOL_GPL(roccat_common2_sysfs_read); 156 + 157 + ssize_t roccat_common2_sysfs_write(struct file *fp, struct kobject *kobj, 158 + void const *buf, loff_t off, size_t count, 159 + size_t real_size, uint command) 160 + { 161 + struct device *dev = 162 + container_of(kobj, struct device, kobj)->parent->parent; 163 + struct roccat_common2_device *roccat_dev = hid_get_drvdata(dev_get_drvdata(dev)); 164 + struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); 165 + int retval; 166 + 167 + if (off != 0 || count != real_size) 168 + return -EINVAL; 169 + 170 + mutex_lock(&roccat_dev->lock); 171 + retval = roccat_common2_send_with_status(usb_dev, command, buf, real_size); 172 + mutex_unlock(&roccat_dev->lock); 173 + 174 + return retval ? retval : real_size; 175 + } 176 + EXPORT_SYMBOL_GPL(roccat_common2_sysfs_write); 177 + 125 178 MODULE_AUTHOR("Stefan Achatz"); 126 179 MODULE_DESCRIPTION("USB Roccat common driver"); 127 180 MODULE_LICENSE("GPL v2");
+62
drivers/hid/hid-roccat-common.h
··· 32 32 int roccat_common2_send_with_status(struct usb_device *usb_dev, 33 33 uint command, void const *buf, uint size); 34 34 35 + struct roccat_common2_device { 36 + int roccat_claimed; 37 + int chrdev_minor; 38 + struct mutex lock; 39 + }; 40 + 41 + int roccat_common2_device_init_struct(struct usb_device *usb_dev, 42 + struct roccat_common2_device *dev); 43 + ssize_t roccat_common2_sysfs_read(struct file *fp, struct kobject *kobj, 44 + char *buf, loff_t off, size_t count, 45 + size_t real_size, uint command); 46 + ssize_t roccat_common2_sysfs_write(struct file *fp, struct kobject *kobj, 47 + void const *buf, loff_t off, size_t count, 48 + size_t real_size, uint command); 49 + 50 + #define ROCCAT_COMMON2_SYSFS_W(thingy, COMMAND, SIZE) \ 51 + static ssize_t roccat_common2_sysfs_write_ ## thingy(struct file *fp, \ 52 + struct kobject *kobj, struct bin_attribute *attr, char *buf, \ 53 + loff_t off, size_t count) \ 54 + { \ 55 + return roccat_common2_sysfs_write(fp, kobj, buf, off, count, \ 56 + SIZE, COMMAND); \ 57 + } 58 + 59 + #define ROCCAT_COMMON2_SYSFS_R(thingy, COMMAND, SIZE) \ 60 + static ssize_t roccat_common2_sysfs_read_ ## thingy(struct file *fp, \ 61 + struct kobject *kobj, struct bin_attribute *attr, char *buf, \ 62 + loff_t off, size_t count) \ 63 + { \ 64 + return roccat_common2_sysfs_read(fp, kobj, buf, off, count, \ 65 + SIZE, COMMAND); \ 66 + } 67 + 68 + #define ROCCAT_COMMON2_SYSFS_RW(thingy, COMMAND, SIZE) \ 69 + ROCCAT_COMMON2_SYSFS_W(thingy, COMMAND, SIZE) \ 70 + ROCCAT_COMMON2_SYSFS_R(thingy, COMMAND, SIZE) 71 + 72 + #define ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(thingy, COMMAND, SIZE) \ 73 + ROCCAT_COMMON2_SYSFS_RW(thingy, COMMAND, SIZE); \ 74 + static struct bin_attribute bin_attr_ ## thingy = { \ 75 + .attr = { .name = #thingy, .mode = 0660 }, \ 76 + .size = SIZE, \ 77 + .read = roccat_common2_sysfs_read_ ## thingy, \ 78 + .write = roccat_common2_sysfs_write_ ## thingy \ 79 + } 80 + 81 + #define ROCCAT_COMMON2_BIN_ATTRIBUTE_R(thingy, COMMAND, SIZE) \ 82 + ROCCAT_COMMON2_SYSFS_R(thingy, COMMAND, SIZE); \ 83 + static struct bin_attribute bin_attr_ ## thingy = { \ 84 + .attr = { .name = #thingy, .mode = 0440 }, \ 85 + .size = SIZE, \ 86 + .read = roccat_common2_sysfs_read_ ## thingy, \ 87 + } 88 + 89 + #define ROCCAT_COMMON2_BIN_ATTRIBUTE_W(thingy, COMMAND, SIZE) \ 90 + ROCCAT_COMMON2_SYSFS_W(thingy, COMMAND, SIZE); \ 91 + static struct bin_attribute bin_attr_ ## thingy = { \ 92 + .attr = { .name = #thingy, .mode = 0220 }, \ 93 + .size = SIZE, \ 94 + .write = roccat_common2_sysfs_write_ ## thingy \ 95 + } 96 + 35 97 #endif
+37 -123
drivers/hid/hid-roccat-konepure.c
··· 15 15 * Roccat KonePure is a smaller version of KoneXTD with less buttons and lights. 16 16 */ 17 17 18 + #include <linux/types.h> 18 19 #include <linux/device.h> 19 20 #include <linux/input.h> 20 21 #include <linux/hid.h> ··· 24 23 #include <linux/hid-roccat.h> 25 24 #include "hid-ids.h" 26 25 #include "hid-roccat-common.h" 27 - #include "hid-roccat-konepure.h" 26 + 27 + enum { 28 + KONEPURE_MOUSE_REPORT_NUMBER_BUTTON = 3, 29 + }; 30 + 31 + struct konepure_mouse_report_button { 32 + uint8_t report_number; /* always KONEPURE_MOUSE_REPORT_NUMBER_BUTTON */ 33 + uint8_t zero; 34 + uint8_t type; 35 + uint8_t data1; 36 + uint8_t data2; 37 + uint8_t zero2; 38 + uint8_t unknown[2]; 39 + } __packed; 28 40 29 41 static struct class *konepure_class; 30 42 31 - static ssize_t konepure_sysfs_read(struct file *fp, struct kobject *kobj, 32 - char *buf, loff_t off, size_t count, 33 - size_t real_size, uint command) 34 - { 35 - struct device *dev = 36 - container_of(kobj, struct device, kobj)->parent->parent; 37 - struct konepure_device *konepure = hid_get_drvdata(dev_get_drvdata(dev)); 38 - struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); 39 - int retval; 43 + ROCCAT_COMMON2_BIN_ATTRIBUTE_W(control, 0x04, 0x03); 44 + ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(actual_profile, 0x05, 0x03); 45 + ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(profile_settings, 0x06, 0x1f); 46 + ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(profile_buttons, 0x07, 0x3b); 47 + ROCCAT_COMMON2_BIN_ATTRIBUTE_W(macro, 0x08, 0x0822); 48 + ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(info, 0x09, 0x06); 49 + ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(tcu, 0x0c, 0x04); 50 + ROCCAT_COMMON2_BIN_ATTRIBUTE_R(tcu_image, 0x0c, 0x0404); 51 + ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(sensor, 0x0f, 0x06); 52 + ROCCAT_COMMON2_BIN_ATTRIBUTE_W(talk, 0x10, 0x10); 40 53 41 - if (off >= real_size) 42 - return 0; 43 - 44 - if (off != 0 || count != real_size) 45 - return -EINVAL; 46 - 47 - mutex_lock(&konepure->konepure_lock); 48 - retval = roccat_common2_receive(usb_dev, command, buf, real_size); 49 - mutex_unlock(&konepure->konepure_lock); 50 - 51 - return retval ? retval : real_size; 52 - } 53 - 54 - static ssize_t konepure_sysfs_write(struct file *fp, struct kobject *kobj, 55 - void const *buf, loff_t off, size_t count, 56 - size_t real_size, uint command) 57 - { 58 - struct device *dev = 59 - container_of(kobj, struct device, kobj)->parent->parent; 60 - struct konepure_device *konepure = hid_get_drvdata(dev_get_drvdata(dev)); 61 - struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); 62 - int retval; 63 - 64 - if (off != 0 || count != real_size) 65 - return -EINVAL; 66 - 67 - mutex_lock(&konepure->konepure_lock); 68 - retval = roccat_common2_send_with_status(usb_dev, command, 69 - (void *)buf, real_size); 70 - mutex_unlock(&konepure->konepure_lock); 71 - 72 - return retval ? retval : real_size; 73 - } 74 - 75 - #define KONEPURE_SYSFS_W(thingy, THINGY) \ 76 - static ssize_t konepure_sysfs_write_ ## thingy(struct file *fp, \ 77 - struct kobject *kobj, struct bin_attribute *attr, char *buf, \ 78 - loff_t off, size_t count) \ 79 - { \ 80 - return konepure_sysfs_write(fp, kobj, buf, off, count, \ 81 - KONEPURE_SIZE_ ## THINGY, KONEPURE_COMMAND_ ## THINGY); \ 82 - } 83 - 84 - #define KONEPURE_SYSFS_R(thingy, THINGY) \ 85 - static ssize_t konepure_sysfs_read_ ## thingy(struct file *fp, \ 86 - struct kobject *kobj, struct bin_attribute *attr, char *buf, \ 87 - loff_t off, size_t count) \ 88 - { \ 89 - return konepure_sysfs_read(fp, kobj, buf, off, count, \ 90 - KONEPURE_SIZE_ ## THINGY, KONEPURE_COMMAND_ ## THINGY); \ 91 - } 92 - 93 - #define KONEPURE_SYSFS_RW(thingy, THINGY) \ 94 - KONEPURE_SYSFS_W(thingy, THINGY) \ 95 - KONEPURE_SYSFS_R(thingy, THINGY) 96 - 97 - #define KONEPURE_BIN_ATTRIBUTE_RW(thingy, THINGY) \ 98 - KONEPURE_SYSFS_RW(thingy, THINGY); \ 99 - static struct bin_attribute bin_attr_##thingy = { \ 100 - .attr = { .name = #thingy, .mode = 0660 }, \ 101 - .size = KONEPURE_SIZE_ ## THINGY, \ 102 - .read = konepure_sysfs_read_ ## thingy, \ 103 - .write = konepure_sysfs_write_ ## thingy \ 104 - } 105 - 106 - #define KONEPURE_BIN_ATTRIBUTE_R(thingy, THINGY) \ 107 - KONEPURE_SYSFS_R(thingy, THINGY); \ 108 - static struct bin_attribute bin_attr_##thingy = { \ 109 - .attr = { .name = #thingy, .mode = 0440 }, \ 110 - .size = KONEPURE_SIZE_ ## THINGY, \ 111 - .read = konepure_sysfs_read_ ## thingy, \ 112 - } 113 - 114 - #define KONEPURE_BIN_ATTRIBUTE_W(thingy, THINGY) \ 115 - KONEPURE_SYSFS_W(thingy, THINGY); \ 116 - static struct bin_attribute bin_attr_##thingy = { \ 117 - .attr = { .name = #thingy, .mode = 0220 }, \ 118 - .size = KONEPURE_SIZE_ ## THINGY, \ 119 - .write = konepure_sysfs_write_ ## thingy \ 120 - } 121 - 122 - KONEPURE_BIN_ATTRIBUTE_RW(actual_profile, ACTUAL_PROFILE); 123 - KONEPURE_BIN_ATTRIBUTE_RW(info, INFO); 124 - KONEPURE_BIN_ATTRIBUTE_RW(sensor, SENSOR); 125 - KONEPURE_BIN_ATTRIBUTE_RW(tcu, TCU); 126 - KONEPURE_BIN_ATTRIBUTE_RW(profile_settings, PROFILE_SETTINGS); 127 - KONEPURE_BIN_ATTRIBUTE_RW(profile_buttons, PROFILE_BUTTONS); 128 - KONEPURE_BIN_ATTRIBUTE_W(control, CONTROL); 129 - KONEPURE_BIN_ATTRIBUTE_W(talk, TALK); 130 - KONEPURE_BIN_ATTRIBUTE_W(macro, MACRO); 131 - KONEPURE_BIN_ATTRIBUTE_R(tcu_image, TCU_IMAGE); 132 - 133 - static struct bin_attribute *konepure_bin_attributes[] = { 54 + static struct bin_attribute *konepure_bin_attrs[] = { 134 55 &bin_attr_actual_profile, 135 - &bin_attr_info, 136 - &bin_attr_sensor, 137 - &bin_attr_tcu, 138 - &bin_attr_profile_settings, 139 - &bin_attr_profile_buttons, 140 56 &bin_attr_control, 57 + &bin_attr_info, 141 58 &bin_attr_talk, 142 59 &bin_attr_macro, 60 + &bin_attr_sensor, 61 + &bin_attr_tcu, 143 62 &bin_attr_tcu_image, 63 + &bin_attr_profile_settings, 64 + &bin_attr_profile_buttons, 144 65 NULL, 145 66 }; 146 67 147 68 static const struct attribute_group konepure_group = { 148 - .bin_attrs = konepure_bin_attributes, 69 + .bin_attrs = konepure_bin_attrs, 149 70 }; 150 71 151 72 static const struct attribute_group *konepure_groups[] = { ··· 75 152 NULL, 76 153 }; 77 154 78 - 79 - static int konepure_init_konepure_device_struct(struct usb_device *usb_dev, 80 - struct konepure_device *konepure) 81 - { 82 - mutex_init(&konepure->konepure_lock); 83 - 84 - return 0; 85 - } 86 - 87 155 static int konepure_init_specials(struct hid_device *hdev) 88 156 { 89 157 struct usb_interface *intf = to_usb_interface(hdev->dev.parent); 90 158 struct usb_device *usb_dev = interface_to_usbdev(intf); 91 - struct konepure_device *konepure; 159 + struct roccat_common2_device *konepure; 92 160 int retval; 93 161 94 162 if (intf->cur_altsetting->desc.bInterfaceProtocol ··· 95 181 } 96 182 hid_set_drvdata(hdev, konepure); 97 183 98 - retval = konepure_init_konepure_device_struct(usb_dev, konepure); 184 + retval = roccat_common2_device_init_struct(usb_dev, konepure); 99 185 if (retval) { 100 - hid_err(hdev, "couldn't init struct konepure_device\n"); 186 + hid_err(hdev, "couldn't init KonePure device\n"); 101 187 goto exit_free; 102 188 } 103 189 ··· 119 205 static void konepure_remove_specials(struct hid_device *hdev) 120 206 { 121 207 struct usb_interface *intf = to_usb_interface(hdev->dev.parent); 122 - struct konepure_device *konepure; 208 + struct roccat_common2_device *konepure; 123 209 124 210 if (intf->cur_altsetting->desc.bInterfaceProtocol 125 211 != USB_INTERFACE_PROTOCOL_MOUSE) ··· 172 258 struct hid_report *report, u8 *data, int size) 173 259 { 174 260 struct usb_interface *intf = to_usb_interface(hdev->dev.parent); 175 - struct konepure_device *konepure = hid_get_drvdata(hdev); 261 + struct roccat_common2_device *konepure = hid_get_drvdata(hdev); 176 262 177 263 if (intf->cur_altsetting->desc.bInterfaceProtocol 178 264 != USB_INTERFACE_PROTOCOL_MOUSE)
-72
drivers/hid/hid-roccat-konepure.h
··· 1 - #ifndef __HID_ROCCAT_KONEPURE_H 2 - #define __HID_ROCCAT_KONEPURE_H 3 - 4 - /* 5 - * Copyright (c) 2012 Stefan Achatz <erazor_de@users.sourceforge.net> 6 - */ 7 - 8 - /* 9 - * This program is free software; you can redistribute it and/or modify it 10 - * under the terms of the GNU General Public License as published by the Free 11 - * Software Foundation; either version 2 of the License, or (at your option) 12 - * any later version. 13 - */ 14 - 15 - #include <linux/types.h> 16 - 17 - enum { 18 - KONEPURE_SIZE_ACTUAL_PROFILE = 0x03, 19 - KONEPURE_SIZE_CONTROL = 0x03, 20 - KONEPURE_SIZE_FIRMWARE_WRITE = 0x0402, 21 - KONEPURE_SIZE_INFO = 0x06, 22 - KONEPURE_SIZE_MACRO = 0x0822, 23 - KONEPURE_SIZE_PROFILE_SETTINGS = 0x1f, 24 - KONEPURE_SIZE_PROFILE_BUTTONS = 0x3b, 25 - KONEPURE_SIZE_SENSOR = 0x06, 26 - KONEPURE_SIZE_TALK = 0x10, 27 - KONEPURE_SIZE_TCU = 0x04, 28 - KONEPURE_SIZE_TCU_IMAGE = 0x0404, 29 - }; 30 - 31 - enum konepure_control_requests { 32 - KONEPURE_CONTROL_REQUEST_GENERAL = 0x80, 33 - KONEPURE_CONTROL_REQUEST_BUTTONS = 0x90, 34 - }; 35 - 36 - enum konepure_commands { 37 - KONEPURE_COMMAND_CONTROL = 0x04, 38 - KONEPURE_COMMAND_ACTUAL_PROFILE = 0x05, 39 - KONEPURE_COMMAND_PROFILE_SETTINGS = 0x06, 40 - KONEPURE_COMMAND_PROFILE_BUTTONS = 0x07, 41 - KONEPURE_COMMAND_MACRO = 0x08, 42 - KONEPURE_COMMAND_INFO = 0x09, 43 - KONEPURE_COMMAND_TCU = 0x0c, 44 - KONEPURE_COMMAND_TCU_IMAGE = 0x0c, 45 - KONEPURE_COMMAND_E = 0x0e, 46 - KONEPURE_COMMAND_SENSOR = 0x0f, 47 - KONEPURE_COMMAND_TALK = 0x10, 48 - KONEPURE_COMMAND_FIRMWARE_WRITE = 0x1b, 49 - KONEPURE_COMMAND_FIRMWARE_WRITE_CONTROL = 0x1c, 50 - }; 51 - 52 - enum { 53 - KONEPURE_MOUSE_REPORT_NUMBER_BUTTON = 3, 54 - }; 55 - 56 - struct konepure_mouse_report_button { 57 - uint8_t report_number; /* always KONEPURE_MOUSE_REPORT_NUMBER_BUTTON */ 58 - uint8_t zero; 59 - uint8_t type; 60 - uint8_t data1; 61 - uint8_t data2; 62 - uint8_t zero2; 63 - uint8_t unknown[2]; 64 - } __packed; 65 - 66 - struct konepure_device { 67 - int roccat_claimed; 68 - int chrdev_minor; 69 - struct mutex konepure_lock; 70 - }; 71 - 72 - #endif
+15 -106
drivers/hid/hid-roccat-savu.c
··· 27 27 28 28 static struct class *savu_class; 29 29 30 - static ssize_t savu_sysfs_read(struct file *fp, struct kobject *kobj, 31 - char *buf, loff_t off, size_t count, 32 - size_t real_size, uint command) 33 - { 34 - struct device *dev = 35 - container_of(kobj, struct device, kobj)->parent->parent; 36 - struct savu_device *savu = hid_get_drvdata(dev_get_drvdata(dev)); 37 - struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); 38 - int retval; 30 + ROCCAT_COMMON2_BIN_ATTRIBUTE_W(control, 0x4, 0x03); 31 + ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(profile, 0x5, 0x03); 32 + ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(general, 0x6, 0x10); 33 + ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(buttons, 0x7, 0x2f); 34 + ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(macro, 0x8, 0x0823); 35 + ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(info, 0x9, 0x08); 36 + ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(sensor, 0xc, 0x04); 39 37 40 - if (off >= real_size) 41 - return 0; 42 - 43 - if (off != 0 || count != real_size) 44 - return -EINVAL; 45 - 46 - mutex_lock(&savu->savu_lock); 47 - retval = roccat_common2_receive(usb_dev, command, buf, real_size); 48 - mutex_unlock(&savu->savu_lock); 49 - 50 - return retval ? retval : real_size; 51 - } 52 - 53 - static ssize_t savu_sysfs_write(struct file *fp, struct kobject *kobj, 54 - void const *buf, loff_t off, size_t count, 55 - size_t real_size, uint command) 56 - { 57 - struct device *dev = 58 - container_of(kobj, struct device, kobj)->parent->parent; 59 - struct savu_device *savu = hid_get_drvdata(dev_get_drvdata(dev)); 60 - struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); 61 - int retval; 62 - 63 - if (off != 0 || count != real_size) 64 - return -EINVAL; 65 - 66 - mutex_lock(&savu->savu_lock); 67 - retval = roccat_common2_send_with_status(usb_dev, command, 68 - (void *)buf, real_size); 69 - mutex_unlock(&savu->savu_lock); 70 - 71 - return retval ? retval : real_size; 72 - } 73 - 74 - #define SAVU_SYSFS_W(thingy, THINGY) \ 75 - static ssize_t savu_sysfs_write_ ## thingy(struct file *fp, \ 76 - struct kobject *kobj, struct bin_attribute *attr, char *buf, \ 77 - loff_t off, size_t count) \ 78 - { \ 79 - return savu_sysfs_write(fp, kobj, buf, off, count, \ 80 - SAVU_SIZE_ ## THINGY, SAVU_COMMAND_ ## THINGY); \ 81 - } 82 - 83 - #define SAVU_SYSFS_R(thingy, THINGY) \ 84 - static ssize_t savu_sysfs_read_ ## thingy(struct file *fp, \ 85 - struct kobject *kobj, struct bin_attribute *attr, char *buf, \ 86 - loff_t off, size_t count) \ 87 - { \ 88 - return savu_sysfs_read(fp, kobj, buf, off, count, \ 89 - SAVU_SIZE_ ## THINGY, SAVU_COMMAND_ ## THINGY); \ 90 - } 91 - 92 - #define SAVU_SYSFS_RW(thingy, THINGY) \ 93 - SAVU_SYSFS_W(thingy, THINGY) \ 94 - SAVU_SYSFS_R(thingy, THINGY) 95 - 96 - #define SAVU_BIN_ATTRIBUTE_RW(thingy, THINGY) \ 97 - SAVU_SYSFS_RW(thingy, THINGY); \ 98 - static struct bin_attribute bin_attr_##thingy = { \ 99 - .attr = { .name = #thingy, .mode = 0660 }, \ 100 - .size = SAVU_SIZE_ ## THINGY, \ 101 - .read = savu_sysfs_read_ ## thingy, \ 102 - .write = savu_sysfs_write_ ## thingy \ 103 - } 104 - 105 - #define SAVU_BIN_ATTRIBUTE_W(thingy, THINGY) \ 106 - SAVU_SYSFS_W(thingy, THINGY); \ 107 - static struct bin_attribute bin_attr_##thingy = { \ 108 - .attr = { .name = #thingy, .mode = 0220 }, \ 109 - .size = SAVU_SIZE_ ## THINGY, \ 110 - .write = savu_sysfs_write_ ## thingy \ 111 - } 112 - 113 - SAVU_BIN_ATTRIBUTE_W(control, CONTROL); 114 - SAVU_BIN_ATTRIBUTE_RW(profile, PROFILE); 115 - SAVU_BIN_ATTRIBUTE_RW(general, GENERAL); 116 - SAVU_BIN_ATTRIBUTE_RW(buttons, BUTTONS); 117 - SAVU_BIN_ATTRIBUTE_RW(macro, MACRO); 118 - SAVU_BIN_ATTRIBUTE_RW(info, INFO); 119 - SAVU_BIN_ATTRIBUTE_RW(sensor, SENSOR); 120 - 121 - static struct bin_attribute *savu_bin_attributes[] = { 38 + static struct bin_attribute *savu_bin_attrs[] = { 122 39 &bin_attr_control, 123 40 &bin_attr_profile, 124 41 &bin_attr_general, ··· 47 130 }; 48 131 49 132 static const struct attribute_group savu_group = { 50 - .bin_attrs = savu_bin_attributes, 133 + .bin_attrs = savu_bin_attrs, 51 134 }; 52 135 53 136 static const struct attribute_group *savu_groups[] = { ··· 55 138 NULL, 56 139 }; 57 140 58 - static int savu_init_savu_device_struct(struct usb_device *usb_dev, 59 - struct savu_device *savu) 60 - { 61 - mutex_init(&savu->savu_lock); 62 - 63 - return 0; 64 - } 65 - 66 141 static int savu_init_specials(struct hid_device *hdev) 67 142 { 68 143 struct usb_interface *intf = to_usb_interface(hdev->dev.parent); 69 144 struct usb_device *usb_dev = interface_to_usbdev(intf); 70 - struct savu_device *savu; 145 + struct roccat_common2_device *savu; 71 146 int retval; 72 147 73 148 if (intf->cur_altsetting->desc.bInterfaceProtocol ··· 75 166 } 76 167 hid_set_drvdata(hdev, savu); 77 168 78 - retval = savu_init_savu_device_struct(usb_dev, savu); 169 + retval = roccat_common2_device_init_struct(usb_dev, savu); 79 170 if (retval) { 80 - hid_err(hdev, "couldn't init struct savu_device\n"); 171 + hid_err(hdev, "couldn't init Savu device\n"); 81 172 goto exit_free; 82 173 } 83 174 ··· 99 190 static void savu_remove_specials(struct hid_device *hdev) 100 191 { 101 192 struct usb_interface *intf = to_usb_interface(hdev->dev.parent); 102 - struct savu_device *savu; 193 + struct roccat_common2_device *savu; 103 194 104 195 if (intf->cur_altsetting->desc.bInterfaceProtocol 105 196 != USB_INTERFACE_PROTOCOL_MOUSE) ··· 148 239 hid_hw_stop(hdev); 149 240 } 150 241 151 - static void savu_report_to_chrdev(struct savu_device const *savu, 242 + static void savu_report_to_chrdev(struct roccat_common2_device const *savu, 152 243 u8 const *data) 153 244 { 154 245 struct savu_roccat_report roccat_report; ··· 170 261 struct hid_report *report, u8 *data, int size) 171 262 { 172 263 struct usb_interface *intf = to_usb_interface(hdev->dev.parent); 173 - struct savu_device *savu = hid_get_drvdata(hdev); 264 + struct roccat_common2_device *savu = hid_get_drvdata(hdev); 174 265 175 266 if (intf->cur_altsetting->desc.bInterfaceProtocol 176 267 != USB_INTERFACE_PROTOCOL_MOUSE)
-32
drivers/hid/hid-roccat-savu.h
··· 14 14 15 15 #include <linux/types.h> 16 16 17 - enum { 18 - SAVU_SIZE_CONTROL = 0x03, 19 - SAVU_SIZE_PROFILE = 0x03, 20 - SAVU_SIZE_GENERAL = 0x10, 21 - SAVU_SIZE_BUTTONS = 0x2f, 22 - SAVU_SIZE_MACRO = 0x0823, 23 - SAVU_SIZE_INFO = 0x08, 24 - SAVU_SIZE_SENSOR = 0x04, 25 - }; 26 - 27 - enum savu_control_requests { 28 - SAVU_CONTROL_REQUEST_GENERAL = 0x80, 29 - SAVU_CONTROL_REQUEST_BUTTONS = 0x90, 30 - }; 31 - 32 - enum savu_commands { 33 - SAVU_COMMAND_CONTROL = 0x4, 34 - SAVU_COMMAND_PROFILE = 0x5, 35 - SAVU_COMMAND_GENERAL = 0x6, 36 - SAVU_COMMAND_BUTTONS = 0x7, 37 - SAVU_COMMAND_MACRO = 0x8, 38 - SAVU_COMMAND_INFO = 0x9, 39 - SAVU_COMMAND_SENSOR = 0xc, 40 - }; 41 - 42 17 struct savu_mouse_report_special { 43 18 uint8_t report_number; /* always 3 */ 44 19 uint8_t zero; ··· 51 76 uint8_t type; 52 77 uint8_t data[2]; 53 78 } __packed; 54 - 55 - struct savu_device { 56 - int roccat_claimed; 57 - int chrdev_minor; 58 - 59 - struct mutex savu_lock; 60 - }; 61 79 62 80 #endif