diff options
Diffstat (limited to 'drivers/hid/hid-roccat-konepure.c')
-rw-r--r-- | drivers/hid/hid-roccat-konepure.c | 158 |
1 files changed, 36 insertions, 122 deletions
diff --git a/drivers/hid/hid-roccat-konepure.c b/drivers/hid/hid-roccat-konepure.c index 99a605ebb665..07de2f9014c6 100644 --- a/drivers/hid/hid-roccat-konepure.c +++ b/drivers/hid/hid-roccat-konepure.c | |||
@@ -15,6 +15,7 @@ | |||
15 | * Roccat KonePure is a smaller version of KoneXTD with less buttons and lights. | 15 | * Roccat KonePure is a smaller version of KoneXTD with less buttons and lights. |
16 | */ | 16 | */ |
17 | 17 | ||
18 | #include <linux/types.h> | ||
18 | #include <linux/device.h> | 19 | #include <linux/device.h> |
19 | #include <linux/input.h> | 20 | #include <linux/input.h> |
20 | #include <linux/hid.h> | 21 | #include <linux/hid.h> |
@@ -23,128 +24,50 @@ | |||
23 | #include <linux/hid-roccat.h> | 24 | #include <linux/hid-roccat.h> |
24 | #include "hid-ids.h" | 25 | #include "hid-ids.h" |
25 | #include "hid-roccat-common.h" | 26 | #include "hid-roccat-common.h" |
26 | #include "hid-roccat-konepure.h" | ||
27 | 27 | ||
28 | static struct class *konepure_class; | 28 | enum { |
29 | 29 | KONEPURE_MOUSE_REPORT_NUMBER_BUTTON = 3, | |
30 | static ssize_t konepure_sysfs_read(struct file *fp, struct kobject *kobj, | 30 | }; |
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 konepure_device *konepure = hid_get_drvdata(dev_get_drvdata(dev)); | ||
37 | struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); | ||
38 | int retval; | ||
39 | |||
40 | if (off >= real_size) | ||
41 | return 0; | ||
42 | |||
43 | if (off != 0 || count != real_size) | ||
44 | return -EINVAL; | ||
45 | |||
46 | mutex_lock(&konepure->konepure_lock); | ||
47 | retval = roccat_common2_receive(usb_dev, command, buf, real_size); | ||
48 | mutex_unlock(&konepure->konepure_lock); | ||
49 | |||
50 | return retval ? retval : real_size; | ||
51 | } | ||
52 | |||
53 | static ssize_t konepure_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 konepure_device *konepure = 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(&konepure->konepure_lock); | ||
67 | retval = roccat_common2_send_with_status(usb_dev, command, | ||
68 | (void *)buf, real_size); | ||
69 | mutex_unlock(&konepure->konepure_lock); | ||
70 | |||
71 | return retval ? retval : real_size; | ||
72 | } | ||
73 | |||
74 | #define KONEPURE_SYSFS_W(thingy, THINGY) \ | ||
75 | static ssize_t konepure_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 konepure_sysfs_write(fp, kobj, buf, off, count, \ | ||
80 | KONEPURE_SIZE_ ## THINGY, KONEPURE_COMMAND_ ## THINGY); \ | ||
81 | } | ||
82 | |||
83 | #define KONEPURE_SYSFS_R(thingy, THINGY) \ | ||
84 | static ssize_t konepure_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 konepure_sysfs_read(fp, kobj, buf, off, count, \ | ||
89 | KONEPURE_SIZE_ ## THINGY, KONEPURE_COMMAND_ ## THINGY); \ | ||
90 | } | ||
91 | 31 | ||
92 | #define KONEPURE_SYSFS_RW(thingy, THINGY) \ | 32 | struct konepure_mouse_report_button { |
93 | KONEPURE_SYSFS_W(thingy, THINGY) \ | 33 | uint8_t report_number; /* always KONEPURE_MOUSE_REPORT_NUMBER_BUTTON */ |
94 | KONEPURE_SYSFS_R(thingy, THINGY) | 34 | uint8_t zero; |
95 | 35 | uint8_t type; | |
96 | #define KONEPURE_BIN_ATTRIBUTE_RW(thingy, THINGY) \ | 36 | uint8_t data1; |
97 | KONEPURE_SYSFS_RW(thingy, THINGY); \ | 37 | uint8_t data2; |
98 | static struct bin_attribute bin_attr_##thingy = { \ | 38 | uint8_t zero2; |
99 | .attr = { .name = #thingy, .mode = 0660 }, \ | 39 | uint8_t unknown[2]; |
100 | .size = KONEPURE_SIZE_ ## THINGY, \ | 40 | } __packed; |
101 | .read = konepure_sysfs_read_ ## thingy, \ | ||
102 | .write = konepure_sysfs_write_ ## thingy \ | ||
103 | } | ||
104 | 41 | ||
105 | #define KONEPURE_BIN_ATTRIBUTE_R(thingy, THINGY) \ | 42 | static struct class *konepure_class; |
106 | KONEPURE_SYSFS_R(thingy, THINGY); \ | ||
107 | static struct bin_attribute bin_attr_##thingy = { \ | ||
108 | .attr = { .name = #thingy, .mode = 0440 }, \ | ||
109 | .size = KONEPURE_SIZE_ ## THINGY, \ | ||
110 | .read = konepure_sysfs_read_ ## thingy, \ | ||
111 | } | ||
112 | |||
113 | #define KONEPURE_BIN_ATTRIBUTE_W(thingy, THINGY) \ | ||
114 | KONEPURE_SYSFS_W(thingy, THINGY); \ | ||
115 | static struct bin_attribute bin_attr_##thingy = { \ | ||
116 | .attr = { .name = #thingy, .mode = 0220 }, \ | ||
117 | .size = KONEPURE_SIZE_ ## THINGY, \ | ||
118 | .write = konepure_sysfs_write_ ## thingy \ | ||
119 | } | ||
120 | 43 | ||
121 | KONEPURE_BIN_ATTRIBUTE_RW(actual_profile, ACTUAL_PROFILE); | 44 | ROCCAT_COMMON2_BIN_ATTRIBUTE_W(control, 0x04, 0x03); |
122 | KONEPURE_BIN_ATTRIBUTE_RW(info, INFO); | 45 | ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(actual_profile, 0x05, 0x03); |
123 | KONEPURE_BIN_ATTRIBUTE_RW(sensor, SENSOR); | 46 | ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(profile_settings, 0x06, 0x1f); |
124 | KONEPURE_BIN_ATTRIBUTE_RW(tcu, TCU); | 47 | ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(profile_buttons, 0x07, 0x3b); |
125 | KONEPURE_BIN_ATTRIBUTE_RW(profile_settings, PROFILE_SETTINGS); | 48 | ROCCAT_COMMON2_BIN_ATTRIBUTE_W(macro, 0x08, 0x0822); |
126 | KONEPURE_BIN_ATTRIBUTE_RW(profile_buttons, PROFILE_BUTTONS); | 49 | ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(info, 0x09, 0x06); |
127 | KONEPURE_BIN_ATTRIBUTE_W(control, CONTROL); | 50 | ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(tcu, 0x0c, 0x04); |
128 | KONEPURE_BIN_ATTRIBUTE_W(talk, TALK); | 51 | ROCCAT_COMMON2_BIN_ATTRIBUTE_R(tcu_image, 0x0c, 0x0404); |
129 | KONEPURE_BIN_ATTRIBUTE_W(macro, MACRO); | 52 | ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(sensor, 0x0f, 0x06); |
130 | KONEPURE_BIN_ATTRIBUTE_R(tcu_image, TCU_IMAGE); | 53 | ROCCAT_COMMON2_BIN_ATTRIBUTE_W(talk, 0x10, 0x10); |
131 | 54 | ||
132 | static struct bin_attribute *konepure_bin_attributes[] = { | 55 | static struct bin_attribute *konepure_bin_attrs[] = { |
133 | &bin_attr_actual_profile, | 56 | &bin_attr_actual_profile, |
57 | &bin_attr_control, | ||
134 | &bin_attr_info, | 58 | &bin_attr_info, |
59 | &bin_attr_talk, | ||
60 | &bin_attr_macro, | ||
135 | &bin_attr_sensor, | 61 | &bin_attr_sensor, |
136 | &bin_attr_tcu, | 62 | &bin_attr_tcu, |
63 | &bin_attr_tcu_image, | ||
137 | &bin_attr_profile_settings, | 64 | &bin_attr_profile_settings, |
138 | &bin_attr_profile_buttons, | 65 | &bin_attr_profile_buttons, |
139 | &bin_attr_control, | ||
140 | &bin_attr_talk, | ||
141 | &bin_attr_macro, | ||
142 | &bin_attr_tcu_image, | ||
143 | NULL, | 66 | NULL, |
144 | }; | 67 | }; |
145 | 68 | ||
146 | static const struct attribute_group konepure_group = { | 69 | static const struct attribute_group konepure_group = { |
147 | .bin_attrs = konepure_bin_attributes, | 70 | .bin_attrs = konepure_bin_attrs, |
148 | }; | 71 | }; |
149 | 72 | ||
150 | static const struct attribute_group *konepure_groups[] = { | 73 | static const struct attribute_group *konepure_groups[] = { |
@@ -152,20 +75,11 @@ static const struct attribute_group *konepure_groups[] = { | |||
152 | NULL, | 75 | NULL, |
153 | }; | 76 | }; |
154 | 77 | ||
155 | |||
156 | static int konepure_init_konepure_device_struct(struct usb_device *usb_dev, | ||
157 | struct konepure_device *konepure) | ||
158 | { | ||
159 | mutex_init(&konepure->konepure_lock); | ||
160 | |||
161 | return 0; | ||
162 | } | ||
163 | |||
164 | static int konepure_init_specials(struct hid_device *hdev) | 78 | static int konepure_init_specials(struct hid_device *hdev) |
165 | { | 79 | { |
166 | struct usb_interface *intf = to_usb_interface(hdev->dev.parent); | 80 | struct usb_interface *intf = to_usb_interface(hdev->dev.parent); |
167 | struct usb_device *usb_dev = interface_to_usbdev(intf); | 81 | struct usb_device *usb_dev = interface_to_usbdev(intf); |
168 | struct konepure_device *konepure; | 82 | struct roccat_common2_device *konepure; |
169 | int retval; | 83 | int retval; |
170 | 84 | ||
171 | if (intf->cur_altsetting->desc.bInterfaceProtocol | 85 | if (intf->cur_altsetting->desc.bInterfaceProtocol |
@@ -181,9 +95,9 @@ static int konepure_init_specials(struct hid_device *hdev) | |||
181 | } | 95 | } |
182 | hid_set_drvdata(hdev, konepure); | 96 | hid_set_drvdata(hdev, konepure); |
183 | 97 | ||
184 | retval = konepure_init_konepure_device_struct(usb_dev, konepure); | 98 | retval = roccat_common2_device_init_struct(usb_dev, konepure); |
185 | if (retval) { | 99 | if (retval) { |
186 | hid_err(hdev, "couldn't init struct konepure_device\n"); | 100 | hid_err(hdev, "couldn't init KonePure device\n"); |
187 | goto exit_free; | 101 | goto exit_free; |
188 | } | 102 | } |
189 | 103 | ||
@@ -205,7 +119,7 @@ exit_free: | |||
205 | static void konepure_remove_specials(struct hid_device *hdev) | 119 | static void konepure_remove_specials(struct hid_device *hdev) |
206 | { | 120 | { |
207 | struct usb_interface *intf = to_usb_interface(hdev->dev.parent); | 121 | struct usb_interface *intf = to_usb_interface(hdev->dev.parent); |
208 | struct konepure_device *konepure; | 122 | struct roccat_common2_device *konepure; |
209 | 123 | ||
210 | if (intf->cur_altsetting->desc.bInterfaceProtocol | 124 | if (intf->cur_altsetting->desc.bInterfaceProtocol |
211 | != USB_INTERFACE_PROTOCOL_MOUSE) | 125 | != USB_INTERFACE_PROTOCOL_MOUSE) |
@@ -258,7 +172,7 @@ static int konepure_raw_event(struct hid_device *hdev, | |||
258 | struct hid_report *report, u8 *data, int size) | 172 | struct hid_report *report, u8 *data, int size) |
259 | { | 173 | { |
260 | struct usb_interface *intf = to_usb_interface(hdev->dev.parent); | 174 | struct usb_interface *intf = to_usb_interface(hdev->dev.parent); |
261 | struct konepure_device *konepure = hid_get_drvdata(hdev); | 175 | struct roccat_common2_device *konepure = hid_get_drvdata(hdev); |
262 | 176 | ||
263 | if (intf->cur_altsetting->desc.bInterfaceProtocol | 177 | if (intf->cur_altsetting->desc.bInterfaceProtocol |
264 | != USB_INTERFACE_PROTOCOL_MOUSE) | 178 | != USB_INTERFACE_PROTOCOL_MOUSE) |