1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Roccat Savu driver for Linux
5 * Copyright (c) 2012 Stefan Achatz <erazor_de@users.sourceforge.net>
11 /* Roccat Savu is a gamer mouse with macro keys that can be configured in
15 #include <linux/device.h>
16 #include <linux/input.h>
17 #include <linux/hid.h>
18 #include <linux/module.h>
19 #include <linux/slab.h>
20 #include <linux/hid-roccat.h>
22 #include "hid-roccat-common.h"
23 #include "hid-roccat-savu.h"
25 ROCCAT_COMMON2_BIN_ATTRIBUTE_W(control, 0x4, 0x03);
26 ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(profile, 0x5, 0x03);
27 ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(general, 0x6, 0x10);
28 ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(buttons, 0x7, 0x2f);
29 ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(macro, 0x8, 0x0823);
30 ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(info, 0x9, 0x08);
31 ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(sensor, 0xc, 0x04);
33 static struct bin_attribute *savu_bin_attrs[] = {
44 static const struct attribute_group savu_group = {
45 .bin_attrs = savu_bin_attrs,
48 static const struct attribute_group *savu_groups[] = {
53 static const struct class savu_class = {
55 .dev_groups = savu_groups,
58 static int savu_init_specials(struct hid_device *hdev)
60 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
61 struct usb_device *usb_dev = interface_to_usbdev(intf);
62 struct roccat_common2_device *savu;
65 if (intf->cur_altsetting->desc.bInterfaceProtocol
66 != USB_INTERFACE_PROTOCOL_MOUSE) {
67 hid_set_drvdata(hdev, NULL);
71 savu = kzalloc(sizeof(*savu), GFP_KERNEL);
73 hid_err(hdev, "can't alloc device descriptor\n");
76 hid_set_drvdata(hdev, savu);
78 retval = roccat_common2_device_init_struct(usb_dev, savu);
80 hid_err(hdev, "couldn't init Savu device\n");
84 retval = roccat_connect(&savu_class, hdev,
85 sizeof(struct savu_roccat_report));
87 hid_err(hdev, "couldn't init char dev\n");
89 savu->chrdev_minor = retval;
90 savu->roccat_claimed = 1;
99 static void savu_remove_specials(struct hid_device *hdev)
101 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
102 struct roccat_common2_device *savu;
104 if (intf->cur_altsetting->desc.bInterfaceProtocol
105 != USB_INTERFACE_PROTOCOL_MOUSE)
108 savu = hid_get_drvdata(hdev);
109 if (savu->roccat_claimed)
110 roccat_disconnect(savu->chrdev_minor);
114 static int savu_probe(struct hid_device *hdev,
115 const struct hid_device_id *id)
119 if (!hid_is_usb(hdev))
122 retval = hid_parse(hdev);
124 hid_err(hdev, "parse failed\n");
128 retval = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
130 hid_err(hdev, "hw start failed\n");
134 retval = savu_init_specials(hdev);
136 hid_err(hdev, "couldn't install mouse\n");
148 static void savu_remove(struct hid_device *hdev)
150 savu_remove_specials(hdev);
154 static void savu_report_to_chrdev(struct roccat_common2_device const *savu,
157 struct savu_roccat_report roccat_report;
158 struct savu_mouse_report_special const *special_report;
160 if (data[0] != SAVU_MOUSE_REPORT_NUMBER_SPECIAL)
163 special_report = (struct savu_mouse_report_special const *)data;
165 roccat_report.type = special_report->type;
166 roccat_report.data[0] = special_report->data[0];
167 roccat_report.data[1] = special_report->data[1];
168 roccat_report_event(savu->chrdev_minor,
169 (uint8_t const *)&roccat_report);
172 static int savu_raw_event(struct hid_device *hdev,
173 struct hid_report *report, u8 *data, int size)
175 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
176 struct roccat_common2_device *savu = hid_get_drvdata(hdev);
178 if (intf->cur_altsetting->desc.bInterfaceProtocol
179 != USB_INTERFACE_PROTOCOL_MOUSE)
185 if (savu->roccat_claimed)
186 savu_report_to_chrdev(savu, data);
191 static const struct hid_device_id savu_devices[] = {
192 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_SAVU) },
196 MODULE_DEVICE_TABLE(hid, savu_devices);
198 static struct hid_driver savu_driver = {
200 .id_table = savu_devices,
202 .remove = savu_remove,
203 .raw_event = savu_raw_event
206 static int __init savu_init(void)
210 retval = class_register(&savu_class);
214 retval = hid_register_driver(&savu_driver);
216 class_unregister(&savu_class);
220 static void __exit savu_exit(void)
222 hid_unregister_driver(&savu_driver);
223 class_unregister(&savu_class);
226 module_init(savu_init);
227 module_exit(savu_exit);
229 MODULE_AUTHOR("Stefan Achatz");
230 MODULE_DESCRIPTION("USB Roccat Savu driver");
231 MODULE_LICENSE("GPL v2");