aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/ABI/obsolete/sysfs-driver-hid-roccat-pyra48
-rw-r--r--Documentation/ABI/testing/sysfs-driver-hid-roccat-pyra45
-rw-r--r--drivers/hid/hid-roccat-pyra.c340
-rw-r--r--drivers/hid/hid-roccat-pyra.h22
4 files changed, 198 insertions, 257 deletions
diff --git a/Documentation/ABI/obsolete/sysfs-driver-hid-roccat-pyra b/Documentation/ABI/obsolete/sysfs-driver-hid-roccat-pyra
new file mode 100644
index 000000000000..0a661b39e701
--- /dev/null
+++ b/Documentation/ABI/obsolete/sysfs-driver-hid-roccat-pyra
@@ -0,0 +1,48 @@
1What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/pyra/roccatpyra<minor>/actual_cpi
2Date: August 2010
3Contact: Stefan Achatz <erazor_de@users.sourceforge.net>
4Description: It is possible to switch the cpi setting of the mouse with the
5 press of a button.
6 When read, this file returns the raw number of the actual cpi
7 setting reported by the mouse. This number has to be further
8 processed to receive the real dpi value.
9
10 VALUE DPI
11 1 400
12 2 800
13 4 1600
14
15 This file is readonly.
16 Has never been used. If bookkeeping is done, it's done in userland tools.
17Users: http://roccat.sourceforge.net
18
19What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/pyra/roccatpyra<minor>/actual_profile
20Date: August 2010
21Contact: Stefan Achatz <erazor_de@users.sourceforge.net>
22Description: When read, this file returns the number of the actual profile in
23 range 0-4.
24 This file is readonly.
25 Please use binary attribute "settings" which provides this information.
26Users: http://roccat.sourceforge.net
27
28What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/pyra/roccatpyra<minor>/firmware_version
29Date: August 2010
30Contact: Stefan Achatz <erazor_de@users.sourceforge.net>
31Description: When read, this file returns the raw integer version number of the
32 firmware reported by the mouse. Using the integer value eases
33 further usage in other programs. To receive the real version
34 number the decimal point has to be shifted 2 positions to the
35 left. E.g. a returned value of 138 means 1.38
36 This file is readonly.
37 Please use binary attribute "info" which provides this information.
38Users: http://roccat.sourceforge.net
39
40What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/pyra/roccatpyra<minor>/startup_profile
41Date: August 2010
42Contact: Stefan Achatz <erazor_de@users.sourceforge.net>
43Description: The integer value of this attribute ranges from 0-4.
44 When read, this attribute returns the number of the profile
45 that's active when the mouse is powered on.
46 This file is readonly.
47 Please use binary attribute "settings" which provides this information.
48Users: http://roccat.sourceforge.net \ No newline at end of file
diff --git a/Documentation/ABI/testing/sysfs-driver-hid-roccat-pyra b/Documentation/ABI/testing/sysfs-driver-hid-roccat-pyra
index 3f8de50e4ff1..b0fab8bcf247 100644
--- a/Documentation/ABI/testing/sysfs-driver-hid-roccat-pyra
+++ b/Documentation/ABI/testing/sysfs-driver-hid-roccat-pyra
@@ -1,39 +1,3 @@
1What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/pyra/roccatpyra<minor>/actual_cpi
2Date: August 2010
3Contact: Stefan Achatz <erazor_de@users.sourceforge.net>
4Description: It is possible to switch the cpi setting of the mouse with the
5 press of a button.
6 When read, this file returns the raw number of the actual cpi
7 setting reported by the mouse. This number has to be further
8 processed to receive the real dpi value.
9
10 VALUE DPI
11 1 400
12 2 800
13 4 1600
14
15 This file is readonly.
16Users: http://roccat.sourceforge.net
17
18What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/pyra/roccatpyra<minor>/actual_profile
19Date: August 2010
20Contact: Stefan Achatz <erazor_de@users.sourceforge.net>
21Description: When read, this file returns the number of the actual profile in
22 range 0-4.
23 This file is readonly.
24Users: http://roccat.sourceforge.net
25
26What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/pyra/roccatpyra<minor>/firmware_version
27Date: August 2010
28Contact: Stefan Achatz <erazor_de@users.sourceforge.net>
29Description: When read, this file returns the raw integer version number of the
30 firmware reported by the mouse. Using the integer value eases
31 further usage in other programs. To receive the real version
32 number the decimal point has to be shifted 2 positions to the
33 left. E.g. a returned value of 138 means 1.38
34 This file is readonly.
35Users: http://roccat.sourceforge.net
36
37What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/pyra/roccatpyra<minor>/profile_settings 1What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/pyra/roccatpyra<minor>/profile_settings
38Date: August 2010 2Date: August 2010
39Contact: Stefan Achatz <erazor_de@users.sourceforge.net> 3Contact: Stefan Achatz <erazor_de@users.sourceforge.net>
@@ -86,15 +50,6 @@ Description: The mouse can store 5 profiles which can be switched by the
86 This file is readonly. 50 This file is readonly.
87Users: http://roccat.sourceforge.net 51Users: http://roccat.sourceforge.net
88 52
89What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/pyra/roccatpyra<minor>/startup_profile
90Date: August 2010
91Contact: Stefan Achatz <erazor_de@users.sourceforge.net>
92Description: The integer value of this attribute ranges from 0-4.
93 When read, this attribute returns the number of the profile
94 that's active when the mouse is powered on.
95 This file is readonly.
96Users: http://roccat.sourceforge.net
97
98What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/pyra/roccatpyra<minor>/settings 53What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/pyra/roccatpyra<minor>/settings
99Date: August 2010 54Date: August 2010
100Contact: Stefan Achatz <erazor_de@users.sourceforge.net> 55Contact: Stefan Achatz <erazor_de@users.sourceforge.net>
diff --git a/drivers/hid/hid-roccat-pyra.c b/drivers/hid/hid-roccat-pyra.c
index 1317c177a3e2..76199fa727ed 100644
--- a/drivers/hid/hid-roccat-pyra.c
+++ b/drivers/hid/hid-roccat-pyra.c
@@ -66,48 +66,14 @@ static int pyra_get_profile_settings(struct usb_device *usb_dev,
66 if (retval) 66 if (retval)
67 return retval; 67 return retval;
68 return roccat_common2_receive(usb_dev, PYRA_COMMAND_PROFILE_SETTINGS, 68 return roccat_common2_receive(usb_dev, PYRA_COMMAND_PROFILE_SETTINGS,
69 buf, sizeof(struct pyra_profile_settings)); 69 buf, PYRA_SIZE_PROFILE_SETTINGS);
70}
71
72static int pyra_get_profile_buttons(struct usb_device *usb_dev,
73 struct pyra_profile_buttons *buf, int number)
74{
75 int retval;
76 retval = pyra_send_control(usb_dev, number,
77 PYRA_CONTROL_REQUEST_PROFILE_BUTTONS);
78 if (retval)
79 return retval;
80 return roccat_common2_receive(usb_dev, PYRA_COMMAND_PROFILE_BUTTONS,
81 buf, sizeof(struct pyra_profile_buttons));
82} 70}
83 71
84static int pyra_get_settings(struct usb_device *usb_dev, 72static int pyra_get_settings(struct usb_device *usb_dev,
85 struct pyra_settings *buf) 73 struct pyra_settings *buf)
86{ 74{
87 return roccat_common2_receive(usb_dev, PYRA_COMMAND_SETTINGS, 75 return roccat_common2_receive(usb_dev, PYRA_COMMAND_SETTINGS,
88 buf, sizeof(struct pyra_settings)); 76 buf, PYRA_SIZE_SETTINGS);
89}
90
91static int pyra_get_info(struct usb_device *usb_dev, struct pyra_info *buf)
92{
93 return roccat_common2_receive(usb_dev, PYRA_COMMAND_INFO,
94 buf, sizeof(struct pyra_info));
95}
96
97static int pyra_set_profile_settings(struct usb_device *usb_dev,
98 struct pyra_profile_settings const *settings)
99{
100 return roccat_common2_send_with_status(usb_dev,
101 PYRA_COMMAND_PROFILE_SETTINGS, settings,
102 sizeof(struct pyra_profile_settings));
103}
104
105static int pyra_set_profile_buttons(struct usb_device *usb_dev,
106 struct pyra_profile_buttons const *buttons)
107{
108 return roccat_common2_send_with_status(usb_dev,
109 PYRA_COMMAND_PROFILE_BUTTONS, buttons,
110 sizeof(struct pyra_profile_buttons));
111} 77}
112 78
113static int pyra_set_settings(struct usb_device *usb_dev, 79static int pyra_set_settings(struct usb_device *usb_dev,
@@ -115,146 +81,143 @@ static int pyra_set_settings(struct usb_device *usb_dev,
115{ 81{
116 return roccat_common2_send_with_status(usb_dev, 82 return roccat_common2_send_with_status(usb_dev,
117 PYRA_COMMAND_SETTINGS, settings, 83 PYRA_COMMAND_SETTINGS, settings,
118 sizeof(struct pyra_settings)); 84 PYRA_SIZE_SETTINGS);
119} 85}
120 86
121static ssize_t pyra_sysfs_read_profilex_settings(struct file *fp, 87static ssize_t pyra_sysfs_read(struct file *fp, struct kobject *kobj,
122 struct kobject *kobj, struct bin_attribute *attr, char *buf, 88 char *buf, loff_t off, size_t count,
123 loff_t off, size_t count) 89 size_t real_size, uint command)
124{ 90{
125 struct device *dev = 91 struct device *dev =
126 container_of(kobj, struct device, kobj)->parent->parent; 92 container_of(kobj, struct device, kobj)->parent->parent;
127 struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev)); 93 struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev));
94 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
95 int retval;
128 96
129 if (off >= sizeof(struct pyra_profile_settings)) 97 if (off >= real_size)
130 return 0; 98 return 0;
131 99
132 if (off + count > sizeof(struct pyra_profile_settings)) 100 if (off != 0 || count != real_size)
133 count = sizeof(struct pyra_profile_settings) - off; 101 return -EINVAL;
134 102
135 mutex_lock(&pyra->pyra_lock); 103 mutex_lock(&pyra->pyra_lock);
136 memcpy(buf, ((char const *)&pyra->profile_settings[*(uint *)(attr->private)]) + off, 104 retval = roccat_common2_receive(usb_dev, command, buf, real_size);
137 count);
138 mutex_unlock(&pyra->pyra_lock); 105 mutex_unlock(&pyra->pyra_lock);
139 106
140 return count; 107 if (retval)
108 return retval;
109
110 return real_size;
141} 111}
142 112
143static ssize_t pyra_sysfs_read_profilex_buttons(struct file *fp, 113static ssize_t pyra_sysfs_write(struct file *fp, struct kobject *kobj,
144 struct kobject *kobj, struct bin_attribute *attr, char *buf, 114 void const *buf, loff_t off, size_t count,
145 loff_t off, size_t count) 115 size_t real_size, uint command)
146{ 116{
147 struct device *dev = 117 struct device *dev =
148 container_of(kobj, struct device, kobj)->parent->parent; 118 container_of(kobj, struct device, kobj)->parent->parent;
149 struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev)); 119 struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev));
120 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
121 int retval;
150 122
151 if (off >= sizeof(struct pyra_profile_buttons)) 123 if (off != 0 || count != real_size)
152 return 0; 124 return -EINVAL;
153
154 if (off + count > sizeof(struct pyra_profile_buttons))
155 count = sizeof(struct pyra_profile_buttons) - off;
156 125
157 mutex_lock(&pyra->pyra_lock); 126 mutex_lock(&pyra->pyra_lock);
158 memcpy(buf, ((char const *)&pyra->profile_buttons[*(uint *)(attr->private)]) + off, 127 retval = roccat_common2_send_with_status(usb_dev, command, (void *)buf, real_size);
159 count);
160 mutex_unlock(&pyra->pyra_lock); 128 mutex_unlock(&pyra->pyra_lock);
161 129
162 return count; 130 if (retval)
131 return retval;
132
133 return real_size;
163} 134}
164 135
165static ssize_t pyra_sysfs_write_profile_settings(struct file *fp, 136#define PYRA_SYSFS_W(thingy, THINGY) \
166 struct kobject *kobj, struct bin_attribute *attr, char *buf, 137static ssize_t pyra_sysfs_write_ ## thingy(struct file *fp, \
167 loff_t off, size_t count) 138 struct kobject *kobj, struct bin_attribute *attr, char *buf, \
168{ 139 loff_t off, size_t count) \
169 struct device *dev = 140{ \
170 container_of(kobj, struct device, kobj)->parent->parent; 141 return pyra_sysfs_write(fp, kobj, buf, off, count, \
171 struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev)); 142 PYRA_SIZE_ ## THINGY, PYRA_COMMAND_ ## THINGY); \
172 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); 143}
173 int retval = 0;
174 int difference;
175 int profile_number;
176 struct pyra_profile_settings *profile_settings;
177 144
178 if (off != 0 || count != sizeof(struct pyra_profile_settings)) 145#define PYRA_SYSFS_R(thingy, THINGY) \
179 return -EINVAL; 146static ssize_t pyra_sysfs_read_ ## thingy(struct file *fp, \
147 struct kobject *kobj, struct bin_attribute *attr, char *buf, \
148 loff_t off, size_t count) \
149{ \
150 return pyra_sysfs_read(fp, kobj, buf, off, count, \
151 PYRA_SIZE_ ## THINGY, PYRA_COMMAND_ ## THINGY); \
152}
180 153
181 profile_number = ((struct pyra_profile_settings const *)buf)->number; 154#define PYRA_SYSFS_RW(thingy, THINGY) \
182 profile_settings = &pyra->profile_settings[profile_number]; 155PYRA_SYSFS_W(thingy, THINGY) \
156PYRA_SYSFS_R(thingy, THINGY)
183 157
184 mutex_lock(&pyra->pyra_lock); 158#define PYRA_BIN_ATTRIBUTE_RW(thingy, THINGY) \
185 difference = memcmp(buf, profile_settings, 159{ \
186 sizeof(struct pyra_profile_settings)); 160 .attr = { .name = #thingy, .mode = 0660 }, \
187 if (difference) { 161 .size = PYRA_SIZE_ ## THINGY, \
188 retval = pyra_set_profile_settings(usb_dev, 162 .read = pyra_sysfs_read_ ## thingy, \
189 (struct pyra_profile_settings const *)buf); 163 .write = pyra_sysfs_write_ ## thingy \
190 if (!retval) 164}
191 memcpy(profile_settings, buf,
192 sizeof(struct pyra_profile_settings));
193 }
194 mutex_unlock(&pyra->pyra_lock);
195 165
196 if (retval) 166#define PYRA_BIN_ATTRIBUTE_R(thingy, THINGY) \
197 return retval; 167{ \
168 .attr = { .name = #thingy, .mode = 0440 }, \
169 .size = PYRA_SIZE_ ## THINGY, \
170 .read = pyra_sysfs_read_ ## thingy, \
171}
198 172
199 return sizeof(struct pyra_profile_settings); 173#define PYRA_BIN_ATTRIBUTE_W(thingy, THINGY) \
174{ \
175 .attr = { .name = #thingy, .mode = 0220 }, \
176 .size = PYRA_SIZE_ ## THINGY, \
177 .write = pyra_sysfs_write_ ## thingy \
200} 178}
201 179
202static ssize_t pyra_sysfs_write_profile_buttons(struct file *fp, 180PYRA_SYSFS_RW(info, INFO)
181PYRA_SYSFS_W(profile_settings, PROFILE_SETTINGS)
182PYRA_SYSFS_W(profile_buttons, PROFILE_BUTTONS)
183PYRA_SYSFS_R(settings, SETTINGS)
184
185static ssize_t pyra_sysfs_read_profilex_settings(struct file *fp,
203 struct kobject *kobj, struct bin_attribute *attr, char *buf, 186 struct kobject *kobj, struct bin_attribute *attr, char *buf,
204 loff_t off, size_t count) 187 loff_t off, size_t count)
205{ 188{
206 struct device *dev = 189 struct device *dev =
207 container_of(kobj, struct device, kobj)->parent->parent; 190 container_of(kobj, struct device, kobj)->parent->parent;
208 struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev));
209 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); 191 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
210 int retval = 0; 192 ssize_t retval;
211 int difference;
212 int profile_number;
213 struct pyra_profile_buttons *profile_buttons;
214
215 if (off != 0 || count != sizeof(struct pyra_profile_buttons))
216 return -EINVAL;
217
218 profile_number = ((struct pyra_profile_buttons const *)buf)->number;
219 profile_buttons = &pyra->profile_buttons[profile_number];
220
221 mutex_lock(&pyra->pyra_lock);
222 difference = memcmp(buf, profile_buttons,
223 sizeof(struct pyra_profile_buttons));
224 if (difference) {
225 retval = pyra_set_profile_buttons(usb_dev,
226 (struct pyra_profile_buttons const *)buf);
227 if (!retval)
228 memcpy(profile_buttons, buf,
229 sizeof(struct pyra_profile_buttons));
230 }
231 mutex_unlock(&pyra->pyra_lock);
232 193
194 retval = pyra_send_control(usb_dev, *(uint *)(attr->private),
195 PYRA_CONTROL_REQUEST_PROFILE_SETTINGS);
233 if (retval) 196 if (retval)
234 return retval; 197 return retval;
235 198
236 return sizeof(struct pyra_profile_buttons); 199 return pyra_sysfs_read(fp, kobj, buf, off, count,
200 PYRA_SIZE_PROFILE_SETTINGS,
201 PYRA_COMMAND_PROFILE_SETTINGS);
237} 202}
238 203
239static ssize_t pyra_sysfs_read_settings(struct file *fp, 204static ssize_t pyra_sysfs_read_profilex_buttons(struct file *fp,
240 struct kobject *kobj, struct bin_attribute *attr, char *buf, 205 struct kobject *kobj, struct bin_attribute *attr, char *buf,
241 loff_t off, size_t count) 206 loff_t off, size_t count)
242{ 207{
243 struct device *dev = 208 struct device *dev =
244 container_of(kobj, struct device, kobj)->parent->parent; 209 container_of(kobj, struct device, kobj)->parent->parent;
245 struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev)); 210 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
246 211 ssize_t retval;
247 if (off >= sizeof(struct pyra_settings))
248 return 0;
249
250 if (off + count > sizeof(struct pyra_settings))
251 count = sizeof(struct pyra_settings) - off;
252 212
253 mutex_lock(&pyra->pyra_lock); 213 retval = pyra_send_control(usb_dev, *(uint *)(attr->private),
254 memcpy(buf, ((char const *)&pyra->settings) + off, count); 214 PYRA_CONTROL_REQUEST_PROFILE_BUTTONS);
255 mutex_unlock(&pyra->pyra_lock); 215 if (retval)
216 return retval;
256 217
257 return count; 218 return pyra_sysfs_read(fp, kobj, buf, off, count,
219 PYRA_SIZE_PROFILE_BUTTONS,
220 PYRA_COMMAND_PROFILE_BUTTONS);
258} 221}
259 222
260static ssize_t pyra_sysfs_write_settings(struct file *fp, 223static ssize_t pyra_sysfs_write_settings(struct file *fp,
@@ -266,35 +229,32 @@ static ssize_t pyra_sysfs_write_settings(struct file *fp,
266 struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev)); 229 struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev));
267 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); 230 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
268 int retval = 0; 231 int retval = 0;
269 int difference;
270 struct pyra_roccat_report roccat_report; 232 struct pyra_roccat_report roccat_report;
233 struct pyra_settings const *settings;
271 234
272 if (off != 0 || count != sizeof(struct pyra_settings)) 235 if (off != 0 || count != PYRA_SIZE_SETTINGS)
273 return -EINVAL; 236 return -EINVAL;
274 237
275 mutex_lock(&pyra->pyra_lock); 238 mutex_lock(&pyra->pyra_lock);
276 difference = memcmp(buf, &pyra->settings, sizeof(struct pyra_settings));
277 if (difference) {
278 retval = pyra_set_settings(usb_dev,
279 (struct pyra_settings const *)buf);
280 if (retval) {
281 mutex_unlock(&pyra->pyra_lock);
282 return retval;
283 }
284
285 memcpy(&pyra->settings, buf,
286 sizeof(struct pyra_settings));
287 239
288 profile_activated(pyra, pyra->settings.startup_profile); 240 settings = (struct pyra_settings const *)buf;
289 241
290 roccat_report.type = PYRA_MOUSE_EVENT_BUTTON_TYPE_PROFILE_2; 242 retval = pyra_set_settings(usb_dev, settings);
291 roccat_report.value = pyra->settings.startup_profile + 1; 243 if (retval) {
292 roccat_report.key = 0; 244 mutex_unlock(&pyra->pyra_lock);
293 roccat_report_event(pyra->chrdev_minor, 245 return retval;
294 (uint8_t const *)&roccat_report);
295 } 246 }
247
248 profile_activated(pyra, settings->startup_profile);
249
250 roccat_report.type = PYRA_MOUSE_EVENT_BUTTON_TYPE_PROFILE_2;
251 roccat_report.value = settings->startup_profile + 1;
252 roccat_report.key = 0;
253 roccat_report_event(pyra->chrdev_minor,
254 (uint8_t const *)&roccat_report);
255
296 mutex_unlock(&pyra->pyra_lock); 256 mutex_unlock(&pyra->pyra_lock);
297 return sizeof(struct pyra_settings); 257 return PYRA_SIZE_SETTINGS;
298} 258}
299 259
300 260
@@ -311,23 +271,34 @@ static ssize_t pyra_sysfs_show_actual_profile(struct device *dev,
311{ 271{
312 struct pyra_device *pyra = 272 struct pyra_device *pyra =
313 hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); 273 hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
314 return snprintf(buf, PAGE_SIZE, "%d\n", pyra->actual_profile); 274 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
275 struct pyra_settings settings;
276
277 mutex_lock(&pyra->pyra_lock);
278 roccat_common2_receive(usb_dev, PYRA_COMMAND_SETTINGS,
279 &settings, PYRA_SIZE_SETTINGS);
280 mutex_unlock(&pyra->pyra_lock);
281
282 return snprintf(buf, PAGE_SIZE, "%d\n", settings.startup_profile);
315} 283}
316 284
317static ssize_t pyra_sysfs_show_firmware_version(struct device *dev, 285static ssize_t pyra_sysfs_show_firmware_version(struct device *dev,
318 struct device_attribute *attr, char *buf) 286 struct device_attribute *attr, char *buf)
319{ 287{
320 struct pyra_device *pyra = 288 struct pyra_device *pyra;
321 hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); 289 struct usb_device *usb_dev;
322 return snprintf(buf, PAGE_SIZE, "%d\n", pyra->firmware_version); 290 struct pyra_info info;
323}
324 291
325static ssize_t pyra_sysfs_show_startup_profile(struct device *dev, 292 dev = dev->parent->parent;
326 struct device_attribute *attr, char *buf) 293 pyra = hid_get_drvdata(dev_get_drvdata(dev));
327{ 294 usb_dev = interface_to_usbdev(to_usb_interface(dev));
328 struct pyra_device *pyra = 295
329 hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); 296 mutex_lock(&pyra->pyra_lock);
330 return snprintf(buf, PAGE_SIZE, "%d\n", pyra->settings.startup_profile); 297 roccat_common2_receive(usb_dev, PYRA_COMMAND_INFO,
298 &info, PYRA_SIZE_INFO);
299 mutex_unlock(&pyra->pyra_lock);
300
301 return snprintf(buf, PAGE_SIZE, "%d\n", info.firmware_version);
331} 302}
332 303
333static struct device_attribute pyra_attributes[] = { 304static struct device_attribute pyra_attributes[] = {
@@ -336,105 +307,87 @@ static struct device_attribute pyra_attributes[] = {
336 __ATTR(firmware_version, 0440, 307 __ATTR(firmware_version, 0440,
337 pyra_sysfs_show_firmware_version, NULL), 308 pyra_sysfs_show_firmware_version, NULL),
338 __ATTR(startup_profile, 0440, 309 __ATTR(startup_profile, 0440,
339 pyra_sysfs_show_startup_profile, NULL), 310 pyra_sysfs_show_actual_profile, NULL),
340 __ATTR_NULL 311 __ATTR_NULL
341}; 312};
342 313
343static struct bin_attribute pyra_bin_attributes[] = { 314static struct bin_attribute pyra_bin_attributes[] = {
344 { 315 PYRA_BIN_ATTRIBUTE_RW(info, INFO),
345 .attr = { .name = "profile_settings", .mode = 0220 }, 316 PYRA_BIN_ATTRIBUTE_W(profile_settings, PROFILE_SETTINGS),
346 .size = sizeof(struct pyra_profile_settings), 317 PYRA_BIN_ATTRIBUTE_W(profile_buttons, PROFILE_BUTTONS),
347 .write = pyra_sysfs_write_profile_settings 318 PYRA_BIN_ATTRIBUTE_RW(settings, SETTINGS),
348 },
349 { 319 {
350 .attr = { .name = "profile1_settings", .mode = 0440 }, 320 .attr = { .name = "profile1_settings", .mode = 0440 },
351 .size = sizeof(struct pyra_profile_settings), 321 .size = PYRA_SIZE_PROFILE_SETTINGS,
352 .read = pyra_sysfs_read_profilex_settings, 322 .read = pyra_sysfs_read_profilex_settings,
353 .private = &profile_numbers[0] 323 .private = &profile_numbers[0]
354 }, 324 },
355 { 325 {
356 .attr = { .name = "profile2_settings", .mode = 0440 }, 326 .attr = { .name = "profile2_settings", .mode = 0440 },
357 .size = sizeof(struct pyra_profile_settings), 327 .size = PYRA_SIZE_PROFILE_SETTINGS,
358 .read = pyra_sysfs_read_profilex_settings, 328 .read = pyra_sysfs_read_profilex_settings,
359 .private = &profile_numbers[1] 329 .private = &profile_numbers[1]
360 }, 330 },
361 { 331 {
362 .attr = { .name = "profile3_settings", .mode = 0440 }, 332 .attr = { .name = "profile3_settings", .mode = 0440 },
363 .size = sizeof(struct pyra_profile_settings), 333 .size = PYRA_SIZE_PROFILE_SETTINGS,
364 .read = pyra_sysfs_read_profilex_settings, 334 .read = pyra_sysfs_read_profilex_settings,
365 .private = &profile_numbers[2] 335 .private = &profile_numbers[2]
366 }, 336 },
367 { 337 {
368 .attr = { .name = "profile4_settings", .mode = 0440 }, 338 .attr = { .name = "profile4_settings", .mode = 0440 },
369 .size = sizeof(struct pyra_profile_settings), 339 .size = PYRA_SIZE_PROFILE_SETTINGS,
370 .read = pyra_sysfs_read_profilex_settings, 340 .read = pyra_sysfs_read_profilex_settings,
371 .private = &profile_numbers[3] 341 .private = &profile_numbers[3]
372 }, 342 },
373 { 343 {
374 .attr = { .name = "profile5_settings", .mode = 0440 }, 344 .attr = { .name = "profile5_settings", .mode = 0440 },
375 .size = sizeof(struct pyra_profile_settings), 345 .size = PYRA_SIZE_PROFILE_SETTINGS,
376 .read = pyra_sysfs_read_profilex_settings, 346 .read = pyra_sysfs_read_profilex_settings,
377 .private = &profile_numbers[4] 347 .private = &profile_numbers[4]
378 }, 348 },
379 { 349 {
380 .attr = { .name = "profile_buttons", .mode = 0220 },
381 .size = sizeof(struct pyra_profile_buttons),
382 .write = pyra_sysfs_write_profile_buttons
383 },
384 {
385 .attr = { .name = "profile1_buttons", .mode = 0440 }, 350 .attr = { .name = "profile1_buttons", .mode = 0440 },
386 .size = sizeof(struct pyra_profile_buttons), 351 .size = PYRA_SIZE_PROFILE_BUTTONS,
387 .read = pyra_sysfs_read_profilex_buttons, 352 .read = pyra_sysfs_read_profilex_buttons,
388 .private = &profile_numbers[0] 353 .private = &profile_numbers[0]
389 }, 354 },
390 { 355 {
391 .attr = { .name = "profile2_buttons", .mode = 0440 }, 356 .attr = { .name = "profile2_buttons", .mode = 0440 },
392 .size = sizeof(struct pyra_profile_buttons), 357 .size = PYRA_SIZE_PROFILE_BUTTONS,
393 .read = pyra_sysfs_read_profilex_buttons, 358 .read = pyra_sysfs_read_profilex_buttons,
394 .private = &profile_numbers[1] 359 .private = &profile_numbers[1]
395 }, 360 },
396 { 361 {
397 .attr = { .name = "profile3_buttons", .mode = 0440 }, 362 .attr = { .name = "profile3_buttons", .mode = 0440 },
398 .size = sizeof(struct pyra_profile_buttons), 363 .size = PYRA_SIZE_PROFILE_BUTTONS,
399 .read = pyra_sysfs_read_profilex_buttons, 364 .read = pyra_sysfs_read_profilex_buttons,
400 .private = &profile_numbers[2] 365 .private = &profile_numbers[2]
401 }, 366 },
402 { 367 {
403 .attr = { .name = "profile4_buttons", .mode = 0440 }, 368 .attr = { .name = "profile4_buttons", .mode = 0440 },
404 .size = sizeof(struct pyra_profile_buttons), 369 .size = PYRA_SIZE_PROFILE_BUTTONS,
405 .read = pyra_sysfs_read_profilex_buttons, 370 .read = pyra_sysfs_read_profilex_buttons,
406 .private = &profile_numbers[3] 371 .private = &profile_numbers[3]
407 }, 372 },
408 { 373 {
409 .attr = { .name = "profile5_buttons", .mode = 0440 }, 374 .attr = { .name = "profile5_buttons", .mode = 0440 },
410 .size = sizeof(struct pyra_profile_buttons), 375 .size = PYRA_SIZE_PROFILE_BUTTONS,
411 .read = pyra_sysfs_read_profilex_buttons, 376 .read = pyra_sysfs_read_profilex_buttons,
412 .private = &profile_numbers[4] 377 .private = &profile_numbers[4]
413 }, 378 },
414 {
415 .attr = { .name = "settings", .mode = 0660 },
416 .size = sizeof(struct pyra_settings),
417 .read = pyra_sysfs_read_settings,
418 .write = pyra_sysfs_write_settings
419 },
420 __ATTR_NULL 379 __ATTR_NULL
421}; 380};
422 381
423static int pyra_init_pyra_device_struct(struct usb_device *usb_dev, 382static int pyra_init_pyra_device_struct(struct usb_device *usb_dev,
424 struct pyra_device *pyra) 383 struct pyra_device *pyra)
425{ 384{
426 struct pyra_info info; 385 struct pyra_settings settings;
427 int retval, i; 386 int retval, i;
428 387
429 mutex_init(&pyra->pyra_lock); 388 mutex_init(&pyra->pyra_lock);
430 389
431 retval = pyra_get_info(usb_dev, &info); 390 retval = pyra_get_settings(usb_dev, &settings);
432 if (retval)
433 return retval;
434
435 pyra->firmware_version = info.firmware_version;
436
437 retval = pyra_get_settings(usb_dev, &pyra->settings);
438 if (retval) 391 if (retval)
439 return retval; 392 return retval;
440 393
@@ -443,14 +396,9 @@ static int pyra_init_pyra_device_struct(struct usb_device *usb_dev,
443 &pyra->profile_settings[i], i); 396 &pyra->profile_settings[i], i);
444 if (retval) 397 if (retval)
445 return retval; 398 return retval;
446
447 retval = pyra_get_profile_buttons(usb_dev,
448 &pyra->profile_buttons[i], i);
449 if (retval)
450 return retval;
451 } 399 }
452 400
453 profile_activated(pyra, pyra->settings.startup_profile); 401 profile_activated(pyra, settings.startup_profile);
454 402
455 return 0; 403 return 0;
456} 404}
diff --git a/drivers/hid/hid-roccat-pyra.h b/drivers/hid/hid-roccat-pyra.h
index eada7830fa99..93e494984976 100644
--- a/drivers/hid/hid-roccat-pyra.h
+++ b/drivers/hid/hid-roccat-pyra.h
@@ -14,11 +14,12 @@
14 14
15#include <linux/types.h> 15#include <linux/types.h>
16 16
17struct pyra_b { 17enum {
18 uint8_t command; /* PYRA_COMMAND_B */ 18 PYRA_SIZE_INFO = 0x06,
19 uint8_t size; /* always 3 */ 19 PYRA_SIZE_PROFILE_SETTINGS = 0x0d,
20 uint8_t unknown; /* 1 */ 20 PYRA_SIZE_PROFILE_BUTTONS = 0x13,
21} __attribute__ ((__packed__)); 21 PYRA_SIZE_SETTINGS = 0x03,
22};
22 23
23enum pyra_control_requests { 24enum pyra_control_requests {
24 PYRA_CONTROL_REQUEST_PROFILE_SETTINGS = 0x10, 25 PYRA_CONTROL_REQUEST_PROFILE_SETTINGS = 0x10,
@@ -46,14 +47,6 @@ struct pyra_profile_settings {
46 uint16_t checksum; /* byte sum */ 47 uint16_t checksum; /* byte sum */
47} __attribute__ ((__packed__)); 48} __attribute__ ((__packed__));
48 49
49struct pyra_profile_buttons {
50 uint8_t command; /* PYRA_COMMAND_PROFILE_BUTTONS */
51 uint8_t size; /* always 0x13 */
52 uint8_t number; /* Range 0-4 */
53 uint8_t buttons[14];
54 uint16_t checksum; /* byte sum */
55} __attribute__ ((__packed__));
56
57struct pyra_info { 50struct pyra_info {
58 uint8_t command; /* PYRA_COMMAND_INFO */ 51 uint8_t command; /* PYRA_COMMAND_INFO */
59 uint8_t size; /* always 6 */ 52 uint8_t size; /* always 6 */
@@ -148,13 +141,10 @@ struct pyra_roccat_report {
148struct pyra_device { 141struct pyra_device {
149 int actual_profile; 142 int actual_profile;
150 int actual_cpi; 143 int actual_cpi;
151 int firmware_version;
152 int roccat_claimed; 144 int roccat_claimed;
153 int chrdev_minor; 145 int chrdev_minor;
154 struct mutex pyra_lock; 146 struct mutex pyra_lock;
155 struct pyra_settings settings;
156 struct pyra_profile_settings profile_settings[5]; 147 struct pyra_profile_settings profile_settings[5];
157 struct pyra_profile_buttons profile_buttons[5];
158}; 148};
159 149
160#endif 150#endif