Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Roccat Kone[+] driver for Linux |
| 3 | * |
| 4 | * Copyright (c) 2010 Stefan Achatz <erazor_de@users.sourceforge.net> |
| 5 | */ |
| 6 | |
| 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. |
| 12 | */ |
| 13 | |
| 14 | /* |
| 15 | * Roccat Kone[+] is an updated/improved version of the Kone with more memory |
| 16 | * and functionality and without the non-standard behaviours the Kone had. |
Stefan Achatz | 8e74a2d | 2012-11-04 09:38:52 +0100 | [diff] [blame^] | 17 | * KoneXTD has same capabilities but updated sensor. |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #include <linux/device.h> |
| 21 | #include <linux/input.h> |
| 22 | #include <linux/hid.h> |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 23 | #include <linux/module.h> |
| 24 | #include <linux/slab.h> |
Stefan Achatz | 5dc0c98 | 2011-02-03 16:14:43 +0100 | [diff] [blame] | 25 | #include <linux/hid-roccat.h> |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 26 | #include "hid-ids.h" |
Stefan Achatz | 5772f63 | 2011-01-30 13:38:23 +0100 | [diff] [blame] | 27 | #include "hid-roccat-common.h" |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 28 | #include "hid-roccat-koneplus.h" |
| 29 | |
| 30 | static uint profile_numbers[5] = {0, 1, 2, 3, 4}; |
| 31 | |
| 32 | static struct class *koneplus_class; |
| 33 | |
| 34 | static void koneplus_profile_activated(struct koneplus_device *koneplus, |
| 35 | uint new_profile) |
| 36 | { |
| 37 | koneplus->actual_profile = new_profile; |
| 38 | } |
| 39 | |
| 40 | static int koneplus_send_control(struct usb_device *usb_dev, uint value, |
| 41 | enum koneplus_control_requests request) |
| 42 | { |
Stefan Achatz | 7392d73 | 2012-05-20 22:45:04 +0200 | [diff] [blame] | 43 | struct roccat_common2_control control; |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 44 | |
| 45 | if ((request == KONEPLUS_CONTROL_REQUEST_PROFILE_SETTINGS || |
| 46 | request == KONEPLUS_CONTROL_REQUEST_PROFILE_BUTTONS) && |
| 47 | value > 4) |
| 48 | return -EINVAL; |
| 49 | |
Stefan Achatz | 4728f2d | 2012-05-20 22:44:59 +0200 | [diff] [blame] | 50 | control.command = ROCCAT_COMMON_COMMAND_CONTROL; |
Stefan Achatz | 5772f63 | 2011-01-30 13:38:23 +0100 | [diff] [blame] | 51 | control.value = value; |
| 52 | control.request = request; |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 53 | |
Stefan Achatz | 7392d73 | 2012-05-20 22:45:04 +0200 | [diff] [blame] | 54 | return roccat_common2_send_with_status(usb_dev, |
Stefan Achatz | 4728f2d | 2012-05-20 22:44:59 +0200 | [diff] [blame] | 55 | ROCCAT_COMMON_COMMAND_CONTROL, |
Stefan Achatz | 7392d73 | 2012-05-20 22:45:04 +0200 | [diff] [blame] | 56 | &control, sizeof(struct roccat_common2_control)); |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | static int koneplus_get_info(struct usb_device *usb_dev, |
| 60 | struct koneplus_info *buf) |
| 61 | { |
Stefan Achatz | 7392d73 | 2012-05-20 22:45:04 +0200 | [diff] [blame] | 62 | return roccat_common2_receive(usb_dev, KONEPLUS_COMMAND_INFO, |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 63 | buf, sizeof(struct koneplus_info)); |
| 64 | } |
| 65 | |
| 66 | static int koneplus_get_profile_settings(struct usb_device *usb_dev, |
| 67 | struct koneplus_profile_settings *buf, uint number) |
| 68 | { |
| 69 | int retval; |
| 70 | |
Stefan Achatz | 4728f2d | 2012-05-20 22:44:59 +0200 | [diff] [blame] | 71 | retval = koneplus_send_control(usb_dev, number, |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 72 | KONEPLUS_CONTROL_REQUEST_PROFILE_SETTINGS); |
| 73 | if (retval) |
| 74 | return retval; |
| 75 | |
Stefan Achatz | 7392d73 | 2012-05-20 22:45:04 +0200 | [diff] [blame] | 76 | return roccat_common2_receive(usb_dev, KONEPLUS_COMMAND_PROFILE_SETTINGS, |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 77 | buf, sizeof(struct koneplus_profile_settings)); |
| 78 | } |
| 79 | |
| 80 | static int koneplus_set_profile_settings(struct usb_device *usb_dev, |
| 81 | struct koneplus_profile_settings const *settings) |
| 82 | { |
Stefan Achatz | 7392d73 | 2012-05-20 22:45:04 +0200 | [diff] [blame] | 83 | return roccat_common2_send_with_status(usb_dev, |
Stefan Achatz | 4728f2d | 2012-05-20 22:44:59 +0200 | [diff] [blame] | 84 | KONEPLUS_COMMAND_PROFILE_SETTINGS, |
Stefan Achatz | 5772f63 | 2011-01-30 13:38:23 +0100 | [diff] [blame] | 85 | settings, sizeof(struct koneplus_profile_settings)); |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | static int koneplus_get_profile_buttons(struct usb_device *usb_dev, |
| 89 | struct koneplus_profile_buttons *buf, int number) |
| 90 | { |
| 91 | int retval; |
| 92 | |
Stefan Achatz | 4728f2d | 2012-05-20 22:44:59 +0200 | [diff] [blame] | 93 | retval = koneplus_send_control(usb_dev, number, |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 94 | KONEPLUS_CONTROL_REQUEST_PROFILE_BUTTONS); |
| 95 | if (retval) |
| 96 | return retval; |
| 97 | |
Stefan Achatz | 7392d73 | 2012-05-20 22:45:04 +0200 | [diff] [blame] | 98 | return roccat_common2_receive(usb_dev, KONEPLUS_COMMAND_PROFILE_BUTTONS, |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 99 | buf, sizeof(struct koneplus_profile_buttons)); |
| 100 | } |
| 101 | |
| 102 | static int koneplus_set_profile_buttons(struct usb_device *usb_dev, |
| 103 | struct koneplus_profile_buttons const *buttons) |
| 104 | { |
Stefan Achatz | 7392d73 | 2012-05-20 22:45:04 +0200 | [diff] [blame] | 105 | return roccat_common2_send_with_status(usb_dev, |
Stefan Achatz | 4728f2d | 2012-05-20 22:44:59 +0200 | [diff] [blame] | 106 | KONEPLUS_COMMAND_PROFILE_BUTTONS, |
Stefan Achatz | 5772f63 | 2011-01-30 13:38:23 +0100 | [diff] [blame] | 107 | buttons, sizeof(struct koneplus_profile_buttons)); |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | /* retval is 0-4 on success, < 0 on error */ |
Stefan Achatz | b50f315 | 2011-04-13 17:17:52 +0200 | [diff] [blame] | 111 | static int koneplus_get_actual_profile(struct usb_device *usb_dev) |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 112 | { |
Stefan Achatz | b50f315 | 2011-04-13 17:17:52 +0200 | [diff] [blame] | 113 | struct koneplus_actual_profile buf; |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 114 | int retval; |
| 115 | |
Stefan Achatz | 7392d73 | 2012-05-20 22:45:04 +0200 | [diff] [blame] | 116 | retval = roccat_common2_receive(usb_dev, KONEPLUS_COMMAND_ACTUAL_PROFILE, |
Stefan Achatz | b50f315 | 2011-04-13 17:17:52 +0200 | [diff] [blame] | 117 | &buf, sizeof(struct koneplus_actual_profile)); |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 118 | |
Stefan Achatz | b50f315 | 2011-04-13 17:17:52 +0200 | [diff] [blame] | 119 | return retval ? retval : buf.actual_profile; |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 120 | } |
| 121 | |
Stefan Achatz | b50f315 | 2011-04-13 17:17:52 +0200 | [diff] [blame] | 122 | static int koneplus_set_actual_profile(struct usb_device *usb_dev, |
| 123 | int new_profile) |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 124 | { |
Stefan Achatz | b50f315 | 2011-04-13 17:17:52 +0200 | [diff] [blame] | 125 | struct koneplus_actual_profile buf; |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 126 | |
Stefan Achatz | b50f315 | 2011-04-13 17:17:52 +0200 | [diff] [blame] | 127 | buf.command = KONEPLUS_COMMAND_ACTUAL_PROFILE; |
| 128 | buf.size = sizeof(struct koneplus_actual_profile); |
| 129 | buf.actual_profile = new_profile; |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 130 | |
Stefan Achatz | 7392d73 | 2012-05-20 22:45:04 +0200 | [diff] [blame] | 131 | return roccat_common2_send_with_status(usb_dev, |
Stefan Achatz | 4728f2d | 2012-05-20 22:44:59 +0200 | [diff] [blame] | 132 | KONEPLUS_COMMAND_ACTUAL_PROFILE, |
Stefan Achatz | b50f315 | 2011-04-13 17:17:52 +0200 | [diff] [blame] | 133 | &buf, sizeof(struct koneplus_actual_profile)); |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | static ssize_t koneplus_sysfs_read(struct file *fp, struct kobject *kobj, |
| 137 | char *buf, loff_t off, size_t count, |
| 138 | size_t real_size, uint command) |
| 139 | { |
| 140 | struct device *dev = |
| 141 | container_of(kobj, struct device, kobj)->parent->parent; |
| 142 | struct koneplus_device *koneplus = hid_get_drvdata(dev_get_drvdata(dev)); |
| 143 | struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); |
| 144 | int retval; |
| 145 | |
Stefan Achatz | fd82be6 | 2011-01-06 09:00:41 +0100 | [diff] [blame] | 146 | if (off >= real_size) |
| 147 | return 0; |
| 148 | |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 149 | if (off != 0 || count != real_size) |
| 150 | return -EINVAL; |
| 151 | |
| 152 | mutex_lock(&koneplus->koneplus_lock); |
Stefan Achatz | 7392d73 | 2012-05-20 22:45:04 +0200 | [diff] [blame] | 153 | retval = roccat_common2_receive(usb_dev, command, buf, real_size); |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 154 | mutex_unlock(&koneplus->koneplus_lock); |
| 155 | |
| 156 | if (retval) |
| 157 | return retval; |
| 158 | |
| 159 | return real_size; |
| 160 | } |
| 161 | |
| 162 | static ssize_t koneplus_sysfs_write(struct file *fp, struct kobject *kobj, |
| 163 | void const *buf, loff_t off, size_t count, |
| 164 | size_t real_size, uint command) |
| 165 | { |
| 166 | struct device *dev = |
| 167 | container_of(kobj, struct device, kobj)->parent->parent; |
| 168 | struct koneplus_device *koneplus = hid_get_drvdata(dev_get_drvdata(dev)); |
| 169 | struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); |
| 170 | int retval; |
| 171 | |
| 172 | if (off != 0 || count != real_size) |
| 173 | return -EINVAL; |
| 174 | |
| 175 | mutex_lock(&koneplus->koneplus_lock); |
Stefan Achatz | 7392d73 | 2012-05-20 22:45:04 +0200 | [diff] [blame] | 176 | retval = roccat_common2_send_with_status(usb_dev, command, |
Stefan Achatz | 4728f2d | 2012-05-20 22:44:59 +0200 | [diff] [blame] | 177 | buf, real_size); |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 178 | mutex_unlock(&koneplus->koneplus_lock); |
| 179 | |
| 180 | if (retval) |
| 181 | return retval; |
| 182 | |
| 183 | return real_size; |
| 184 | } |
| 185 | |
Stefan Achatz | 6d1dec8 | 2011-05-29 19:32:57 +0200 | [diff] [blame] | 186 | static ssize_t koneplus_sysfs_write_talk(struct file *fp, |
| 187 | struct kobject *kobj, struct bin_attribute *attr, char *buf, |
| 188 | loff_t off, size_t count) |
| 189 | { |
| 190 | return koneplus_sysfs_write(fp, kobj, buf, off, count, |
Stefan Achatz | 1edd5b4 | 2011-06-01 15:54:17 +0200 | [diff] [blame] | 191 | sizeof(struct koneplus_talk), KONEPLUS_COMMAND_TALK); |
Stefan Achatz | 6d1dec8 | 2011-05-29 19:32:57 +0200 | [diff] [blame] | 192 | } |
| 193 | |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 194 | static ssize_t koneplus_sysfs_write_macro(struct file *fp, |
| 195 | struct kobject *kobj, struct bin_attribute *attr, char *buf, |
| 196 | loff_t off, size_t count) |
| 197 | { |
| 198 | return koneplus_sysfs_write(fp, kobj, buf, off, count, |
Stefan Achatz | 1edd5b4 | 2011-06-01 15:54:17 +0200 | [diff] [blame] | 199 | sizeof(struct koneplus_macro), KONEPLUS_COMMAND_MACRO); |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | static ssize_t koneplus_sysfs_read_sensor(struct file *fp, |
| 203 | struct kobject *kobj, struct bin_attribute *attr, char *buf, |
| 204 | loff_t off, size_t count) |
| 205 | { |
| 206 | return koneplus_sysfs_read(fp, kobj, buf, off, count, |
Stefan Achatz | 1edd5b4 | 2011-06-01 15:54:17 +0200 | [diff] [blame] | 207 | sizeof(struct koneplus_sensor), KONEPLUS_COMMAND_SENSOR); |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | static ssize_t koneplus_sysfs_write_sensor(struct file *fp, |
| 211 | struct kobject *kobj, struct bin_attribute *attr, char *buf, |
| 212 | loff_t off, size_t count) |
| 213 | { |
| 214 | return koneplus_sysfs_write(fp, kobj, buf, off, count, |
Stefan Achatz | 1edd5b4 | 2011-06-01 15:54:17 +0200 | [diff] [blame] | 215 | sizeof(struct koneplus_sensor), KONEPLUS_COMMAND_SENSOR); |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | static ssize_t koneplus_sysfs_write_tcu(struct file *fp, |
| 219 | struct kobject *kobj, struct bin_attribute *attr, char *buf, |
| 220 | loff_t off, size_t count) |
| 221 | { |
| 222 | return koneplus_sysfs_write(fp, kobj, buf, off, count, |
Stefan Achatz | 1edd5b4 | 2011-06-01 15:54:17 +0200 | [diff] [blame] | 223 | sizeof(struct koneplus_tcu), KONEPLUS_COMMAND_TCU); |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 224 | } |
| 225 | |
Stefan Achatz | 5277e97 | 2012-10-17 16:35:42 +0200 | [diff] [blame] | 226 | static ssize_t koneplus_sysfs_read_tcu(struct file *fp, |
| 227 | struct kobject *kobj, struct bin_attribute *attr, char *buf, |
| 228 | loff_t off, size_t count) |
| 229 | { |
| 230 | return koneplus_sysfs_read(fp, kobj, buf, off, count, |
| 231 | sizeof(struct koneplus_tcu), KONEPLUS_COMMAND_TCU); |
| 232 | } |
| 233 | |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 234 | static ssize_t koneplus_sysfs_read_tcu_image(struct file *fp, |
| 235 | struct kobject *kobj, struct bin_attribute *attr, char *buf, |
| 236 | loff_t off, size_t count) |
| 237 | { |
| 238 | return koneplus_sysfs_read(fp, kobj, buf, off, count, |
Stefan Achatz | 1edd5b4 | 2011-06-01 15:54:17 +0200 | [diff] [blame] | 239 | sizeof(struct koneplus_tcu_image), KONEPLUS_COMMAND_TCU); |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | static ssize_t koneplus_sysfs_read_profilex_settings(struct file *fp, |
| 243 | struct kobject *kobj, struct bin_attribute *attr, char *buf, |
| 244 | loff_t off, size_t count) |
| 245 | { |
| 246 | struct device *dev = |
| 247 | container_of(kobj, struct device, kobj)->parent->parent; |
| 248 | struct koneplus_device *koneplus = hid_get_drvdata(dev_get_drvdata(dev)); |
| 249 | |
| 250 | if (off >= sizeof(struct koneplus_profile_settings)) |
| 251 | return 0; |
| 252 | |
| 253 | if (off + count > sizeof(struct koneplus_profile_settings)) |
| 254 | count = sizeof(struct koneplus_profile_settings) - off; |
| 255 | |
| 256 | mutex_lock(&koneplus->koneplus_lock); |
Stefan Achatz | 5772f63 | 2011-01-30 13:38:23 +0100 | [diff] [blame] | 257 | memcpy(buf, ((char const *)&koneplus->profile_settings[*(uint *)(attr->private)]) + off, |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 258 | count); |
| 259 | mutex_unlock(&koneplus->koneplus_lock); |
| 260 | |
| 261 | return count; |
| 262 | } |
| 263 | |
| 264 | static ssize_t koneplus_sysfs_write_profile_settings(struct file *fp, |
| 265 | struct kobject *kobj, struct bin_attribute *attr, char *buf, |
| 266 | loff_t off, size_t count) |
| 267 | { |
| 268 | struct device *dev = |
| 269 | container_of(kobj, struct device, kobj)->parent->parent; |
| 270 | struct koneplus_device *koneplus = hid_get_drvdata(dev_get_drvdata(dev)); |
| 271 | struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); |
| 272 | int retval = 0; |
| 273 | int difference; |
| 274 | int profile_number; |
| 275 | struct koneplus_profile_settings *profile_settings; |
| 276 | |
| 277 | if (off != 0 || count != sizeof(struct koneplus_profile_settings)) |
| 278 | return -EINVAL; |
| 279 | |
| 280 | profile_number = ((struct koneplus_profile_settings const *)buf)->number; |
| 281 | profile_settings = &koneplus->profile_settings[profile_number]; |
| 282 | |
| 283 | mutex_lock(&koneplus->koneplus_lock); |
| 284 | difference = memcmp(buf, profile_settings, |
| 285 | sizeof(struct koneplus_profile_settings)); |
| 286 | if (difference) { |
| 287 | retval = koneplus_set_profile_settings(usb_dev, |
| 288 | (struct koneplus_profile_settings const *)buf); |
| 289 | if (!retval) |
| 290 | memcpy(profile_settings, buf, |
| 291 | sizeof(struct koneplus_profile_settings)); |
| 292 | } |
| 293 | mutex_unlock(&koneplus->koneplus_lock); |
| 294 | |
| 295 | if (retval) |
| 296 | return retval; |
| 297 | |
| 298 | return sizeof(struct koneplus_profile_settings); |
| 299 | } |
| 300 | |
| 301 | static ssize_t koneplus_sysfs_read_profilex_buttons(struct file *fp, |
| 302 | struct kobject *kobj, struct bin_attribute *attr, char *buf, |
| 303 | loff_t off, size_t count) |
| 304 | { |
| 305 | struct device *dev = |
| 306 | container_of(kobj, struct device, kobj)->parent->parent; |
| 307 | struct koneplus_device *koneplus = hid_get_drvdata(dev_get_drvdata(dev)); |
| 308 | |
| 309 | if (off >= sizeof(struct koneplus_profile_buttons)) |
| 310 | return 0; |
| 311 | |
| 312 | if (off + count > sizeof(struct koneplus_profile_buttons)) |
| 313 | count = sizeof(struct koneplus_profile_buttons) - off; |
| 314 | |
| 315 | mutex_lock(&koneplus->koneplus_lock); |
Stefan Achatz | 5772f63 | 2011-01-30 13:38:23 +0100 | [diff] [blame] | 316 | memcpy(buf, ((char const *)&koneplus->profile_buttons[*(uint *)(attr->private)]) + off, |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 317 | count); |
| 318 | mutex_unlock(&koneplus->koneplus_lock); |
| 319 | |
| 320 | return count; |
| 321 | } |
| 322 | |
| 323 | static ssize_t koneplus_sysfs_write_profile_buttons(struct file *fp, |
| 324 | struct kobject *kobj, struct bin_attribute *attr, char *buf, |
| 325 | loff_t off, size_t count) |
| 326 | { |
| 327 | struct device *dev = |
| 328 | container_of(kobj, struct device, kobj)->parent->parent; |
| 329 | struct koneplus_device *koneplus = hid_get_drvdata(dev_get_drvdata(dev)); |
| 330 | struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); |
| 331 | int retval = 0; |
| 332 | int difference; |
| 333 | uint profile_number; |
| 334 | struct koneplus_profile_buttons *profile_buttons; |
| 335 | |
| 336 | if (off != 0 || count != sizeof(struct koneplus_profile_buttons)) |
| 337 | return -EINVAL; |
| 338 | |
| 339 | profile_number = ((struct koneplus_profile_buttons const *)buf)->number; |
| 340 | profile_buttons = &koneplus->profile_buttons[profile_number]; |
| 341 | |
| 342 | mutex_lock(&koneplus->koneplus_lock); |
| 343 | difference = memcmp(buf, profile_buttons, |
| 344 | sizeof(struct koneplus_profile_buttons)); |
| 345 | if (difference) { |
| 346 | retval = koneplus_set_profile_buttons(usb_dev, |
| 347 | (struct koneplus_profile_buttons const *)buf); |
| 348 | if (!retval) |
| 349 | memcpy(profile_buttons, buf, |
| 350 | sizeof(struct koneplus_profile_buttons)); |
| 351 | } |
| 352 | mutex_unlock(&koneplus->koneplus_lock); |
| 353 | |
| 354 | if (retval) |
| 355 | return retval; |
| 356 | |
| 357 | return sizeof(struct koneplus_profile_buttons); |
| 358 | } |
| 359 | |
Stefan Achatz | b50f315 | 2011-04-13 17:17:52 +0200 | [diff] [blame] | 360 | static ssize_t koneplus_sysfs_show_actual_profile(struct device *dev, |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 361 | struct device_attribute *attr, char *buf) |
| 362 | { |
| 363 | struct koneplus_device *koneplus = |
| 364 | hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); |
Stefan Achatz | b50f315 | 2011-04-13 17:17:52 +0200 | [diff] [blame] | 365 | return snprintf(buf, PAGE_SIZE, "%d\n", koneplus->actual_profile); |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 366 | } |
| 367 | |
Stefan Achatz | b50f315 | 2011-04-13 17:17:52 +0200 | [diff] [blame] | 368 | static ssize_t koneplus_sysfs_set_actual_profile(struct device *dev, |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 369 | struct device_attribute *attr, char const *buf, size_t size) |
| 370 | { |
| 371 | struct koneplus_device *koneplus; |
| 372 | struct usb_device *usb_dev; |
| 373 | unsigned long profile; |
| 374 | int retval; |
Stefan Achatz | b50f315 | 2011-04-13 17:17:52 +0200 | [diff] [blame] | 375 | struct koneplus_roccat_report roccat_report; |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 376 | |
| 377 | dev = dev->parent->parent; |
| 378 | koneplus = hid_get_drvdata(dev_get_drvdata(dev)); |
| 379 | usb_dev = interface_to_usbdev(to_usb_interface(dev)); |
| 380 | |
| 381 | retval = strict_strtoul(buf, 10, &profile); |
| 382 | if (retval) |
| 383 | return retval; |
| 384 | |
Stefan Achatz | 901e64d | 2011-06-12 10:02:44 +0200 | [diff] [blame] | 385 | if (profile > 4) |
| 386 | return -EINVAL; |
| 387 | |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 388 | mutex_lock(&koneplus->koneplus_lock); |
Stefan Achatz | b50f315 | 2011-04-13 17:17:52 +0200 | [diff] [blame] | 389 | |
| 390 | retval = koneplus_set_actual_profile(usb_dev, profile); |
| 391 | if (retval) { |
| 392 | mutex_unlock(&koneplus->koneplus_lock); |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 393 | return retval; |
Stefan Achatz | b50f315 | 2011-04-13 17:17:52 +0200 | [diff] [blame] | 394 | } |
| 395 | |
Stefan Achatz | 901e64d | 2011-06-12 10:02:44 +0200 | [diff] [blame] | 396 | koneplus_profile_activated(koneplus, profile); |
Stefan Achatz | b50f315 | 2011-04-13 17:17:52 +0200 | [diff] [blame] | 397 | |
| 398 | roccat_report.type = KONEPLUS_MOUSE_REPORT_BUTTON_TYPE_PROFILE; |
| 399 | roccat_report.data1 = profile + 1; |
| 400 | roccat_report.data2 = 0; |
| 401 | roccat_report.profile = profile + 1; |
| 402 | roccat_report_event(koneplus->chrdev_minor, |
| 403 | (uint8_t const *)&roccat_report); |
| 404 | |
| 405 | mutex_unlock(&koneplus->koneplus_lock); |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 406 | |
| 407 | return size; |
| 408 | } |
| 409 | |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 410 | static ssize_t koneplus_sysfs_show_firmware_version(struct device *dev, |
| 411 | struct device_attribute *attr, char *buf) |
| 412 | { |
| 413 | struct koneplus_device *koneplus = |
| 414 | hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); |
| 415 | return snprintf(buf, PAGE_SIZE, "%d\n", koneplus->info.firmware_version); |
| 416 | } |
| 417 | |
| 418 | static struct device_attribute koneplus_attributes[] = { |
Stefan Achatz | b50f315 | 2011-04-13 17:17:52 +0200 | [diff] [blame] | 419 | __ATTR(actual_profile, 0660, |
| 420 | koneplus_sysfs_show_actual_profile, |
| 421 | koneplus_sysfs_set_actual_profile), |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 422 | __ATTR(startup_profile, 0660, |
Stefan Achatz | b50f315 | 2011-04-13 17:17:52 +0200 | [diff] [blame] | 423 | koneplus_sysfs_show_actual_profile, |
| 424 | koneplus_sysfs_set_actual_profile), |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 425 | __ATTR(firmware_version, 0440, |
| 426 | koneplus_sysfs_show_firmware_version, NULL), |
| 427 | __ATTR_NULL |
| 428 | }; |
| 429 | |
| 430 | static struct bin_attribute koneplus_bin_attributes[] = { |
| 431 | { |
Stefan Achatz | 61c29f5 | 2011-03-14 21:43:07 +0100 | [diff] [blame] | 432 | .attr = { .name = "sensor", .mode = 0660 }, |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 433 | .size = sizeof(struct koneplus_sensor), |
| 434 | .read = koneplus_sysfs_read_sensor, |
| 435 | .write = koneplus_sysfs_write_sensor |
| 436 | }, |
| 437 | { |
Stefan Achatz | 5277e97 | 2012-10-17 16:35:42 +0200 | [diff] [blame] | 438 | .attr = { .name = "tcu", .mode = 0660 }, |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 439 | .size = sizeof(struct koneplus_tcu), |
Stefan Achatz | 5277e97 | 2012-10-17 16:35:42 +0200 | [diff] [blame] | 440 | .read = koneplus_sysfs_read_tcu, |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 441 | .write = koneplus_sysfs_write_tcu |
| 442 | }, |
| 443 | { |
| 444 | .attr = { .name = "tcu_image", .mode = 0440 }, |
| 445 | .size = sizeof(struct koneplus_tcu_image), |
| 446 | .read = koneplus_sysfs_read_tcu_image |
| 447 | }, |
| 448 | { |
| 449 | .attr = { .name = "profile_settings", .mode = 0220 }, |
| 450 | .size = sizeof(struct koneplus_profile_settings), |
| 451 | .write = koneplus_sysfs_write_profile_settings |
| 452 | }, |
| 453 | { |
| 454 | .attr = { .name = "profile1_settings", .mode = 0440 }, |
| 455 | .size = sizeof(struct koneplus_profile_settings), |
| 456 | .read = koneplus_sysfs_read_profilex_settings, |
| 457 | .private = &profile_numbers[0] |
| 458 | }, |
| 459 | { |
| 460 | .attr = { .name = "profile2_settings", .mode = 0440 }, |
| 461 | .size = sizeof(struct koneplus_profile_settings), |
| 462 | .read = koneplus_sysfs_read_profilex_settings, |
| 463 | .private = &profile_numbers[1] |
| 464 | }, |
| 465 | { |
| 466 | .attr = { .name = "profile3_settings", .mode = 0440 }, |
| 467 | .size = sizeof(struct koneplus_profile_settings), |
| 468 | .read = koneplus_sysfs_read_profilex_settings, |
| 469 | .private = &profile_numbers[2] |
| 470 | }, |
| 471 | { |
| 472 | .attr = { .name = "profile4_settings", .mode = 0440 }, |
| 473 | .size = sizeof(struct koneplus_profile_settings), |
| 474 | .read = koneplus_sysfs_read_profilex_settings, |
| 475 | .private = &profile_numbers[3] |
| 476 | }, |
| 477 | { |
| 478 | .attr = { .name = "profile5_settings", .mode = 0440 }, |
| 479 | .size = sizeof(struct koneplus_profile_settings), |
| 480 | .read = koneplus_sysfs_read_profilex_settings, |
| 481 | .private = &profile_numbers[4] |
| 482 | }, |
| 483 | { |
| 484 | .attr = { .name = "profile_buttons", .mode = 0220 }, |
| 485 | .size = sizeof(struct koneplus_profile_buttons), |
| 486 | .write = koneplus_sysfs_write_profile_buttons |
| 487 | }, |
| 488 | { |
| 489 | .attr = { .name = "profile1_buttons", .mode = 0440 }, |
| 490 | .size = sizeof(struct koneplus_profile_buttons), |
| 491 | .read = koneplus_sysfs_read_profilex_buttons, |
| 492 | .private = &profile_numbers[0] |
| 493 | }, |
| 494 | { |
| 495 | .attr = { .name = "profile2_buttons", .mode = 0440 }, |
| 496 | .size = sizeof(struct koneplus_profile_buttons), |
| 497 | .read = koneplus_sysfs_read_profilex_buttons, |
| 498 | .private = &profile_numbers[1] |
| 499 | }, |
| 500 | { |
| 501 | .attr = { .name = "profile3_buttons", .mode = 0440 }, |
| 502 | .size = sizeof(struct koneplus_profile_buttons), |
| 503 | .read = koneplus_sysfs_read_profilex_buttons, |
| 504 | .private = &profile_numbers[2] |
| 505 | }, |
| 506 | { |
| 507 | .attr = { .name = "profile4_buttons", .mode = 0440 }, |
| 508 | .size = sizeof(struct koneplus_profile_buttons), |
| 509 | .read = koneplus_sysfs_read_profilex_buttons, |
| 510 | .private = &profile_numbers[3] |
| 511 | }, |
| 512 | { |
| 513 | .attr = { .name = "profile5_buttons", .mode = 0440 }, |
| 514 | .size = sizeof(struct koneplus_profile_buttons), |
| 515 | .read = koneplus_sysfs_read_profilex_buttons, |
| 516 | .private = &profile_numbers[4] |
| 517 | }, |
| 518 | { |
| 519 | .attr = { .name = "macro", .mode = 0220 }, |
| 520 | .size = sizeof(struct koneplus_macro), |
| 521 | .write = koneplus_sysfs_write_macro |
| 522 | }, |
Stefan Achatz | 6d1dec8 | 2011-05-29 19:32:57 +0200 | [diff] [blame] | 523 | { |
| 524 | .attr = { .name = "talk", .mode = 0220 }, |
| 525 | .size = sizeof(struct koneplus_talk), |
| 526 | .write = koneplus_sysfs_write_talk |
| 527 | }, |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 528 | __ATTR_NULL |
| 529 | }; |
| 530 | |
| 531 | static int koneplus_init_koneplus_device_struct(struct usb_device *usb_dev, |
| 532 | struct koneplus_device *koneplus) |
| 533 | { |
| 534 | int retval, i; |
Stefan Achatz | b50f315 | 2011-04-13 17:17:52 +0200 | [diff] [blame] | 535 | static uint wait = 200; |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 536 | |
| 537 | mutex_init(&koneplus->koneplus_lock); |
| 538 | |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 539 | retval = koneplus_get_info(usb_dev, &koneplus->info); |
| 540 | if (retval) |
| 541 | return retval; |
| 542 | |
| 543 | for (i = 0; i < 5; ++i) { |
| 544 | msleep(wait); |
| 545 | retval = koneplus_get_profile_settings(usb_dev, |
| 546 | &koneplus->profile_settings[i], i); |
| 547 | if (retval) |
| 548 | return retval; |
| 549 | |
| 550 | msleep(wait); |
| 551 | retval = koneplus_get_profile_buttons(usb_dev, |
| 552 | &koneplus->profile_buttons[i], i); |
| 553 | if (retval) |
| 554 | return retval; |
| 555 | } |
| 556 | |
Stefan Achatz | b50f315 | 2011-04-13 17:17:52 +0200 | [diff] [blame] | 557 | msleep(wait); |
| 558 | retval = koneplus_get_actual_profile(usb_dev); |
| 559 | if (retval < 0) |
| 560 | return retval; |
| 561 | koneplus_profile_activated(koneplus, retval); |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 562 | |
| 563 | return 0; |
| 564 | } |
| 565 | |
| 566 | static int koneplus_init_specials(struct hid_device *hdev) |
| 567 | { |
| 568 | struct usb_interface *intf = to_usb_interface(hdev->dev.parent); |
| 569 | struct usb_device *usb_dev = interface_to_usbdev(intf); |
| 570 | struct koneplus_device *koneplus; |
| 571 | int retval; |
| 572 | |
| 573 | if (intf->cur_altsetting->desc.bInterfaceProtocol |
| 574 | == USB_INTERFACE_PROTOCOL_MOUSE) { |
| 575 | |
| 576 | koneplus = kzalloc(sizeof(*koneplus), GFP_KERNEL); |
| 577 | if (!koneplus) { |
Stefan Achatz | a28764e | 2011-01-30 13:38:21 +0100 | [diff] [blame] | 578 | hid_err(hdev, "can't alloc device descriptor\n"); |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 579 | return -ENOMEM; |
| 580 | } |
| 581 | hid_set_drvdata(hdev, koneplus); |
| 582 | |
| 583 | retval = koneplus_init_koneplus_device_struct(usb_dev, koneplus); |
| 584 | if (retval) { |
Stefan Achatz | a28764e | 2011-01-30 13:38:21 +0100 | [diff] [blame] | 585 | hid_err(hdev, "couldn't init struct koneplus_device\n"); |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 586 | goto exit_free; |
| 587 | } |
| 588 | |
Stefan Achatz | 8211e46 | 2011-01-30 13:38:25 +0100 | [diff] [blame] | 589 | retval = roccat_connect(koneplus_class, hdev, |
| 590 | sizeof(struct koneplus_roccat_report)); |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 591 | if (retval < 0) { |
Stefan Achatz | a28764e | 2011-01-30 13:38:21 +0100 | [diff] [blame] | 592 | hid_err(hdev, "couldn't init char dev\n"); |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 593 | } else { |
| 594 | koneplus->chrdev_minor = retval; |
| 595 | koneplus->roccat_claimed = 1; |
| 596 | } |
| 597 | } else { |
| 598 | hid_set_drvdata(hdev, NULL); |
| 599 | } |
| 600 | |
| 601 | return 0; |
| 602 | exit_free: |
| 603 | kfree(koneplus); |
| 604 | return retval; |
| 605 | } |
| 606 | |
| 607 | static void koneplus_remove_specials(struct hid_device *hdev) |
| 608 | { |
| 609 | struct usb_interface *intf = to_usb_interface(hdev->dev.parent); |
| 610 | struct koneplus_device *koneplus; |
| 611 | |
| 612 | if (intf->cur_altsetting->desc.bInterfaceProtocol |
| 613 | == USB_INTERFACE_PROTOCOL_MOUSE) { |
| 614 | koneplus = hid_get_drvdata(hdev); |
| 615 | if (koneplus->roccat_claimed) |
| 616 | roccat_disconnect(koneplus->chrdev_minor); |
| 617 | kfree(koneplus); |
| 618 | } |
| 619 | } |
| 620 | |
| 621 | static int koneplus_probe(struct hid_device *hdev, |
| 622 | const struct hid_device_id *id) |
| 623 | { |
| 624 | int retval; |
| 625 | |
| 626 | retval = hid_parse(hdev); |
| 627 | if (retval) { |
Stefan Achatz | a28764e | 2011-01-30 13:38:21 +0100 | [diff] [blame] | 628 | hid_err(hdev, "parse failed\n"); |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 629 | goto exit; |
| 630 | } |
| 631 | |
| 632 | retval = hid_hw_start(hdev, HID_CONNECT_DEFAULT); |
| 633 | if (retval) { |
Stefan Achatz | a28764e | 2011-01-30 13:38:21 +0100 | [diff] [blame] | 634 | hid_err(hdev, "hw start failed\n"); |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 635 | goto exit; |
| 636 | } |
| 637 | |
| 638 | retval = koneplus_init_specials(hdev); |
| 639 | if (retval) { |
Stefan Achatz | a28764e | 2011-01-30 13:38:21 +0100 | [diff] [blame] | 640 | hid_err(hdev, "couldn't install mouse\n"); |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 641 | goto exit_stop; |
| 642 | } |
| 643 | |
| 644 | return 0; |
| 645 | |
| 646 | exit_stop: |
| 647 | hid_hw_stop(hdev); |
| 648 | exit: |
| 649 | return retval; |
| 650 | } |
| 651 | |
| 652 | static void koneplus_remove(struct hid_device *hdev) |
| 653 | { |
| 654 | koneplus_remove_specials(hdev); |
| 655 | hid_hw_stop(hdev); |
| 656 | } |
| 657 | |
| 658 | static void koneplus_keep_values_up_to_date(struct koneplus_device *koneplus, |
| 659 | u8 const *data) |
| 660 | { |
| 661 | struct koneplus_mouse_report_button const *button_report; |
| 662 | |
| 663 | switch (data[0]) { |
| 664 | case KONEPLUS_MOUSE_REPORT_NUMBER_BUTTON: |
| 665 | button_report = (struct koneplus_mouse_report_button const *)data; |
| 666 | switch (button_report->type) { |
| 667 | case KONEPLUS_MOUSE_REPORT_BUTTON_TYPE_PROFILE: |
| 668 | koneplus_profile_activated(koneplus, button_report->data1 - 1); |
| 669 | break; |
| 670 | } |
| 671 | break; |
| 672 | } |
| 673 | } |
| 674 | |
| 675 | static void koneplus_report_to_chrdev(struct koneplus_device const *koneplus, |
| 676 | u8 const *data) |
| 677 | { |
| 678 | struct koneplus_roccat_report roccat_report; |
| 679 | struct koneplus_mouse_report_button const *button_report; |
| 680 | |
| 681 | if (data[0] != KONEPLUS_MOUSE_REPORT_NUMBER_BUTTON) |
| 682 | return; |
| 683 | |
| 684 | button_report = (struct koneplus_mouse_report_button const *)data; |
| 685 | |
| 686 | if ((button_report->type == KONEPLUS_MOUSE_REPORT_BUTTON_TYPE_QUICKLAUNCH || |
| 687 | button_report->type == KONEPLUS_MOUSE_REPORT_BUTTON_TYPE_TIMER) && |
| 688 | button_report->data2 != KONEPLUS_MOUSE_REPORT_BUTTON_ACTION_PRESS) |
| 689 | return; |
| 690 | |
| 691 | roccat_report.type = button_report->type; |
| 692 | roccat_report.data1 = button_report->data1; |
| 693 | roccat_report.data2 = button_report->data2; |
| 694 | roccat_report.profile = koneplus->actual_profile + 1; |
| 695 | roccat_report_event(koneplus->chrdev_minor, |
Stefan Achatz | 8211e46 | 2011-01-30 13:38:25 +0100 | [diff] [blame] | 696 | (uint8_t const *)&roccat_report); |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | static int koneplus_raw_event(struct hid_device *hdev, |
| 700 | struct hid_report *report, u8 *data, int size) |
| 701 | { |
| 702 | struct usb_interface *intf = to_usb_interface(hdev->dev.parent); |
| 703 | struct koneplus_device *koneplus = hid_get_drvdata(hdev); |
| 704 | |
| 705 | if (intf->cur_altsetting->desc.bInterfaceProtocol |
| 706 | != USB_INTERFACE_PROTOCOL_MOUSE) |
| 707 | return 0; |
| 708 | |
Stefan Achatz | 901e64d | 2011-06-12 10:02:44 +0200 | [diff] [blame] | 709 | if (koneplus == NULL) |
| 710 | return 0; |
| 711 | |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 712 | koneplus_keep_values_up_to_date(koneplus, data); |
| 713 | |
| 714 | if (koneplus->roccat_claimed) |
| 715 | koneplus_report_to_chrdev(koneplus, data); |
| 716 | |
| 717 | return 0; |
| 718 | } |
| 719 | |
| 720 | static const struct hid_device_id koneplus_devices[] = { |
| 721 | { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPLUS) }, |
Stefan Achatz | 8e74a2d | 2012-11-04 09:38:52 +0100 | [diff] [blame^] | 722 | { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEXTD) }, |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 723 | { } |
| 724 | }; |
| 725 | |
| 726 | MODULE_DEVICE_TABLE(hid, koneplus_devices); |
| 727 | |
| 728 | static struct hid_driver koneplus_driver = { |
| 729 | .name = "koneplus", |
| 730 | .id_table = koneplus_devices, |
| 731 | .probe = koneplus_probe, |
| 732 | .remove = koneplus_remove, |
| 733 | .raw_event = koneplus_raw_event |
| 734 | }; |
| 735 | |
| 736 | static int __init koneplus_init(void) |
| 737 | { |
| 738 | int retval; |
| 739 | |
| 740 | /* class name has to be same as driver name */ |
| 741 | koneplus_class = class_create(THIS_MODULE, "koneplus"); |
| 742 | if (IS_ERR(koneplus_class)) |
| 743 | return PTR_ERR(koneplus_class); |
| 744 | koneplus_class->dev_attrs = koneplus_attributes; |
| 745 | koneplus_class->dev_bin_attrs = koneplus_bin_attributes; |
| 746 | |
| 747 | retval = hid_register_driver(&koneplus_driver); |
| 748 | if (retval) |
| 749 | class_destroy(koneplus_class); |
| 750 | return retval; |
| 751 | } |
| 752 | |
| 753 | static void __exit koneplus_exit(void) |
| 754 | { |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 755 | hid_unregister_driver(&koneplus_driver); |
Stefan Achatz | 74b643d | 2011-01-30 13:38:27 +0100 | [diff] [blame] | 756 | class_destroy(koneplus_class); |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 757 | } |
| 758 | |
| 759 | module_init(koneplus_init); |
| 760 | module_exit(koneplus_exit); |
| 761 | |
| 762 | MODULE_AUTHOR("Stefan Achatz"); |
Stefan Achatz | 8e74a2d | 2012-11-04 09:38:52 +0100 | [diff] [blame^] | 763 | MODULE_DESCRIPTION("USB Roccat Kone[+]/XTD driver"); |
Stefan Achatz | 47dbdbff | 2010-11-26 19:57:42 +0000 | [diff] [blame] | 764 | MODULE_LICENSE("GPL v2"); |