1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Roccat KonePure driver for Linux
5 * Copyright (c) 2012 Stefan Achatz <erazor_de@users.sourceforge.net>
12 * Roccat KonePure is a smaller version of KoneXTD with less buttons and lights.
15 #include <linux/types.h>
16 #include <linux/device.h>
17 #include <linux/input.h>
18 #include <linux/hid.h>
19 #include <linux/module.h>
20 #include <linux/slab.h>
21 #include <linux/hid-roccat.h>
23 #include "hid-roccat-common.h"
26 KONEPURE_MOUSE_REPORT_NUMBER_BUTTON = 3,
29 struct konepure_mouse_report_button {
30 uint8_t report_number; /* always KONEPURE_MOUSE_REPORT_NUMBER_BUTTON */
39 ROCCAT_COMMON2_BIN_ATTRIBUTE_W(control, 0x04, 0x03);
40 ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(actual_profile, 0x05, 0x03);
41 ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(profile_settings, 0x06, 0x1f);
42 ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(profile_buttons, 0x07, 0x3b);
43 ROCCAT_COMMON2_BIN_ATTRIBUTE_W(macro, 0x08, 0x0822);
44 ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(info, 0x09, 0x06);
45 ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(tcu, 0x0c, 0x04);
46 ROCCAT_COMMON2_BIN_ATTRIBUTE_R(tcu_image, 0x0c, 0x0404);
47 ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(sensor, 0x0f, 0x06);
48 ROCCAT_COMMON2_BIN_ATTRIBUTE_W(talk, 0x10, 0x10);
50 static struct bin_attribute *konepure_bin_attrs[] = {
51 &bin_attr_actual_profile,
59 &bin_attr_profile_settings,
60 &bin_attr_profile_buttons,
64 static const struct attribute_group konepure_group = {
65 .bin_attrs = konepure_bin_attrs,
68 static const struct attribute_group *konepure_groups[] = {
73 static const struct class konepure_class = {
75 .dev_groups = konepure_groups,
78 static int konepure_init_specials(struct hid_device *hdev)
80 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
81 struct usb_device *usb_dev = interface_to_usbdev(intf);
82 struct roccat_common2_device *konepure;
85 if (intf->cur_altsetting->desc.bInterfaceProtocol
86 != USB_INTERFACE_PROTOCOL_MOUSE) {
87 hid_set_drvdata(hdev, NULL);
91 konepure = kzalloc(sizeof(*konepure), GFP_KERNEL);
93 hid_err(hdev, "can't alloc device descriptor\n");
96 hid_set_drvdata(hdev, konepure);
98 retval = roccat_common2_device_init_struct(usb_dev, konepure);
100 hid_err(hdev, "couldn't init KonePure device\n");
104 retval = roccat_connect(&konepure_class, hdev,
105 sizeof(struct konepure_mouse_report_button));
107 hid_err(hdev, "couldn't init char dev\n");
109 konepure->chrdev_minor = retval;
110 konepure->roccat_claimed = 1;
119 static void konepure_remove_specials(struct hid_device *hdev)
121 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
122 struct roccat_common2_device *konepure;
124 if (intf->cur_altsetting->desc.bInterfaceProtocol
125 != USB_INTERFACE_PROTOCOL_MOUSE)
128 konepure = hid_get_drvdata(hdev);
129 if (konepure->roccat_claimed)
130 roccat_disconnect(konepure->chrdev_minor);
134 static int konepure_probe(struct hid_device *hdev,
135 const struct hid_device_id *id)
139 if (!hid_is_usb(hdev))
142 retval = hid_parse(hdev);
144 hid_err(hdev, "parse failed\n");
148 retval = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
150 hid_err(hdev, "hw start failed\n");
154 retval = konepure_init_specials(hdev);
156 hid_err(hdev, "couldn't install mouse\n");
168 static void konepure_remove(struct hid_device *hdev)
170 konepure_remove_specials(hdev);
174 static int konepure_raw_event(struct hid_device *hdev,
175 struct hid_report *report, u8 *data, int size)
177 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
178 struct roccat_common2_device *konepure = hid_get_drvdata(hdev);
180 if (intf->cur_altsetting->desc.bInterfaceProtocol
181 != USB_INTERFACE_PROTOCOL_MOUSE)
184 if (data[0] != KONEPURE_MOUSE_REPORT_NUMBER_BUTTON)
187 if (konepure != NULL && konepure->roccat_claimed)
188 roccat_report_event(konepure->chrdev_minor, data);
193 static const struct hid_device_id konepure_devices[] = {
194 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPURE) },
195 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPURE_OPTICAL) },
199 MODULE_DEVICE_TABLE(hid, konepure_devices);
201 static struct hid_driver konepure_driver = {
203 .id_table = konepure_devices,
204 .probe = konepure_probe,
205 .remove = konepure_remove,
206 .raw_event = konepure_raw_event
209 static int __init konepure_init(void)
213 retval = class_register(&konepure_class);
217 retval = hid_register_driver(&konepure_driver);
219 class_unregister(&konepure_class);
223 static void __exit konepure_exit(void)
225 hid_unregister_driver(&konepure_driver);
226 class_unregister(&konepure_class);
229 module_init(konepure_init);
230 module_exit(konepure_exit);
232 MODULE_AUTHOR("Stefan Achatz");
233 MODULE_DESCRIPTION("USB Roccat KonePure/Optical driver");
234 MODULE_LICENSE("GPL v2");