2 * Roccat Savu driver for Linux
4 * Copyright (c) 2012 Stefan Achatz <erazor_de@users.sourceforge.net>
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)
14 /* Roccat Savu is a gamer mouse with macro keys that can be configured in
18 #include <linux/device.h>
19 #include <linux/input.h>
20 #include <linux/hid.h>
21 #include <linux/module.h>
22 #include <linux/slab.h>
23 #include <linux/hid-roccat.h>
25 #include "hid-roccat-common.h"
26 #include "hid-roccat-savu.h"
28 static struct class *savu_class
;
30 ROCCAT_COMMON2_BIN_ATTRIBUTE_W(control
, 0x4, 0x03);
31 ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(profile
, 0x5, 0x03);
32 ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(general
, 0x6, 0x10);
33 ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(buttons
, 0x7, 0x2f);
34 ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(macro
, 0x8, 0x0823);
35 ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(info
, 0x9, 0x08);
36 ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(sensor
, 0xc, 0x04);
38 static struct bin_attribute
*savu_bin_attrs
[] = {
49 static const struct attribute_group savu_group
= {
50 .bin_attrs
= savu_bin_attrs
,
53 static const struct attribute_group
*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 retval
= hid_parse(hdev
);
121 hid_err(hdev
, "parse failed\n");
125 retval
= hid_hw_start(hdev
, HID_CONNECT_DEFAULT
);
127 hid_err(hdev
, "hw start failed\n");
131 retval
= savu_init_specials(hdev
);
133 hid_err(hdev
, "couldn't install mouse\n");
145 static void savu_remove(struct hid_device
*hdev
)
147 savu_remove_specials(hdev
);
151 static void savu_report_to_chrdev(struct roccat_common2_device
const *savu
,
154 struct savu_roccat_report roccat_report
;
155 struct savu_mouse_report_special
const *special_report
;
157 if (data
[0] != SAVU_MOUSE_REPORT_NUMBER_SPECIAL
)
160 special_report
= (struct savu_mouse_report_special
const *)data
;
162 roccat_report
.type
= special_report
->type
;
163 roccat_report
.data
[0] = special_report
->data
[0];
164 roccat_report
.data
[1] = special_report
->data
[1];
165 roccat_report_event(savu
->chrdev_minor
,
166 (uint8_t const *)&roccat_report
);
169 static int savu_raw_event(struct hid_device
*hdev
,
170 struct hid_report
*report
, u8
*data
, int size
)
172 struct usb_interface
*intf
= to_usb_interface(hdev
->dev
.parent
);
173 struct roccat_common2_device
*savu
= hid_get_drvdata(hdev
);
175 if (intf
->cur_altsetting
->desc
.bInterfaceProtocol
176 != USB_INTERFACE_PROTOCOL_MOUSE
)
182 if (savu
->roccat_claimed
)
183 savu_report_to_chrdev(savu
, data
);
188 static const struct hid_device_id savu_devices
[] = {
189 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT
, USB_DEVICE_ID_ROCCAT_SAVU
) },
193 MODULE_DEVICE_TABLE(hid
, savu_devices
);
195 static struct hid_driver savu_driver
= {
197 .id_table
= savu_devices
,
199 .remove
= savu_remove
,
200 .raw_event
= savu_raw_event
203 static int __init
savu_init(void)
207 savu_class
= class_create(THIS_MODULE
, "savu");
208 if (IS_ERR(savu_class
))
209 return PTR_ERR(savu_class
);
210 savu_class
->dev_groups
= savu_groups
;
212 retval
= hid_register_driver(&savu_driver
);
214 class_destroy(savu_class
);
218 static void __exit
savu_exit(void)
220 hid_unregister_driver(&savu_driver
);
221 class_destroy(savu_class
);
224 module_init(savu_init
);
225 module_exit(savu_exit
);
227 MODULE_AUTHOR("Stefan Achatz");
228 MODULE_DESCRIPTION("USB Roccat Savu driver");
229 MODULE_LICENSE("GPL v2");