aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hid/hid-roccat-arvo.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hid/hid-roccat-arvo.c')
-rw-r--r--drivers/hid/hid-roccat-arvo.c148
1 files changed, 41 insertions, 107 deletions
diff --git a/drivers/hid/hid-roccat-arvo.c b/drivers/hid/hid-roccat-arvo.c
index ebf3c15f1a7e..d72ee4186d11 100644
--- a/drivers/hid/hid-roccat-arvo.c
+++ b/drivers/hid/hid-roccat-arvo.c
@@ -19,41 +19,15 @@
19#include <linux/device.h> 19#include <linux/device.h>
20#include <linux/input.h> 20#include <linux/input.h>
21#include <linux/hid.h> 21#include <linux/hid.h>
22#include <linux/usb.h>
23#include <linux/module.h> 22#include <linux/module.h>
24#include <linux/slab.h> 23#include <linux/slab.h>
25#include "hid-ids.h" 24#include "hid-ids.h"
26#include "hid-roccat.h" 25#include "hid-roccat.h"
26#include "hid-roccat-common.h"
27#include "hid-roccat-arvo.h" 27#include "hid-roccat-arvo.h"
28 28
29static struct class *arvo_class; 29static struct class *arvo_class;
30 30
31static int arvo_receive(struct usb_device *usb_dev, uint usb_command,
32 void *buf, uint size)
33{
34 int len;
35
36 len = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
37 USB_REQ_CLEAR_FEATURE,
38 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
39 usb_command, 0, buf, size, USB_CTRL_SET_TIMEOUT);
40
41 return (len != size) ? -EIO : 0;
42}
43
44static int arvo_send(struct usb_device *usb_dev, uint usb_command,
45 void const *buf, uint size)
46{
47 int len;
48
49 len = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
50 USB_REQ_SET_CONFIGURATION,
51 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
52 usb_command, 0, (void *)buf, size, USB_CTRL_SET_TIMEOUT);
53
54 return (len != size) ? -EIO : 0;
55}
56
57static ssize_t arvo_sysfs_show_mode_key(struct device *dev, 31static ssize_t arvo_sysfs_show_mode_key(struct device *dev,
58 struct device_attribute *attr, char *buf) 32 struct device_attribute *attr, char *buf)
59{ 33{
@@ -61,24 +35,17 @@ static ssize_t arvo_sysfs_show_mode_key(struct device *dev,
61 hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); 35 hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
62 struct usb_device *usb_dev = 36 struct usb_device *usb_dev =
63 interface_to_usbdev(to_usb_interface(dev->parent->parent)); 37 interface_to_usbdev(to_usb_interface(dev->parent->parent));
64 struct arvo_mode_key *temp_buf; 38 struct arvo_mode_key temp_buf;
65 int retval; 39 int retval;
66 40
67 temp_buf = kmalloc(sizeof(struct arvo_mode_key), GFP_KERNEL);
68 if (!temp_buf)
69 return -ENOMEM;
70
71 mutex_lock(&arvo->arvo_lock); 41 mutex_lock(&arvo->arvo_lock);
72 retval = arvo_receive(usb_dev, ARVO_USB_COMMAND_MODE_KEY, 42 retval = roccat_common_receive(usb_dev, ARVO_USB_COMMAND_MODE_KEY,
73 temp_buf, sizeof(struct arvo_mode_key)); 43 &temp_buf, sizeof(struct arvo_mode_key));
74 mutex_unlock(&arvo->arvo_lock); 44 mutex_unlock(&arvo->arvo_lock);
75 if (retval) 45 if (retval)
76 goto out; 46 return retval;
77 47
78 retval = snprintf(buf, PAGE_SIZE, "%d\n", temp_buf->state); 48 return snprintf(buf, PAGE_SIZE, "%d\n", temp_buf.state);
79out:
80 kfree(temp_buf);
81 return retval;
82} 49}
83 50
84static ssize_t arvo_sysfs_set_mode_key(struct device *dev, 51static ssize_t arvo_sysfs_set_mode_key(struct device *dev,
@@ -88,32 +55,25 @@ static ssize_t arvo_sysfs_set_mode_key(struct device *dev,
88 hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); 55 hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
89 struct usb_device *usb_dev = 56 struct usb_device *usb_dev =
90 interface_to_usbdev(to_usb_interface(dev->parent->parent)); 57 interface_to_usbdev(to_usb_interface(dev->parent->parent));
91 struct arvo_mode_key *temp_buf; 58 struct arvo_mode_key temp_buf;
92 unsigned long state; 59 unsigned long state;
93 int retval; 60 int retval;
94 61
95 temp_buf = kmalloc(sizeof(struct arvo_mode_key), GFP_KERNEL);
96 if (!temp_buf)
97 return -ENOMEM;
98
99 retval = strict_strtoul(buf, 10, &state); 62 retval = strict_strtoul(buf, 10, &state);
100 if (retval) 63 if (retval)
101 goto out; 64 return retval;
102 65
103 temp_buf->command = ARVO_COMMAND_MODE_KEY; 66 temp_buf.command = ARVO_COMMAND_MODE_KEY;
104 temp_buf->state = state; 67 temp_buf.state = state;
105 68
106 mutex_lock(&arvo->arvo_lock); 69 mutex_lock(&arvo->arvo_lock);
107 retval = arvo_send(usb_dev, ARVO_USB_COMMAND_MODE_KEY, 70 retval = roccat_common_send(usb_dev, ARVO_USB_COMMAND_MODE_KEY,
108 temp_buf, sizeof(struct arvo_mode_key)); 71 &temp_buf, sizeof(struct arvo_mode_key));
109 mutex_unlock(&arvo->arvo_lock); 72 mutex_unlock(&arvo->arvo_lock);
110 if (retval) 73 if (retval)
111 goto out; 74 return retval;
112 75
113 retval = size; 76 return size;
114out:
115 kfree(temp_buf);
116 return retval;
117} 77}
118 78
119static ssize_t arvo_sysfs_show_key_mask(struct device *dev, 79static ssize_t arvo_sysfs_show_key_mask(struct device *dev,
@@ -123,24 +83,17 @@ static ssize_t arvo_sysfs_show_key_mask(struct device *dev,
123 hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); 83 hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
124 struct usb_device *usb_dev = 84 struct usb_device *usb_dev =
125 interface_to_usbdev(to_usb_interface(dev->parent->parent)); 85 interface_to_usbdev(to_usb_interface(dev->parent->parent));
126 struct arvo_key_mask *temp_buf; 86 struct arvo_key_mask temp_buf;
127 int retval; 87 int retval;
128 88
129 temp_buf = kmalloc(sizeof(struct arvo_key_mask), GFP_KERNEL);
130 if (!temp_buf)
131 return -ENOMEM;
132
133 mutex_lock(&arvo->arvo_lock); 89 mutex_lock(&arvo->arvo_lock);
134 retval = arvo_receive(usb_dev, ARVO_USB_COMMAND_KEY_MASK, 90 retval = roccat_common_receive(usb_dev, ARVO_USB_COMMAND_KEY_MASK,
135 temp_buf, sizeof(struct arvo_key_mask)); 91 &temp_buf, sizeof(struct arvo_key_mask));
136 mutex_unlock(&arvo->arvo_lock); 92 mutex_unlock(&arvo->arvo_lock);
137 if (retval) 93 if (retval)
138 goto out; 94 return retval;
139 95
140 retval = snprintf(buf, PAGE_SIZE, "%d\n", temp_buf->key_mask); 96 return snprintf(buf, PAGE_SIZE, "%d\n", temp_buf.key_mask);
141out:
142 kfree(temp_buf);
143 return retval;
144} 97}
145 98
146static ssize_t arvo_sysfs_set_key_mask(struct device *dev, 99static ssize_t arvo_sysfs_set_key_mask(struct device *dev,
@@ -150,52 +103,40 @@ static ssize_t arvo_sysfs_set_key_mask(struct device *dev,
150 hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); 103 hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
151 struct usb_device *usb_dev = 104 struct usb_device *usb_dev =
152 interface_to_usbdev(to_usb_interface(dev->parent->parent)); 105 interface_to_usbdev(to_usb_interface(dev->parent->parent));
153 struct arvo_key_mask *temp_buf; 106 struct arvo_key_mask temp_buf;
154 unsigned long key_mask; 107 unsigned long key_mask;
155 int retval; 108 int retval;
156 109
157 temp_buf = kmalloc(sizeof(struct arvo_key_mask), GFP_KERNEL);
158 if (!temp_buf)
159 return -ENOMEM;
160
161 retval = strict_strtoul(buf, 10, &key_mask); 110 retval = strict_strtoul(buf, 10, &key_mask);
162 if (retval) 111 if (retval)
163 goto out; 112 return retval;
164 113
165 temp_buf->command = ARVO_COMMAND_KEY_MASK; 114 temp_buf.command = ARVO_COMMAND_KEY_MASK;
166 temp_buf->key_mask = key_mask; 115 temp_buf.key_mask = key_mask;
167 116
168 mutex_lock(&arvo->arvo_lock); 117 mutex_lock(&arvo->arvo_lock);
169 retval = arvo_send(usb_dev, ARVO_USB_COMMAND_KEY_MASK, 118 retval = roccat_common_send(usb_dev, ARVO_USB_COMMAND_KEY_MASK,
170 temp_buf, sizeof(struct arvo_key_mask)); 119 &temp_buf, sizeof(struct arvo_key_mask));
171 mutex_unlock(&arvo->arvo_lock); 120 mutex_unlock(&arvo->arvo_lock);
172 if (retval) 121 if (retval)
173 goto out; 122 return retval;
174 123
175 retval = size; 124 return size;
176out:
177 kfree(temp_buf);
178 return retval;
179} 125}
180 126
181/* retval is 1-5 on success, < 0 on error */ 127/* retval is 1-5 on success, < 0 on error */
182static int arvo_get_actual_profile(struct usb_device *usb_dev) 128static int arvo_get_actual_profile(struct usb_device *usb_dev)
183{ 129{
184 struct arvo_actual_profile *temp_buf; 130 struct arvo_actual_profile temp_buf;
185 int retval; 131 int retval;
186 132
187 temp_buf = kmalloc(sizeof(struct arvo_actual_profile), GFP_KERNEL); 133 retval = roccat_common_receive(usb_dev, ARVO_USB_COMMAND_ACTUAL_PROFILE,
188 if (!temp_buf) 134 &temp_buf, sizeof(struct arvo_actual_profile));
189 return -ENOMEM;
190
191 retval = arvo_receive(usb_dev, ARVO_USB_COMMAND_ACTUAL_PROFILE,
192 temp_buf, sizeof(struct arvo_actual_profile));
193 135
194 if (!retval) 136 if (retval)
195 retval = temp_buf->actual_profile; 137 return retval;
196 138
197 kfree(temp_buf); 139 return temp_buf.actual_profile;
198 return retval;
199} 140}
200 141
201static ssize_t arvo_sysfs_show_actual_profile(struct device *dev, 142static ssize_t arvo_sysfs_show_actual_profile(struct device *dev,
@@ -214,32 +155,25 @@ static ssize_t arvo_sysfs_set_actual_profile(struct device *dev,
214 hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); 155 hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
215 struct usb_device *usb_dev = 156 struct usb_device *usb_dev =
216 interface_to_usbdev(to_usb_interface(dev->parent->parent)); 157 interface_to_usbdev(to_usb_interface(dev->parent->parent));
217 struct arvo_actual_profile *temp_buf; 158 struct arvo_actual_profile temp_buf;
218 unsigned long profile; 159 unsigned long profile;
219 int retval; 160 int retval;
220 161
221 temp_buf = kmalloc(sizeof(struct arvo_actual_profile), GFP_KERNEL);
222 if (!temp_buf)
223 return -ENOMEM;
224
225 retval = strict_strtoul(buf, 10, &profile); 162 retval = strict_strtoul(buf, 10, &profile);
226 if (retval) 163 if (retval)
227 goto out; 164 return retval;
228 165
229 temp_buf->command = ARVO_COMMAND_ACTUAL_PROFILE; 166 temp_buf.command = ARVO_COMMAND_ACTUAL_PROFILE;
230 temp_buf->actual_profile = profile; 167 temp_buf.actual_profile = profile;
231 168
232 mutex_lock(&arvo->arvo_lock); 169 mutex_lock(&arvo->arvo_lock);
233 retval = arvo_send(usb_dev, ARVO_USB_COMMAND_ACTUAL_PROFILE, 170 retval = roccat_common_send(usb_dev, ARVO_USB_COMMAND_ACTUAL_PROFILE,
234 temp_buf, sizeof(struct arvo_actual_profile)); 171 &temp_buf, sizeof(struct arvo_actual_profile));
235 if (!retval) { 172 if (!retval) {
236 arvo->actual_profile = profile; 173 arvo->actual_profile = profile;
237 retval = size; 174 retval = size;
238 } 175 }
239 mutex_unlock(&arvo->arvo_lock); 176 mutex_unlock(&arvo->arvo_lock);
240
241out:
242 kfree(temp_buf);
243 return retval; 177 return retval;
244} 178}
245 179
@@ -257,7 +191,7 @@ static ssize_t arvo_sysfs_write(struct file *fp,
257 return -EINVAL; 191 return -EINVAL;
258 192
259 mutex_lock(&arvo->arvo_lock); 193 mutex_lock(&arvo->arvo_lock);
260 retval = arvo_send(usb_dev, command, buf, real_size); 194 retval = roccat_common_send(usb_dev, command, buf, real_size);
261 mutex_unlock(&arvo->arvo_lock); 195 mutex_unlock(&arvo->arvo_lock);
262 196
263 return (retval ? retval : real_size); 197 return (retval ? retval : real_size);
@@ -280,7 +214,7 @@ static ssize_t arvo_sysfs_read(struct file *fp,
280 return -EINVAL; 214 return -EINVAL;
281 215
282 mutex_lock(&arvo->arvo_lock); 216 mutex_lock(&arvo->arvo_lock);
283 retval = arvo_receive(usb_dev, command, buf, real_size); 217 retval = roccat_common_receive(usb_dev, command, buf, real_size);
284 mutex_unlock(&arvo->arvo_lock); 218 mutex_unlock(&arvo->arvo_lock);
285 219
286 return (retval ? retval : real_size); 220 return (retval ? retval : real_size);