drm/i915: tune Sandy Bridge DRPS constants
[linux/fpc-iii.git] / drivers / hid / hid-roccat-pyra.c
blob02c58e015bee953a03ed5a7b8f48666e53dcec39
1 /*
2 * Roccat Pyra driver for Linux
4 * Copyright (c) 2010 Stefan Achatz <erazor_de@users.sourceforge.net>
5 */
7 /*
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
11 * any later version.
15 * Roccat Pyra is a mobile gamer mouse which comes in wired and wireless
16 * variant. Wireless variant is not tested.
17 * Userland tools can be found at http://sourceforge.net/projects/roccat
20 #include <linux/device.h>
21 #include <linux/input.h>
22 #include <linux/hid.h>
23 #include <linux/usb.h>
24 #include <linux/module.h>
25 #include <linux/slab.h>
26 #include "hid-ids.h"
27 #include "hid-roccat.h"
28 #include "hid-roccat-pyra.h"
30 static uint profile_numbers[5] = {0, 1, 2, 3, 4};
32 /* pyra_class is used for creating sysfs attributes via roccat char device */
33 static struct class *pyra_class;
35 static void profile_activated(struct pyra_device *pyra,
36 unsigned int new_profile)
38 pyra->actual_profile = new_profile;
39 pyra->actual_cpi = pyra->profile_settings[pyra->actual_profile].y_cpi;
42 static int pyra_send_control(struct usb_device *usb_dev, int value,
43 enum pyra_control_requests request)
45 int len;
46 struct pyra_control control;
48 if ((request == PYRA_CONTROL_REQUEST_PROFILE_SETTINGS ||
49 request == PYRA_CONTROL_REQUEST_PROFILE_BUTTONS) &&
50 (value < 0 || value > 4))
51 return -EINVAL;
53 control.command = PYRA_COMMAND_CONTROL;
54 control.value = value;
55 control.request = request;
57 len = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
58 USB_REQ_SET_CONFIGURATION,
59 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
60 PYRA_USB_COMMAND_CONTROL, 0, (char *)&control,
61 sizeof(struct pyra_control),
62 USB_CTRL_SET_TIMEOUT);
64 if (len != sizeof(struct pyra_control))
65 return len;
67 return 0;
70 static int pyra_receive_control_status(struct usb_device *usb_dev)
72 int len;
73 struct pyra_control control;
75 do {
76 msleep(10);
78 len = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
79 USB_REQ_CLEAR_FEATURE,
80 USB_TYPE_CLASS | USB_RECIP_INTERFACE |
81 USB_DIR_IN,
82 PYRA_USB_COMMAND_CONTROL, 0, (char *)&control,
83 sizeof(struct pyra_control),
84 USB_CTRL_SET_TIMEOUT);
86 /* requested too early, try again */
87 } while (len == -EPROTO);
89 if (len == sizeof(struct pyra_control) &&
90 control.command == PYRA_COMMAND_CONTROL &&
91 control.request == PYRA_CONTROL_REQUEST_STATUS &&
92 control.value == 1)
93 return 0;
94 else {
95 hid_err(usb_dev, "receive control status: unknown response 0x%x 0x%x\n",
96 control.request, control.value);
97 return -EINVAL;
101 static int pyra_get_profile_settings(struct usb_device *usb_dev,
102 struct pyra_profile_settings *buf, int number)
104 int retval;
106 retval = pyra_send_control(usb_dev, number,
107 PYRA_CONTROL_REQUEST_PROFILE_SETTINGS);
109 if (retval)
110 return retval;
112 retval = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
113 USB_REQ_CLEAR_FEATURE,
114 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
115 PYRA_USB_COMMAND_PROFILE_SETTINGS, 0, (char *)buf,
116 sizeof(struct pyra_profile_settings),
117 USB_CTRL_SET_TIMEOUT);
119 if (retval != sizeof(struct pyra_profile_settings))
120 return retval;
122 return 0;
125 static int pyra_get_profile_buttons(struct usb_device *usb_dev,
126 struct pyra_profile_buttons *buf, int number)
128 int retval;
130 retval = pyra_send_control(usb_dev, number,
131 PYRA_CONTROL_REQUEST_PROFILE_BUTTONS);
133 if (retval)
134 return retval;
136 retval = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
137 USB_REQ_CLEAR_FEATURE,
138 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
139 PYRA_USB_COMMAND_PROFILE_BUTTONS, 0, (char *)buf,
140 sizeof(struct pyra_profile_buttons),
141 USB_CTRL_SET_TIMEOUT);
143 if (retval != sizeof(struct pyra_profile_buttons))
144 return retval;
146 return 0;
149 static int pyra_get_settings(struct usb_device *usb_dev,
150 struct pyra_settings *buf)
152 int len;
153 len = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
154 USB_REQ_CLEAR_FEATURE,
155 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
156 PYRA_USB_COMMAND_SETTINGS, 0, buf,
157 sizeof(struct pyra_settings), USB_CTRL_SET_TIMEOUT);
158 if (len != sizeof(struct pyra_settings))
159 return -EIO;
160 return 0;
163 static int pyra_get_info(struct usb_device *usb_dev, struct pyra_info *buf)
165 int len;
166 len = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
167 USB_REQ_CLEAR_FEATURE,
168 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
169 PYRA_USB_COMMAND_INFO, 0, buf,
170 sizeof(struct pyra_info), USB_CTRL_SET_TIMEOUT);
171 if (len != sizeof(struct pyra_info))
172 return -EIO;
173 return 0;
176 static int pyra_set_profile_settings(struct usb_device *usb_dev,
177 struct pyra_profile_settings const *settings)
179 int len;
180 len = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
181 USB_REQ_SET_CONFIGURATION,
182 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
183 PYRA_USB_COMMAND_PROFILE_SETTINGS, 0, (char *)settings,
184 sizeof(struct pyra_profile_settings),
185 USB_CTRL_SET_TIMEOUT);
186 if (len != sizeof(struct pyra_profile_settings))
187 return -EIO;
188 if (pyra_receive_control_status(usb_dev))
189 return -EIO;
190 return 0;
193 static int pyra_set_profile_buttons(struct usb_device *usb_dev,
194 struct pyra_profile_buttons const *buttons)
196 int len;
197 len = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
198 USB_REQ_SET_CONFIGURATION,
199 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
200 PYRA_USB_COMMAND_PROFILE_BUTTONS, 0, (char *)buttons,
201 sizeof(struct pyra_profile_buttons),
202 USB_CTRL_SET_TIMEOUT);
203 if (len != sizeof(struct pyra_profile_buttons))
204 return -EIO;
205 if (pyra_receive_control_status(usb_dev))
206 return -EIO;
207 return 0;
210 static int pyra_set_settings(struct usb_device *usb_dev,
211 struct pyra_settings const *settings)
213 int len;
214 len = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
215 USB_REQ_SET_CONFIGURATION,
216 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
217 PYRA_USB_COMMAND_SETTINGS, 0, (char *)settings,
218 sizeof(struct pyra_settings), USB_CTRL_SET_TIMEOUT);
219 if (len != sizeof(struct pyra_settings))
220 return -EIO;
221 if (pyra_receive_control_status(usb_dev))
222 return -EIO;
223 return 0;
226 static ssize_t pyra_sysfs_read_profilex_settings(struct file *fp,
227 struct kobject *kobj, struct bin_attribute *attr, char *buf,
228 loff_t off, size_t count)
230 struct device *dev =
231 container_of(kobj, struct device, kobj)->parent->parent;
232 struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev));
234 if (off >= sizeof(struct pyra_profile_settings))
235 return 0;
237 if (off + count > sizeof(struct pyra_profile_settings))
238 count = sizeof(struct pyra_profile_settings) - off;
240 mutex_lock(&pyra->pyra_lock);
241 memcpy(buf, ((char const *)&pyra->profile_settings[*(uint *)(attr->private)]) + off,
242 count);
243 mutex_unlock(&pyra->pyra_lock);
245 return count;
248 static ssize_t pyra_sysfs_read_profilex_buttons(struct file *fp,
249 struct kobject *kobj, struct bin_attribute *attr, char *buf,
250 loff_t off, size_t count)
252 struct device *dev =
253 container_of(kobj, struct device, kobj)->parent->parent;
254 struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev));
256 if (off >= sizeof(struct pyra_profile_buttons))
257 return 0;
259 if (off + count > sizeof(struct pyra_profile_buttons))
260 count = sizeof(struct pyra_profile_buttons) - off;
262 mutex_lock(&pyra->pyra_lock);
263 memcpy(buf, ((char const *)&pyra->profile_buttons[*(uint *)(attr->private)]) + off,
264 count);
265 mutex_unlock(&pyra->pyra_lock);
267 return count;
270 static ssize_t pyra_sysfs_write_profile_settings(struct file *fp,
271 struct kobject *kobj, struct bin_attribute *attr, char *buf,
272 loff_t off, size_t count)
274 struct device *dev =
275 container_of(kobj, struct device, kobj)->parent->parent;
276 struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev));
277 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
278 int retval = 0;
279 int difference;
280 int profile_number;
281 struct pyra_profile_settings *profile_settings;
283 if (off != 0 || count != sizeof(struct pyra_profile_settings))
284 return -EINVAL;
286 profile_number = ((struct pyra_profile_settings const *)buf)->number;
287 profile_settings = &pyra->profile_settings[profile_number];
289 mutex_lock(&pyra->pyra_lock);
290 difference = memcmp(buf, profile_settings,
291 sizeof(struct pyra_profile_settings));
292 if (difference) {
293 retval = pyra_set_profile_settings(usb_dev,
294 (struct pyra_profile_settings const *)buf);
295 if (!retval)
296 memcpy(profile_settings, buf,
297 sizeof(struct pyra_profile_settings));
299 mutex_unlock(&pyra->pyra_lock);
301 if (retval)
302 return retval;
304 return sizeof(struct pyra_profile_settings);
307 static ssize_t pyra_sysfs_write_profile_buttons(struct file *fp,
308 struct kobject *kobj, struct bin_attribute *attr, char *buf,
309 loff_t off, size_t count)
311 struct device *dev =
312 container_of(kobj, struct device, kobj)->parent->parent;
313 struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev));
314 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
315 int retval = 0;
316 int difference;
317 int profile_number;
318 struct pyra_profile_buttons *profile_buttons;
320 if (off != 0 || count != sizeof(struct pyra_profile_buttons))
321 return -EINVAL;
323 profile_number = ((struct pyra_profile_buttons const *)buf)->number;
324 profile_buttons = &pyra->profile_buttons[profile_number];
326 mutex_lock(&pyra->pyra_lock);
327 difference = memcmp(buf, profile_buttons,
328 sizeof(struct pyra_profile_buttons));
329 if (difference) {
330 retval = pyra_set_profile_buttons(usb_dev,
331 (struct pyra_profile_buttons const *)buf);
332 if (!retval)
333 memcpy(profile_buttons, buf,
334 sizeof(struct pyra_profile_buttons));
336 mutex_unlock(&pyra->pyra_lock);
338 if (retval)
339 return retval;
341 return sizeof(struct pyra_profile_buttons);
344 static ssize_t pyra_sysfs_read_settings(struct file *fp,
345 struct kobject *kobj, struct bin_attribute *attr, char *buf,
346 loff_t off, size_t count)
348 struct device *dev =
349 container_of(kobj, struct device, kobj)->parent->parent;
350 struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev));
352 if (off >= sizeof(struct pyra_settings))
353 return 0;
355 if (off + count > sizeof(struct pyra_settings))
356 count = sizeof(struct pyra_settings) - off;
358 mutex_lock(&pyra->pyra_lock);
359 memcpy(buf, ((char const *)&pyra->settings) + off, count);
360 mutex_unlock(&pyra->pyra_lock);
362 return count;
365 static ssize_t pyra_sysfs_write_settings(struct file *fp,
366 struct kobject *kobj, struct bin_attribute *attr, char *buf,
367 loff_t off, size_t count)
369 struct device *dev =
370 container_of(kobj, struct device, kobj)->parent->parent;
371 struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev));
372 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
373 int retval = 0;
374 int difference;
376 if (off != 0 || count != sizeof(struct pyra_settings))
377 return -EINVAL;
379 mutex_lock(&pyra->pyra_lock);
380 difference = memcmp(buf, &pyra->settings, sizeof(struct pyra_settings));
381 if (difference) {
382 retval = pyra_set_settings(usb_dev,
383 (struct pyra_settings const *)buf);
384 if (!retval)
385 memcpy(&pyra->settings, buf,
386 sizeof(struct pyra_settings));
388 mutex_unlock(&pyra->pyra_lock);
390 if (retval)
391 return retval;
393 profile_activated(pyra, pyra->settings.startup_profile);
395 return sizeof(struct pyra_settings);
399 static ssize_t pyra_sysfs_show_actual_cpi(struct device *dev,
400 struct device_attribute *attr, char *buf)
402 struct pyra_device *pyra =
403 hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
404 return snprintf(buf, PAGE_SIZE, "%d\n", pyra->actual_cpi);
407 static ssize_t pyra_sysfs_show_actual_profile(struct device *dev,
408 struct device_attribute *attr, char *buf)
410 struct pyra_device *pyra =
411 hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
412 return snprintf(buf, PAGE_SIZE, "%d\n", pyra->actual_profile);
415 static ssize_t pyra_sysfs_show_firmware_version(struct device *dev,
416 struct device_attribute *attr, char *buf)
418 struct pyra_device *pyra =
419 hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
420 return snprintf(buf, PAGE_SIZE, "%d\n", pyra->firmware_version);
423 static ssize_t pyra_sysfs_show_startup_profile(struct device *dev,
424 struct device_attribute *attr, char *buf)
426 struct pyra_device *pyra =
427 hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
428 return snprintf(buf, PAGE_SIZE, "%d\n", pyra->settings.startup_profile);
431 static struct device_attribute pyra_attributes[] = {
432 __ATTR(actual_cpi, 0440, pyra_sysfs_show_actual_cpi, NULL),
433 __ATTR(actual_profile, 0440, pyra_sysfs_show_actual_profile, NULL),
434 __ATTR(firmware_version, 0440,
435 pyra_sysfs_show_firmware_version, NULL),
436 __ATTR(startup_profile, 0440,
437 pyra_sysfs_show_startup_profile, NULL),
438 __ATTR_NULL
441 static struct bin_attribute pyra_bin_attributes[] = {
443 .attr = { .name = "profile_settings", .mode = 0220 },
444 .size = sizeof(struct pyra_profile_settings),
445 .write = pyra_sysfs_write_profile_settings
448 .attr = { .name = "profile1_settings", .mode = 0440 },
449 .size = sizeof(struct pyra_profile_settings),
450 .read = pyra_sysfs_read_profilex_settings,
451 .private = &profile_numbers[0]
454 .attr = { .name = "profile2_settings", .mode = 0440 },
455 .size = sizeof(struct pyra_profile_settings),
456 .read = pyra_sysfs_read_profilex_settings,
457 .private = &profile_numbers[1]
460 .attr = { .name = "profile3_settings", .mode = 0440 },
461 .size = sizeof(struct pyra_profile_settings),
462 .read = pyra_sysfs_read_profilex_settings,
463 .private = &profile_numbers[2]
466 .attr = { .name = "profile4_settings", .mode = 0440 },
467 .size = sizeof(struct pyra_profile_settings),
468 .read = pyra_sysfs_read_profilex_settings,
469 .private = &profile_numbers[3]
472 .attr = { .name = "profile5_settings", .mode = 0440 },
473 .size = sizeof(struct pyra_profile_settings),
474 .read = pyra_sysfs_read_profilex_settings,
475 .private = &profile_numbers[4]
478 .attr = { .name = "profile_buttons", .mode = 0220 },
479 .size = sizeof(struct pyra_profile_buttons),
480 .write = pyra_sysfs_write_profile_buttons
483 .attr = { .name = "profile1_buttons", .mode = 0440 },
484 .size = sizeof(struct pyra_profile_buttons),
485 .read = pyra_sysfs_read_profilex_buttons,
486 .private = &profile_numbers[0]
489 .attr = { .name = "profile2_buttons", .mode = 0440 },
490 .size = sizeof(struct pyra_profile_buttons),
491 .read = pyra_sysfs_read_profilex_buttons,
492 .private = &profile_numbers[1]
495 .attr = { .name = "profile3_buttons", .mode = 0440 },
496 .size = sizeof(struct pyra_profile_buttons),
497 .read = pyra_sysfs_read_profilex_buttons,
498 .private = &profile_numbers[2]
501 .attr = { .name = "profile4_buttons", .mode = 0440 },
502 .size = sizeof(struct pyra_profile_buttons),
503 .read = pyra_sysfs_read_profilex_buttons,
504 .private = &profile_numbers[3]
507 .attr = { .name = "profile5_buttons", .mode = 0440 },
508 .size = sizeof(struct pyra_profile_buttons),
509 .read = pyra_sysfs_read_profilex_buttons,
510 .private = &profile_numbers[4]
513 .attr = { .name = "settings", .mode = 0660 },
514 .size = sizeof(struct pyra_settings),
515 .read = pyra_sysfs_read_settings,
516 .write = pyra_sysfs_write_settings
518 __ATTR_NULL
521 static int pyra_init_pyra_device_struct(struct usb_device *usb_dev,
522 struct pyra_device *pyra)
524 struct pyra_info *info;
525 int retval, i;
527 mutex_init(&pyra->pyra_lock);
529 info = kmalloc(sizeof(struct pyra_info), GFP_KERNEL);
530 if (!info)
531 return -ENOMEM;
532 retval = pyra_get_info(usb_dev, info);
533 if (retval) {
534 kfree(info);
535 return retval;
537 pyra->firmware_version = info->firmware_version;
538 kfree(info);
540 retval = pyra_get_settings(usb_dev, &pyra->settings);
541 if (retval)
542 return retval;
544 for (i = 0; i < 5; ++i) {
545 retval = pyra_get_profile_settings(usb_dev,
546 &pyra->profile_settings[i], i);
547 if (retval)
548 return retval;
550 retval = pyra_get_profile_buttons(usb_dev,
551 &pyra->profile_buttons[i], i);
552 if (retval)
553 return retval;
556 profile_activated(pyra, pyra->settings.startup_profile);
558 return 0;
561 static int pyra_init_specials(struct hid_device *hdev)
563 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
564 struct usb_device *usb_dev = interface_to_usbdev(intf);
565 struct pyra_device *pyra;
566 int retval;
568 if (intf->cur_altsetting->desc.bInterfaceProtocol
569 == USB_INTERFACE_PROTOCOL_MOUSE) {
571 pyra = kzalloc(sizeof(*pyra), GFP_KERNEL);
572 if (!pyra) {
573 hid_err(hdev, "can't alloc device descriptor\n");
574 return -ENOMEM;
576 hid_set_drvdata(hdev, pyra);
578 retval = pyra_init_pyra_device_struct(usb_dev, pyra);
579 if (retval) {
580 hid_err(hdev, "couldn't init struct pyra_device\n");
581 goto exit_free;
584 retval = roccat_connect(pyra_class, hdev);
585 if (retval < 0) {
586 hid_err(hdev, "couldn't init char dev\n");
587 } else {
588 pyra->chrdev_minor = retval;
589 pyra->roccat_claimed = 1;
591 } else {
592 hid_set_drvdata(hdev, NULL);
595 return 0;
596 exit_free:
597 kfree(pyra);
598 return retval;
601 static void pyra_remove_specials(struct hid_device *hdev)
603 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
604 struct pyra_device *pyra;
606 if (intf->cur_altsetting->desc.bInterfaceProtocol
607 == USB_INTERFACE_PROTOCOL_MOUSE) {
608 pyra = hid_get_drvdata(hdev);
609 if (pyra->roccat_claimed)
610 roccat_disconnect(pyra->chrdev_minor);
611 kfree(hid_get_drvdata(hdev));
615 static int pyra_probe(struct hid_device *hdev, const struct hid_device_id *id)
617 int retval;
619 retval = hid_parse(hdev);
620 if (retval) {
621 hid_err(hdev, "parse failed\n");
622 goto exit;
625 retval = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
626 if (retval) {
627 hid_err(hdev, "hw start failed\n");
628 goto exit;
631 retval = pyra_init_specials(hdev);
632 if (retval) {
633 hid_err(hdev, "couldn't install mouse\n");
634 goto exit_stop;
636 return 0;
638 exit_stop:
639 hid_hw_stop(hdev);
640 exit:
641 return retval;
644 static void pyra_remove(struct hid_device *hdev)
646 pyra_remove_specials(hdev);
647 hid_hw_stop(hdev);
650 static void pyra_keep_values_up_to_date(struct pyra_device *pyra,
651 u8 const *data)
653 struct pyra_mouse_event_button const *button_event;
655 switch (data[0]) {
656 case PYRA_MOUSE_REPORT_NUMBER_BUTTON:
657 button_event = (struct pyra_mouse_event_button const *)data;
658 switch (button_event->type) {
659 case PYRA_MOUSE_EVENT_BUTTON_TYPE_PROFILE_2:
660 profile_activated(pyra, button_event->data1 - 1);
661 break;
662 case PYRA_MOUSE_EVENT_BUTTON_TYPE_CPI:
663 pyra->actual_cpi = button_event->data1;
664 break;
666 break;
670 static void pyra_report_to_chrdev(struct pyra_device const *pyra,
671 u8 const *data)
673 struct pyra_roccat_report roccat_report;
674 struct pyra_mouse_event_button const *button_event;
676 if (data[0] != PYRA_MOUSE_REPORT_NUMBER_BUTTON)
677 return;
679 button_event = (struct pyra_mouse_event_button const *)data;
681 switch (button_event->type) {
682 case PYRA_MOUSE_EVENT_BUTTON_TYPE_PROFILE_2:
683 case PYRA_MOUSE_EVENT_BUTTON_TYPE_CPI:
684 roccat_report.type = button_event->type;
685 roccat_report.value = button_event->data1;
686 roccat_report.key = 0;
687 roccat_report_event(pyra->chrdev_minor,
688 (uint8_t const *)&roccat_report,
689 sizeof(struct pyra_roccat_report));
690 break;
691 case PYRA_MOUSE_EVENT_BUTTON_TYPE_MACRO:
692 case PYRA_MOUSE_EVENT_BUTTON_TYPE_SHORTCUT:
693 case PYRA_MOUSE_EVENT_BUTTON_TYPE_QUICKLAUNCH:
694 if (button_event->data2 == PYRA_MOUSE_EVENT_BUTTON_PRESS) {
695 roccat_report.type = button_event->type;
696 roccat_report.key = button_event->data1;
698 * pyra reports profile numbers with range 1-5.
699 * Keeping this behaviour.
701 roccat_report.value = pyra->actual_profile + 1;
702 roccat_report_event(pyra->chrdev_minor,
703 (uint8_t const *)&roccat_report,
704 sizeof(struct pyra_roccat_report));
706 break;
710 static int pyra_raw_event(struct hid_device *hdev, struct hid_report *report,
711 u8 *data, int size)
713 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
714 struct pyra_device *pyra = hid_get_drvdata(hdev);
716 if (intf->cur_altsetting->desc.bInterfaceProtocol
717 != USB_INTERFACE_PROTOCOL_MOUSE)
718 return 0;
720 pyra_keep_values_up_to_date(pyra, data);
722 if (pyra->roccat_claimed)
723 pyra_report_to_chrdev(pyra, data);
725 return 0;
728 static const struct hid_device_id pyra_devices[] = {
729 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT,
730 USB_DEVICE_ID_ROCCAT_PYRA_WIRED) },
731 /* TODO add USB_DEVICE_ID_ROCCAT_PYRA_WIRELESS after testing */
735 MODULE_DEVICE_TABLE(hid, pyra_devices);
737 static struct hid_driver pyra_driver = {
738 .name = "pyra",
739 .id_table = pyra_devices,
740 .probe = pyra_probe,
741 .remove = pyra_remove,
742 .raw_event = pyra_raw_event
745 static int __init pyra_init(void)
747 int retval;
749 /* class name has to be same as driver name */
750 pyra_class = class_create(THIS_MODULE, "pyra");
751 if (IS_ERR(pyra_class))
752 return PTR_ERR(pyra_class);
753 pyra_class->dev_attrs = pyra_attributes;
754 pyra_class->dev_bin_attrs = pyra_bin_attributes;
756 retval = hid_register_driver(&pyra_driver);
757 if (retval)
758 class_destroy(pyra_class);
759 return retval;
762 static void __exit pyra_exit(void)
764 class_destroy(pyra_class);
765 hid_unregister_driver(&pyra_driver);
768 module_init(pyra_init);
769 module_exit(pyra_exit);
771 MODULE_AUTHOR("Stefan Achatz");
772 MODULE_DESCRIPTION("USB Roccat Pyra driver");
773 MODULE_LICENSE("GPL v2");