mm, vmalloc: remove useless variable in vmap_block
[linux/fpc-iii.git] / drivers / hid / hid-roccat-konepure.c
blob99a605ebb665b6eb952f99922bc7103a0536819f
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/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>
24 #include "hid-ids.h"
25 #include "hid-roccat-common.h"
26 #include "hid-roccat-konepure.h"
28 static struct class *konepure_class;
30 static ssize_t konepure_sysfs_read(struct file *fp, struct kobject *kobj,
31 char *buf, loff_t off, size_t count,
32 size_t real_size, uint command)
34 struct device *dev =
35 container_of(kobj, struct device, kobj)->parent->parent;
36 struct konepure_device *konepure = hid_get_drvdata(dev_get_drvdata(dev));
37 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
38 int retval;
40 if (off >= real_size)
41 return 0;
43 if (off != 0 || count != real_size)
44 return -EINVAL;
46 mutex_lock(&konepure->konepure_lock);
47 retval = roccat_common2_receive(usb_dev, command, buf, real_size);
48 mutex_unlock(&konepure->konepure_lock);
50 return retval ? retval : real_size;
53 static ssize_t konepure_sysfs_write(struct file *fp, struct kobject *kobj,
54 void const *buf, loff_t off, size_t count,
55 size_t real_size, uint command)
57 struct device *dev =
58 container_of(kobj, struct device, kobj)->parent->parent;
59 struct konepure_device *konepure = hid_get_drvdata(dev_get_drvdata(dev));
60 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
61 int retval;
63 if (off != 0 || count != real_size)
64 return -EINVAL;
66 mutex_lock(&konepure->konepure_lock);
67 retval = roccat_common2_send_with_status(usb_dev, command,
68 (void *)buf, real_size);
69 mutex_unlock(&konepure->konepure_lock);
71 return retval ? retval : real_size;
74 #define KONEPURE_SYSFS_W(thingy, THINGY) \
75 static ssize_t konepure_sysfs_write_ ## thingy(struct file *fp, \
76 struct kobject *kobj, struct bin_attribute *attr, char *buf, \
77 loff_t off, size_t count) \
78 { \
79 return konepure_sysfs_write(fp, kobj, buf, off, count, \
80 KONEPURE_SIZE_ ## THINGY, KONEPURE_COMMAND_ ## THINGY); \
83 #define KONEPURE_SYSFS_R(thingy, THINGY) \
84 static ssize_t konepure_sysfs_read_ ## thingy(struct file *fp, \
85 struct kobject *kobj, struct bin_attribute *attr, char *buf, \
86 loff_t off, size_t count) \
87 { \
88 return konepure_sysfs_read(fp, kobj, buf, off, count, \
89 KONEPURE_SIZE_ ## THINGY, KONEPURE_COMMAND_ ## THINGY); \
92 #define KONEPURE_SYSFS_RW(thingy, THINGY) \
93 KONEPURE_SYSFS_W(thingy, THINGY) \
94 KONEPURE_SYSFS_R(thingy, THINGY)
96 #define KONEPURE_BIN_ATTRIBUTE_RW(thingy, THINGY) \
97 KONEPURE_SYSFS_RW(thingy, THINGY); \
98 static struct bin_attribute bin_attr_##thingy = { \
99 .attr = { .name = #thingy, .mode = 0660 }, \
100 .size = KONEPURE_SIZE_ ## THINGY, \
101 .read = konepure_sysfs_read_ ## thingy, \
102 .write = konepure_sysfs_write_ ## thingy \
105 #define KONEPURE_BIN_ATTRIBUTE_R(thingy, THINGY) \
106 KONEPURE_SYSFS_R(thingy, THINGY); \
107 static struct bin_attribute bin_attr_##thingy = { \
108 .attr = { .name = #thingy, .mode = 0440 }, \
109 .size = KONEPURE_SIZE_ ## THINGY, \
110 .read = konepure_sysfs_read_ ## thingy, \
113 #define KONEPURE_BIN_ATTRIBUTE_W(thingy, THINGY) \
114 KONEPURE_SYSFS_W(thingy, THINGY); \
115 static struct bin_attribute bin_attr_##thingy = { \
116 .attr = { .name = #thingy, .mode = 0220 }, \
117 .size = KONEPURE_SIZE_ ## THINGY, \
118 .write = konepure_sysfs_write_ ## thingy \
121 KONEPURE_BIN_ATTRIBUTE_RW(actual_profile, ACTUAL_PROFILE);
122 KONEPURE_BIN_ATTRIBUTE_RW(info, INFO);
123 KONEPURE_BIN_ATTRIBUTE_RW(sensor, SENSOR);
124 KONEPURE_BIN_ATTRIBUTE_RW(tcu, TCU);
125 KONEPURE_BIN_ATTRIBUTE_RW(profile_settings, PROFILE_SETTINGS);
126 KONEPURE_BIN_ATTRIBUTE_RW(profile_buttons, PROFILE_BUTTONS);
127 KONEPURE_BIN_ATTRIBUTE_W(control, CONTROL);
128 KONEPURE_BIN_ATTRIBUTE_W(talk, TALK);
129 KONEPURE_BIN_ATTRIBUTE_W(macro, MACRO);
130 KONEPURE_BIN_ATTRIBUTE_R(tcu_image, TCU_IMAGE);
132 static struct bin_attribute *konepure_bin_attributes[] = {
133 &bin_attr_actual_profile,
134 &bin_attr_info,
135 &bin_attr_sensor,
136 &bin_attr_tcu,
137 &bin_attr_profile_settings,
138 &bin_attr_profile_buttons,
139 &bin_attr_control,
140 &bin_attr_talk,
141 &bin_attr_macro,
142 &bin_attr_tcu_image,
143 NULL,
146 static const struct attribute_group konepure_group = {
147 .bin_attrs = konepure_bin_attributes,
150 static const struct attribute_group *konepure_groups[] = {
151 &konepure_group,
152 NULL,
156 static int konepure_init_konepure_device_struct(struct usb_device *usb_dev,
157 struct konepure_device *konepure)
159 mutex_init(&konepure->konepure_lock);
161 return 0;
164 static int konepure_init_specials(struct hid_device *hdev)
166 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
167 struct usb_device *usb_dev = interface_to_usbdev(intf);
168 struct konepure_device *konepure;
169 int retval;
171 if (intf->cur_altsetting->desc.bInterfaceProtocol
172 != USB_INTERFACE_PROTOCOL_MOUSE) {
173 hid_set_drvdata(hdev, NULL);
174 return 0;
177 konepure = kzalloc(sizeof(*konepure), GFP_KERNEL);
178 if (!konepure) {
179 hid_err(hdev, "can't alloc device descriptor\n");
180 return -ENOMEM;
182 hid_set_drvdata(hdev, konepure);
184 retval = konepure_init_konepure_device_struct(usb_dev, konepure);
185 if (retval) {
186 hid_err(hdev, "couldn't init struct konepure_device\n");
187 goto exit_free;
190 retval = roccat_connect(konepure_class, hdev,
191 sizeof(struct konepure_mouse_report_button));
192 if (retval < 0) {
193 hid_err(hdev, "couldn't init char dev\n");
194 } else {
195 konepure->chrdev_minor = retval;
196 konepure->roccat_claimed = 1;
199 return 0;
200 exit_free:
201 kfree(konepure);
202 return retval;
205 static void konepure_remove_specials(struct hid_device *hdev)
207 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
208 struct konepure_device *konepure;
210 if (intf->cur_altsetting->desc.bInterfaceProtocol
211 != USB_INTERFACE_PROTOCOL_MOUSE)
212 return;
214 konepure = hid_get_drvdata(hdev);
215 if (konepure->roccat_claimed)
216 roccat_disconnect(konepure->chrdev_minor);
217 kfree(konepure);
220 static int konepure_probe(struct hid_device *hdev,
221 const struct hid_device_id *id)
223 int retval;
225 retval = hid_parse(hdev);
226 if (retval) {
227 hid_err(hdev, "parse failed\n");
228 goto exit;
231 retval = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
232 if (retval) {
233 hid_err(hdev, "hw start failed\n");
234 goto exit;
237 retval = konepure_init_specials(hdev);
238 if (retval) {
239 hid_err(hdev, "couldn't install mouse\n");
240 goto exit_stop;
243 return 0;
245 exit_stop:
246 hid_hw_stop(hdev);
247 exit:
248 return retval;
251 static void konepure_remove(struct hid_device *hdev)
253 konepure_remove_specials(hdev);
254 hid_hw_stop(hdev);
257 static int konepure_raw_event(struct hid_device *hdev,
258 struct hid_report *report, u8 *data, int size)
260 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
261 struct konepure_device *konepure = hid_get_drvdata(hdev);
263 if (intf->cur_altsetting->desc.bInterfaceProtocol
264 != USB_INTERFACE_PROTOCOL_MOUSE)
265 return 0;
267 if (data[0] != KONEPURE_MOUSE_REPORT_NUMBER_BUTTON)
268 return 0;
270 if (konepure != NULL && konepure->roccat_claimed)
271 roccat_report_event(konepure->chrdev_minor, data);
273 return 0;
276 static const struct hid_device_id konepure_devices[] = {
277 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPURE) },
278 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPURE_OPTICAL) },
282 MODULE_DEVICE_TABLE(hid, konepure_devices);
284 static struct hid_driver konepure_driver = {
285 .name = "konepure",
286 .id_table = konepure_devices,
287 .probe = konepure_probe,
288 .remove = konepure_remove,
289 .raw_event = konepure_raw_event
292 static int __init konepure_init(void)
294 int retval;
296 konepure_class = class_create(THIS_MODULE, "konepure");
297 if (IS_ERR(konepure_class))
298 return PTR_ERR(konepure_class);
299 konepure_class->dev_groups = konepure_groups;
301 retval = hid_register_driver(&konepure_driver);
302 if (retval)
303 class_destroy(konepure_class);
304 return retval;
307 static void __exit konepure_exit(void)
309 hid_unregister_driver(&konepure_driver);
310 class_destroy(konepure_class);
313 module_init(konepure_init);
314 module_exit(konepure_exit);
316 MODULE_AUTHOR("Stefan Achatz");
317 MODULE_DESCRIPTION("USB Roccat KonePure/Optical driver");
318 MODULE_LICENSE("GPL v2");