Blame view
drivers/hid/hid-roccat-konepure.c
5.33 KB
2874c5fd2 treewide: Replace... |
1 |
// SPDX-License-Identifier: GPL-2.0-or-later |
8936aa31c HID: roccat: add ... |
2 3 4 5 6 7 8 |
/* * Roccat KonePure driver for Linux * * Copyright (c) 2012 Stefan Achatz <erazor_de@users.sourceforge.net> */ /* |
8936aa31c HID: roccat: add ... |
9 10 11 12 13 |
*/ /* * Roccat KonePure is a smaller version of KoneXTD with less buttons and lights. */ |
71304f5a2 HID: roccat: gene... |
14 |
#include <linux/types.h> |
8936aa31c HID: roccat: add ... |
15 16 17 18 19 20 21 22 |
#include <linux/device.h> #include <linux/input.h> #include <linux/hid.h> #include <linux/module.h> #include <linux/slab.h> #include <linux/hid-roccat.h> #include "hid-ids.h" #include "hid-roccat-common.h" |
8936aa31c HID: roccat: add ... |
23 |
|
71304f5a2 HID: roccat: gene... |
24 25 26 |
enum { KONEPURE_MOUSE_REPORT_NUMBER_BUTTON = 3, }; |
8936aa31c HID: roccat: add ... |
27 |
|
71304f5a2 HID: roccat: gene... |
28 29 30 31 32 33 34 35 36 |
struct konepure_mouse_report_button { uint8_t report_number; /* always KONEPURE_MOUSE_REPORT_NUMBER_BUTTON */ uint8_t zero; uint8_t type; uint8_t data1; uint8_t data2; uint8_t zero2; uint8_t unknown[2]; } __packed; |
8936aa31c HID: roccat: add ... |
37 |
|
71304f5a2 HID: roccat: gene... |
38 |
static struct class *konepure_class; |
8936aa31c HID: roccat: add ... |
39 |
|
71304f5a2 HID: roccat: gene... |
40 41 42 43 44 45 46 47 48 49 50 51 |
ROCCAT_COMMON2_BIN_ATTRIBUTE_W(control, 0x04, 0x03); ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(actual_profile, 0x05, 0x03); ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(profile_settings, 0x06, 0x1f); ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(profile_buttons, 0x07, 0x3b); ROCCAT_COMMON2_BIN_ATTRIBUTE_W(macro, 0x08, 0x0822); ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(info, 0x09, 0x06); ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(tcu, 0x0c, 0x04); ROCCAT_COMMON2_BIN_ATTRIBUTE_R(tcu_image, 0x0c, 0x0404); ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(sensor, 0x0f, 0x06); ROCCAT_COMMON2_BIN_ATTRIBUTE_W(talk, 0x10, 0x10); static struct bin_attribute *konepure_bin_attrs[] = { |
0f1947f35 hid: roccat-konep... |
52 |
&bin_attr_actual_profile, |
71304f5a2 HID: roccat: gene... |
53 |
&bin_attr_control, |
0f1947f35 hid: roccat-konep... |
54 |
&bin_attr_info, |
71304f5a2 HID: roccat: gene... |
55 56 |
&bin_attr_talk, &bin_attr_macro, |
0f1947f35 hid: roccat-konep... |
57 58 |
&bin_attr_sensor, &bin_attr_tcu, |
71304f5a2 HID: roccat: gene... |
59 |
&bin_attr_tcu_image, |
0f1947f35 hid: roccat-konep... |
60 61 |
&bin_attr_profile_settings, &bin_attr_profile_buttons, |
0f1947f35 hid: roccat-konep... |
62 63 64 65 |
NULL, }; static const struct attribute_group konepure_group = { |
71304f5a2 HID: roccat: gene... |
66 |
.bin_attrs = konepure_bin_attrs, |
0f1947f35 hid: roccat-konep... |
67 68 69 70 71 |
}; static const struct attribute_group *konepure_groups[] = { &konepure_group, NULL, |
8936aa31c HID: roccat: add ... |
72 |
}; |
8936aa31c HID: roccat: add ... |
73 74 75 76 |
static int konepure_init_specials(struct hid_device *hdev) { struct usb_interface *intf = to_usb_interface(hdev->dev.parent); struct usb_device *usb_dev = interface_to_usbdev(intf); |
71304f5a2 HID: roccat: gene... |
77 |
struct roccat_common2_device *konepure; |
8936aa31c HID: roccat: add ... |
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
int retval; if (intf->cur_altsetting->desc.bInterfaceProtocol != USB_INTERFACE_PROTOCOL_MOUSE) { hid_set_drvdata(hdev, NULL); return 0; } konepure = kzalloc(sizeof(*konepure), GFP_KERNEL); if (!konepure) { hid_err(hdev, "can't alloc device descriptor "); return -ENOMEM; } hid_set_drvdata(hdev, konepure); |
71304f5a2 HID: roccat: gene... |
93 |
retval = roccat_common2_device_init_struct(usb_dev, konepure); |
8936aa31c HID: roccat: add ... |
94 |
if (retval) { |
71304f5a2 HID: roccat: gene... |
95 96 |
hid_err(hdev, "couldn't init KonePure device "); |
8936aa31c HID: roccat: add ... |
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
goto exit_free; } retval = roccat_connect(konepure_class, hdev, sizeof(struct konepure_mouse_report_button)); if (retval < 0) { hid_err(hdev, "couldn't init char dev "); } else { konepure->chrdev_minor = retval; konepure->roccat_claimed = 1; } return 0; exit_free: kfree(konepure); return retval; } static void konepure_remove_specials(struct hid_device *hdev) { struct usb_interface *intf = to_usb_interface(hdev->dev.parent); |
71304f5a2 HID: roccat: gene... |
119 |
struct roccat_common2_device *konepure; |
8936aa31c HID: roccat: add ... |
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
if (intf->cur_altsetting->desc.bInterfaceProtocol != USB_INTERFACE_PROTOCOL_MOUSE) return; konepure = hid_get_drvdata(hdev); if (konepure->roccat_claimed) roccat_disconnect(konepure->chrdev_minor); kfree(konepure); } static int konepure_probe(struct hid_device *hdev, const struct hid_device_id *id) { int retval; retval = hid_parse(hdev); if (retval) { hid_err(hdev, "parse failed "); goto exit; } retval = hid_hw_start(hdev, HID_CONNECT_DEFAULT); if (retval) { hid_err(hdev, "hw start failed "); goto exit; } retval = konepure_init_specials(hdev); if (retval) { hid_err(hdev, "couldn't install mouse "); goto exit_stop; } return 0; exit_stop: hid_hw_stop(hdev); exit: return retval; } static void konepure_remove(struct hid_device *hdev) { konepure_remove_specials(hdev); hid_hw_stop(hdev); } static int konepure_raw_event(struct hid_device *hdev, struct hid_report *report, u8 *data, int size) { struct usb_interface *intf = to_usb_interface(hdev->dev.parent); |
71304f5a2 HID: roccat: gene... |
175 |
struct roccat_common2_device *konepure = hid_get_drvdata(hdev); |
8936aa31c HID: roccat: add ... |
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
if (intf->cur_altsetting->desc.bInterfaceProtocol != USB_INTERFACE_PROTOCOL_MOUSE) return 0; if (data[0] != KONEPURE_MOUSE_REPORT_NUMBER_BUTTON) return 0; if (konepure != NULL && konepure->roccat_claimed) roccat_report_event(konepure->chrdev_minor, data); return 0; } static const struct hid_device_id konepure_devices[] = { { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPURE) }, |
a4be0ed39 HID: roccat: add ... |
192 |
{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPURE_OPTICAL) }, |
8936aa31c HID: roccat: add ... |
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
{ } }; MODULE_DEVICE_TABLE(hid, konepure_devices); static struct hid_driver konepure_driver = { .name = "konepure", .id_table = konepure_devices, .probe = konepure_probe, .remove = konepure_remove, .raw_event = konepure_raw_event }; static int __init konepure_init(void) { int retval; konepure_class = class_create(THIS_MODULE, "konepure"); if (IS_ERR(konepure_class)) return PTR_ERR(konepure_class); |
0f1947f35 hid: roccat-konep... |
213 |
konepure_class->dev_groups = konepure_groups; |
8936aa31c HID: roccat: add ... |
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
retval = hid_register_driver(&konepure_driver); if (retval) class_destroy(konepure_class); return retval; } static void __exit konepure_exit(void) { hid_unregister_driver(&konepure_driver); class_destroy(konepure_class); } module_init(konepure_init); module_exit(konepure_exit); MODULE_AUTHOR("Stefan Achatz"); |
a4be0ed39 HID: roccat: add ... |
231 |
MODULE_DESCRIPTION("USB Roccat KonePure/Optical driver"); |
8936aa31c HID: roccat: add ... |
232 |
MODULE_LICENSE("GPL v2"); |