sh_eth: fix EESIPR values for SH77{34|63}
[linux/fpc-iii.git] / drivers / hid / hid-roccat-konepure.c
blob07de2f9014c67f914209a5dfc08185892955bd79
1 /*
2 * Roccat KonePure driver for Linux
4 * Copyright (c) 2012 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 KonePure is a smaller version of KoneXTD with less buttons and lights.
18 #include <linux/types.h>
19 #include <linux/device.h>
20 #include <linux/input.h>
21 #include <linux/hid.h>
22 #include <linux/module.h>
23 #include <linux/slab.h>
24 #include <linux/hid-roccat.h>
25 #include "hid-ids.h"
26 #include "hid-roccat-common.h"
28 enum {
29 KONEPURE_MOUSE_REPORT_NUMBER_BUTTON = 3,
32 struct konepure_mouse_report_button {
33 uint8_t report_number; /* always KONEPURE_MOUSE_REPORT_NUMBER_BUTTON */
34 uint8_t zero;
35 uint8_t type;
36 uint8_t data1;
37 uint8_t data2;
38 uint8_t zero2;
39 uint8_t unknown[2];
40 } __packed;
42 static struct class *konepure_class;
44 ROCCAT_COMMON2_BIN_ATTRIBUTE_W(control, 0x04, 0x03);
45 ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(actual_profile, 0x05, 0x03);
46 ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(profile_settings, 0x06, 0x1f);
47 ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(profile_buttons, 0x07, 0x3b);
48 ROCCAT_COMMON2_BIN_ATTRIBUTE_W(macro, 0x08, 0x0822);
49 ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(info, 0x09, 0x06);
50 ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(tcu, 0x0c, 0x04);
51 ROCCAT_COMMON2_BIN_ATTRIBUTE_R(tcu_image, 0x0c, 0x0404);
52 ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(sensor, 0x0f, 0x06);
53 ROCCAT_COMMON2_BIN_ATTRIBUTE_W(talk, 0x10, 0x10);
55 static struct bin_attribute *konepure_bin_attrs[] = {
56 &bin_attr_actual_profile,
57 &bin_attr_control,
58 &bin_attr_info,
59 &bin_attr_talk,
60 &bin_attr_macro,
61 &bin_attr_sensor,
62 &bin_attr_tcu,
63 &bin_attr_tcu_image,
64 &bin_attr_profile_settings,
65 &bin_attr_profile_buttons,
66 NULL,
69 static const struct attribute_group konepure_group = {
70 .bin_attrs = konepure_bin_attrs,
73 static const struct attribute_group *konepure_groups[] = {
74 &konepure_group,
75 NULL,
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;
83 int retval;
85 if (intf->cur_altsetting->desc.bInterfaceProtocol
86 != USB_INTERFACE_PROTOCOL_MOUSE) {
87 hid_set_drvdata(hdev, NULL);
88 return 0;
91 konepure = kzalloc(sizeof(*konepure), GFP_KERNEL);
92 if (!konepure) {
93 hid_err(hdev, "can't alloc device descriptor\n");
94 return -ENOMEM;
96 hid_set_drvdata(hdev, konepure);
98 retval = roccat_common2_device_init_struct(usb_dev, konepure);
99 if (retval) {
100 hid_err(hdev, "couldn't init KonePure device\n");
101 goto exit_free;
104 retval = roccat_connect(konepure_class, hdev,
105 sizeof(struct konepure_mouse_report_button));
106 if (retval < 0) {
107 hid_err(hdev, "couldn't init char dev\n");
108 } else {
109 konepure->chrdev_minor = retval;
110 konepure->roccat_claimed = 1;
113 return 0;
114 exit_free:
115 kfree(konepure);
116 return retval;
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)
126 return;
128 konepure = hid_get_drvdata(hdev);
129 if (konepure->roccat_claimed)
130 roccat_disconnect(konepure->chrdev_minor);
131 kfree(konepure);
134 static int konepure_probe(struct hid_device *hdev,
135 const struct hid_device_id *id)
137 int retval;
139 retval = hid_parse(hdev);
140 if (retval) {
141 hid_err(hdev, "parse failed\n");
142 goto exit;
145 retval = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
146 if (retval) {
147 hid_err(hdev, "hw start failed\n");
148 goto exit;
151 retval = konepure_init_specials(hdev);
152 if (retval) {
153 hid_err(hdev, "couldn't install mouse\n");
154 goto exit_stop;
157 return 0;
159 exit_stop:
160 hid_hw_stop(hdev);
161 exit:
162 return retval;
165 static void konepure_remove(struct hid_device *hdev)
167 konepure_remove_specials(hdev);
168 hid_hw_stop(hdev);
171 static int konepure_raw_event(struct hid_device *hdev,
172 struct hid_report *report, u8 *data, int size)
174 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
175 struct roccat_common2_device *konepure = hid_get_drvdata(hdev);
177 if (intf->cur_altsetting->desc.bInterfaceProtocol
178 != USB_INTERFACE_PROTOCOL_MOUSE)
179 return 0;
181 if (data[0] != KONEPURE_MOUSE_REPORT_NUMBER_BUTTON)
182 return 0;
184 if (konepure != NULL && konepure->roccat_claimed)
185 roccat_report_event(konepure->chrdev_minor, data);
187 return 0;
190 static const struct hid_device_id konepure_devices[] = {
191 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPURE) },
192 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPURE_OPTICAL) },
196 MODULE_DEVICE_TABLE(hid, konepure_devices);
198 static struct hid_driver konepure_driver = {
199 .name = "konepure",
200 .id_table = konepure_devices,
201 .probe = konepure_probe,
202 .remove = konepure_remove,
203 .raw_event = konepure_raw_event
206 static int __init konepure_init(void)
208 int retval;
210 konepure_class = class_create(THIS_MODULE, "konepure");
211 if (IS_ERR(konepure_class))
212 return PTR_ERR(konepure_class);
213 konepure_class->dev_groups = konepure_groups;
215 retval = hid_register_driver(&konepure_driver);
216 if (retval)
217 class_destroy(konepure_class);
218 return retval;
221 static void __exit konepure_exit(void)
223 hid_unregister_driver(&konepure_driver);
224 class_destroy(konepure_class);
227 module_init(konepure_init);
228 module_exit(konepure_exit);
230 MODULE_AUTHOR("Stefan Achatz");
231 MODULE_DESCRIPTION("USB Roccat KonePure/Optical driver");
232 MODULE_LICENSE("GPL v2");