Rafi Rubin | 94011f9 | 2008-11-19 15:54:46 +0100 | [diff] [blame] | 1 | /* |
Stephane Chatty | 57fd637 | 2009-05-20 15:49:35 +0200 | [diff] [blame] | 2 | * HID driver for N-Trig touchscreens |
Rafi Rubin | 94011f9 | 2008-11-19 15:54:46 +0100 | [diff] [blame] | 3 | * |
Stephane Chatty | 6549981 | 2010-04-06 22:22:58 +0200 | [diff] [blame] | 4 | * Copyright (c) 2008-2010 Rafi Rubin |
| 5 | * Copyright (c) 2009-2010 Stephane Chatty |
Rafi Rubin | 94011f9 | 2008-11-19 15:54:46 +0100 | [diff] [blame] | 6 | * |
| 7 | */ |
| 8 | |
| 9 | /* |
| 10 | * This program is free software; you can redistribute it and/or modify it |
| 11 | * under the terms of the GNU General Public License as published by the Free |
| 12 | * Software Foundation; either version 2 of the License, or (at your option) |
| 13 | * any later version. |
| 14 | */ |
| 15 | |
| 16 | #include <linux/device.h> |
| 17 | #include <linux/hid.h> |
Stephane Chatty | 6549981 | 2010-04-06 22:22:58 +0200 | [diff] [blame] | 18 | #include <linux/usb.h> |
| 19 | #include "usbhid/usbhid.h" |
Rafi Rubin | 94011f9 | 2008-11-19 15:54:46 +0100 | [diff] [blame] | 20 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 21 | #include <linux/slab.h> |
Rafi Rubin | 94011f9 | 2008-11-19 15:54:46 +0100 | [diff] [blame] | 22 | |
| 23 | #include "hid-ids.h" |
| 24 | |
| 25 | #define NTRIG_DUPLICATE_USAGES 0x001 |
| 26 | |
Rafi Rubin | 369db2a | 2010-05-04 14:20:15 -0400 | [diff] [blame] | 27 | static unsigned int min_width; |
Rafi Rubin | ab3f498 | 2010-05-04 14:20:16 -0400 | [diff] [blame] | 28 | module_param(min_width, uint, 0644); |
| 29 | MODULE_PARM_DESC(min_width, "Minimum touch contact width to accept."); |
| 30 | |
Rafi Rubin | 369db2a | 2010-05-04 14:20:15 -0400 | [diff] [blame] | 31 | static unsigned int min_height; |
Rafi Rubin | ab3f498 | 2010-05-04 14:20:16 -0400 | [diff] [blame] | 32 | module_param(min_height, uint, 0644); |
| 33 | MODULE_PARM_DESC(min_height, "Minimum touch contact height to accept."); |
| 34 | |
Rafi Rubin | 369db2a | 2010-05-04 14:20:15 -0400 | [diff] [blame] | 35 | static unsigned int activate_slack = 1; |
Rafi Rubin | ab3f498 | 2010-05-04 14:20:16 -0400 | [diff] [blame] | 36 | module_param(activate_slack, uint, 0644); |
| 37 | MODULE_PARM_DESC(activate_slack, "Number of touch frames to ignore at " |
| 38 | "the start of touch input."); |
| 39 | |
Rafi Rubin | 369db2a | 2010-05-04 14:20:15 -0400 | [diff] [blame] | 40 | static unsigned int deactivate_slack = 4; |
Rafi Rubin | ab3f498 | 2010-05-04 14:20:16 -0400 | [diff] [blame] | 41 | module_param(deactivate_slack, uint, 0644); |
| 42 | MODULE_PARM_DESC(deactivate_slack, "Number of empty frames to ignore before " |
| 43 | "deactivating touch."); |
| 44 | |
Rafi Rubin | 369db2a | 2010-05-04 14:20:15 -0400 | [diff] [blame] | 45 | static unsigned int activation_width = 64; |
Rafi Rubin | ab3f498 | 2010-05-04 14:20:16 -0400 | [diff] [blame] | 46 | module_param(activation_width, uint, 0644); |
| 47 | MODULE_PARM_DESC(activation_width, "Width threshold to immediately start " |
| 48 | "processing touch events."); |
| 49 | |
Rafi Rubin | 369db2a | 2010-05-04 14:20:15 -0400 | [diff] [blame] | 50 | static unsigned int activation_height = 32; |
Rafi Rubin | ab3f498 | 2010-05-04 14:20:16 -0400 | [diff] [blame] | 51 | module_param(activation_height, uint, 0644); |
| 52 | MODULE_PARM_DESC(activation_height, "Height threshold to immediately start " |
| 53 | "processing touch events."); |
Rafi Rubin | 369db2a | 2010-05-04 14:20:15 -0400 | [diff] [blame] | 54 | |
Stephane Chatty | 57fd637 | 2009-05-20 15:49:35 +0200 | [diff] [blame] | 55 | struct ntrig_data { |
Rafi Rubin | dbf2b17 | 2010-02-12 21:13:05 -0500 | [diff] [blame] | 56 | /* Incoming raw values for a single contact */ |
| 57 | __u16 x, y, w, h; |
| 58 | __u16 id; |
Rafi Rubin | 250d377 | 2010-05-03 05:08:29 -0400 | [diff] [blame] | 59 | |
| 60 | bool tipswitch; |
| 61 | bool confidence; |
| 62 | bool first_contact_touch; |
Rafi Rubin | dbf2b17 | 2010-02-12 21:13:05 -0500 | [diff] [blame] | 63 | |
| 64 | bool reading_mt; |
Rafi Rubin | dbf2b17 | 2010-02-12 21:13:05 -0500 | [diff] [blame] | 65 | |
| 66 | __u8 mt_footer[4]; |
| 67 | __u8 mt_foot_count; |
Rafi Rubin | 369db2a | 2010-05-04 14:20:15 -0400 | [diff] [blame] | 68 | |
| 69 | /* The current activation state. */ |
| 70 | __s8 act_state; |
| 71 | |
| 72 | /* Empty frames to ignore before recognizing the end of activity */ |
| 73 | __s8 deactivate_slack; |
| 74 | |
| 75 | /* Frames to ignore before acknowledging the start of activity */ |
| 76 | __s8 activate_slack; |
| 77 | |
| 78 | /* Minimum size contact to accept */ |
| 79 | __u16 min_width; |
| 80 | __u16 min_height; |
| 81 | |
| 82 | /* Threshold to override activation slack */ |
| 83 | __u16 activation_width; |
| 84 | __u16 activation_height; |
| 85 | |
| 86 | __u16 sensor_logical_width; |
| 87 | __u16 sensor_logical_height; |
| 88 | __u16 sensor_physical_width; |
| 89 | __u16 sensor_physical_height; |
Stephane Chatty | 57fd637 | 2009-05-20 15:49:35 +0200 | [diff] [blame] | 90 | }; |
| 91 | |
Rafi Rubin | eab32f5 | 2010-05-04 14:20:17 -0400 | [diff] [blame] | 92 | |
| 93 | static ssize_t show_phys_width(struct device *dev, |
| 94 | struct device_attribute *attr, |
| 95 | char *buf) |
| 96 | { |
| 97 | struct hid_device *hdev = container_of(dev, struct hid_device, dev); |
| 98 | struct ntrig_data *nd = hid_get_drvdata(hdev); |
| 99 | |
| 100 | return sprintf(buf, "%d\n", nd->sensor_physical_width); |
| 101 | } |
| 102 | |
| 103 | static DEVICE_ATTR(sensor_physical_width, S_IRUGO, show_phys_width, NULL); |
| 104 | |
| 105 | static ssize_t show_phys_height(struct device *dev, |
| 106 | struct device_attribute *attr, |
| 107 | char *buf) |
| 108 | { |
| 109 | struct hid_device *hdev = container_of(dev, struct hid_device, dev); |
| 110 | struct ntrig_data *nd = hid_get_drvdata(hdev); |
| 111 | |
| 112 | return sprintf(buf, "%d\n", nd->sensor_physical_height); |
| 113 | } |
| 114 | |
| 115 | static DEVICE_ATTR(sensor_physical_height, S_IRUGO, show_phys_height, NULL); |
| 116 | |
| 117 | static ssize_t show_log_width(struct device *dev, |
| 118 | struct device_attribute *attr, |
| 119 | char *buf) |
| 120 | { |
| 121 | struct hid_device *hdev = container_of(dev, struct hid_device, dev); |
| 122 | struct ntrig_data *nd = hid_get_drvdata(hdev); |
| 123 | |
| 124 | return sprintf(buf, "%d\n", nd->sensor_logical_width); |
| 125 | } |
| 126 | |
| 127 | static DEVICE_ATTR(sensor_logical_width, S_IRUGO, show_log_width, NULL); |
| 128 | |
| 129 | static ssize_t show_log_height(struct device *dev, |
| 130 | struct device_attribute *attr, |
| 131 | char *buf) |
| 132 | { |
| 133 | struct hid_device *hdev = container_of(dev, struct hid_device, dev); |
| 134 | struct ntrig_data *nd = hid_get_drvdata(hdev); |
| 135 | |
| 136 | return sprintf(buf, "%d\n", nd->sensor_logical_height); |
| 137 | } |
| 138 | |
| 139 | static DEVICE_ATTR(sensor_logical_height, S_IRUGO, show_log_height, NULL); |
| 140 | |
| 141 | static ssize_t show_min_width(struct device *dev, |
| 142 | struct device_attribute *attr, |
| 143 | char *buf) |
| 144 | { |
| 145 | struct hid_device *hdev = container_of(dev, struct hid_device, dev); |
| 146 | struct ntrig_data *nd = hid_get_drvdata(hdev); |
| 147 | |
| 148 | return sprintf(buf, "%d\n", nd->min_width * |
| 149 | nd->sensor_physical_width / |
| 150 | nd->sensor_logical_width); |
| 151 | } |
| 152 | |
| 153 | static ssize_t set_min_width(struct device *dev, |
| 154 | struct device_attribute *attr, |
| 155 | const char *buf, size_t count) |
| 156 | { |
| 157 | struct hid_device *hdev = container_of(dev, struct hid_device, dev); |
| 158 | struct ntrig_data *nd = hid_get_drvdata(hdev); |
| 159 | |
| 160 | unsigned long val; |
| 161 | |
| 162 | if (strict_strtoul(buf, 0, &val)) |
| 163 | return -EINVAL; |
| 164 | |
| 165 | if (val > nd->sensor_physical_width) |
| 166 | return -EINVAL; |
| 167 | |
| 168 | nd->min_width = val * nd->sensor_logical_width / |
| 169 | nd->sensor_physical_width; |
| 170 | |
| 171 | return count; |
| 172 | } |
| 173 | |
| 174 | static DEVICE_ATTR(min_width, S_IWUSR | S_IRUGO, show_min_width, set_min_width); |
| 175 | |
| 176 | static ssize_t show_min_height(struct device *dev, |
| 177 | struct device_attribute *attr, |
| 178 | char *buf) |
| 179 | { |
| 180 | struct hid_device *hdev = container_of(dev, struct hid_device, dev); |
| 181 | struct ntrig_data *nd = hid_get_drvdata(hdev); |
| 182 | |
| 183 | return sprintf(buf, "%d\n", nd->min_height * |
| 184 | nd->sensor_physical_height / |
| 185 | nd->sensor_logical_height); |
| 186 | } |
| 187 | |
| 188 | static ssize_t set_min_height(struct device *dev, |
| 189 | struct device_attribute *attr, |
| 190 | const char *buf, size_t count) |
| 191 | { |
| 192 | struct hid_device *hdev = container_of(dev, struct hid_device, dev); |
| 193 | struct ntrig_data *nd = hid_get_drvdata(hdev); |
| 194 | |
| 195 | unsigned long val; |
| 196 | |
| 197 | if (strict_strtoul(buf, 0, &val)) |
| 198 | return -EINVAL; |
| 199 | |
| 200 | if (val > nd->sensor_physical_height) |
| 201 | return -EINVAL; |
| 202 | |
| 203 | nd->min_height = val * nd->sensor_logical_height / |
| 204 | nd->sensor_physical_height; |
| 205 | |
| 206 | return count; |
| 207 | } |
| 208 | |
| 209 | static DEVICE_ATTR(min_height, S_IWUSR | S_IRUGO, show_min_height, |
| 210 | set_min_height); |
| 211 | |
| 212 | static ssize_t show_activate_slack(struct device *dev, |
| 213 | struct device_attribute *attr, |
| 214 | char *buf) |
| 215 | { |
| 216 | struct hid_device *hdev = container_of(dev, struct hid_device, dev); |
| 217 | struct ntrig_data *nd = hid_get_drvdata(hdev); |
| 218 | |
| 219 | return sprintf(buf, "%d\n", nd->activate_slack); |
| 220 | } |
| 221 | |
| 222 | static ssize_t set_activate_slack(struct device *dev, |
| 223 | struct device_attribute *attr, |
| 224 | const char *buf, size_t count) |
| 225 | { |
| 226 | struct hid_device *hdev = container_of(dev, struct hid_device, dev); |
| 227 | struct ntrig_data *nd = hid_get_drvdata(hdev); |
| 228 | |
| 229 | unsigned long val; |
| 230 | |
| 231 | if (strict_strtoul(buf, 0, &val)) |
| 232 | return -EINVAL; |
| 233 | |
| 234 | if (val > 0x7f) |
| 235 | return -EINVAL; |
| 236 | |
| 237 | nd->activate_slack = val; |
| 238 | |
| 239 | return count; |
| 240 | } |
| 241 | |
| 242 | static DEVICE_ATTR(activate_slack, S_IWUSR | S_IRUGO, show_activate_slack, |
| 243 | set_activate_slack); |
| 244 | |
| 245 | static ssize_t show_activation_width(struct device *dev, |
| 246 | struct device_attribute *attr, |
| 247 | char *buf) |
| 248 | { |
| 249 | struct hid_device *hdev = container_of(dev, struct hid_device, dev); |
| 250 | struct ntrig_data *nd = hid_get_drvdata(hdev); |
| 251 | |
| 252 | return sprintf(buf, "%d\n", nd->activation_width * |
| 253 | nd->sensor_physical_width / |
| 254 | nd->sensor_logical_width); |
| 255 | } |
| 256 | |
| 257 | static ssize_t set_activation_width(struct device *dev, |
| 258 | struct device_attribute *attr, |
| 259 | const char *buf, size_t count) |
| 260 | { |
| 261 | struct hid_device *hdev = container_of(dev, struct hid_device, dev); |
| 262 | struct ntrig_data *nd = hid_get_drvdata(hdev); |
| 263 | |
| 264 | unsigned long val; |
| 265 | |
| 266 | if (strict_strtoul(buf, 0, &val)) |
| 267 | return -EINVAL; |
| 268 | |
| 269 | if (val > nd->sensor_physical_width) |
| 270 | return -EINVAL; |
| 271 | |
| 272 | nd->activation_width = val * nd->sensor_logical_width / |
| 273 | nd->sensor_physical_width; |
| 274 | |
| 275 | return count; |
| 276 | } |
| 277 | |
| 278 | static DEVICE_ATTR(activation_width, S_IWUSR | S_IRUGO, show_activation_width, |
| 279 | set_activation_width); |
| 280 | |
| 281 | static ssize_t show_activation_height(struct device *dev, |
| 282 | struct device_attribute *attr, |
| 283 | char *buf) |
| 284 | { |
| 285 | struct hid_device *hdev = container_of(dev, struct hid_device, dev); |
| 286 | struct ntrig_data *nd = hid_get_drvdata(hdev); |
| 287 | |
| 288 | return sprintf(buf, "%d\n", nd->activation_height * |
| 289 | nd->sensor_physical_height / |
| 290 | nd->sensor_logical_height); |
| 291 | } |
| 292 | |
| 293 | static ssize_t set_activation_height(struct device *dev, |
| 294 | struct device_attribute *attr, |
| 295 | const char *buf, size_t count) |
| 296 | { |
| 297 | struct hid_device *hdev = container_of(dev, struct hid_device, dev); |
| 298 | struct ntrig_data *nd = hid_get_drvdata(hdev); |
| 299 | |
| 300 | unsigned long val; |
| 301 | |
| 302 | if (strict_strtoul(buf, 0, &val)) |
| 303 | return -EINVAL; |
| 304 | |
| 305 | if (val > nd->sensor_physical_height) |
| 306 | return -EINVAL; |
| 307 | |
| 308 | nd->activation_height = val * nd->sensor_logical_height / |
| 309 | nd->sensor_physical_height; |
| 310 | |
| 311 | return count; |
| 312 | } |
| 313 | |
| 314 | static DEVICE_ATTR(activation_height, S_IWUSR | S_IRUGO, |
| 315 | show_activation_height, set_activation_height); |
| 316 | |
| 317 | static ssize_t show_deactivate_slack(struct device *dev, |
| 318 | struct device_attribute *attr, |
| 319 | char *buf) |
| 320 | { |
| 321 | struct hid_device *hdev = container_of(dev, struct hid_device, dev); |
| 322 | struct ntrig_data *nd = hid_get_drvdata(hdev); |
| 323 | |
| 324 | return sprintf(buf, "%d\n", -nd->deactivate_slack); |
| 325 | } |
| 326 | |
| 327 | static ssize_t set_deactivate_slack(struct device *dev, |
| 328 | struct device_attribute *attr, |
| 329 | const char *buf, size_t count) |
| 330 | { |
| 331 | struct hid_device *hdev = container_of(dev, struct hid_device, dev); |
| 332 | struct ntrig_data *nd = hid_get_drvdata(hdev); |
| 333 | |
| 334 | unsigned long val; |
| 335 | |
| 336 | if (strict_strtoul(buf, 0, &val)) |
| 337 | return -EINVAL; |
| 338 | |
| 339 | /* |
| 340 | * No more than 8 terminal frames have been observed so far |
| 341 | * and higher slack is highly likely to leave the single |
| 342 | * touch emulation stuck down. |
| 343 | */ |
| 344 | if (val > 7) |
| 345 | return -EINVAL; |
| 346 | |
| 347 | nd->deactivate_slack = -val; |
| 348 | |
| 349 | return count; |
| 350 | } |
| 351 | |
| 352 | static DEVICE_ATTR(deactivate_slack, S_IWUSR | S_IRUGO, show_deactivate_slack, |
| 353 | set_deactivate_slack); |
| 354 | |
| 355 | static struct attribute *sysfs_attrs[] = { |
| 356 | &dev_attr_sensor_physical_width.attr, |
| 357 | &dev_attr_sensor_physical_height.attr, |
| 358 | &dev_attr_sensor_logical_width.attr, |
| 359 | &dev_attr_sensor_logical_height.attr, |
| 360 | &dev_attr_min_height.attr, |
| 361 | &dev_attr_min_width.attr, |
| 362 | &dev_attr_activate_slack.attr, |
| 363 | &dev_attr_activation_width.attr, |
| 364 | &dev_attr_activation_height.attr, |
| 365 | &dev_attr_deactivate_slack.attr, |
| 366 | NULL |
| 367 | }; |
| 368 | |
| 369 | static struct attribute_group ntrig_attribute_group = { |
| 370 | .attrs = sysfs_attrs |
| 371 | }; |
| 372 | |
Stephane Chatty | 57fd637 | 2009-05-20 15:49:35 +0200 | [diff] [blame] | 373 | /* |
| 374 | * this driver is aimed at two firmware versions in circulation: |
| 375 | * - dual pen/finger single touch |
| 376 | * - finger multitouch, pen not working |
| 377 | */ |
| 378 | |
Rafi Rubin | 94011f9 | 2008-11-19 15:54:46 +0100 | [diff] [blame] | 379 | static int ntrig_input_mapping(struct hid_device *hdev, struct hid_input *hi, |
| 380 | struct hid_field *field, struct hid_usage *usage, |
| 381 | unsigned long **bit, int *max) |
| 382 | { |
Rafi Rubin | 369db2a | 2010-05-04 14:20:15 -0400 | [diff] [blame] | 383 | struct ntrig_data *nd = hid_get_drvdata(hdev); |
| 384 | |
Rafi Rubin | dbf2b17 | 2010-02-12 21:13:05 -0500 | [diff] [blame] | 385 | /* No special mappings needed for the pen and single touch */ |
| 386 | if (field->physical) |
Rafi Rubin | 943ed46 | 2010-02-11 22:14:05 -0500 | [diff] [blame] | 387 | return 0; |
| 388 | |
Stephane Chatty | 57fd637 | 2009-05-20 15:49:35 +0200 | [diff] [blame] | 389 | switch (usage->hid & HID_USAGE_PAGE) { |
Stephane Chatty | 57fd637 | 2009-05-20 15:49:35 +0200 | [diff] [blame] | 390 | case HID_UP_GENDESK: |
| 391 | switch (usage->hid) { |
| 392 | case HID_GD_X: |
| 393 | hid_map_usage(hi, usage, bit, max, |
| 394 | EV_ABS, ABS_MT_POSITION_X); |
| 395 | input_set_abs_params(hi->input, ABS_X, |
| 396 | field->logical_minimum, |
| 397 | field->logical_maximum, 0, 0); |
Rafi Rubin | 369db2a | 2010-05-04 14:20:15 -0400 | [diff] [blame] | 398 | |
| 399 | if (!nd->sensor_logical_width) { |
| 400 | nd->sensor_logical_width = |
| 401 | field->logical_maximum - |
| 402 | field->logical_minimum; |
| 403 | nd->sensor_physical_width = |
| 404 | field->physical_maximum - |
| 405 | field->physical_minimum; |
| 406 | nd->activation_width = activation_width * |
| 407 | nd->sensor_logical_width / |
| 408 | nd->sensor_physical_width; |
| 409 | nd->min_width = min_width * |
| 410 | nd->sensor_logical_width / |
| 411 | nd->sensor_physical_width; |
| 412 | } |
Stephane Chatty | 57fd637 | 2009-05-20 15:49:35 +0200 | [diff] [blame] | 413 | return 1; |
| 414 | case HID_GD_Y: |
| 415 | hid_map_usage(hi, usage, bit, max, |
| 416 | EV_ABS, ABS_MT_POSITION_Y); |
| 417 | input_set_abs_params(hi->input, ABS_Y, |
| 418 | field->logical_minimum, |
| 419 | field->logical_maximum, 0, 0); |
Rafi Rubin | 369db2a | 2010-05-04 14:20:15 -0400 | [diff] [blame] | 420 | |
| 421 | if (!nd->sensor_logical_height) { |
| 422 | nd->sensor_logical_height = |
| 423 | field->logical_maximum - |
| 424 | field->logical_minimum; |
| 425 | nd->sensor_physical_height = |
| 426 | field->physical_maximum - |
| 427 | field->physical_minimum; |
| 428 | nd->activation_height = activation_height * |
| 429 | nd->sensor_logical_height / |
| 430 | nd->sensor_physical_height; |
| 431 | nd->min_height = min_height * |
| 432 | nd->sensor_logical_height / |
| 433 | nd->sensor_physical_height; |
| 434 | } |
Stephane Chatty | 57fd637 | 2009-05-20 15:49:35 +0200 | [diff] [blame] | 435 | return 1; |
| 436 | } |
| 437 | return 0; |
| 438 | |
| 439 | case HID_UP_DIGITIZER: |
| 440 | switch (usage->hid) { |
| 441 | /* we do not want to map these for now */ |
Rafi Rubin | dbf2b17 | 2010-02-12 21:13:05 -0500 | [diff] [blame] | 442 | case HID_DG_CONTACTID: /* Not trustworthy, squelch for now */ |
Stephane Chatty | 57fd637 | 2009-05-20 15:49:35 +0200 | [diff] [blame] | 443 | case HID_DG_INPUTMODE: |
| 444 | case HID_DG_DEVICEINDEX: |
Stephane Chatty | 57fd637 | 2009-05-20 15:49:35 +0200 | [diff] [blame] | 445 | case HID_DG_CONTACTMAX: |
| 446 | return -1; |
| 447 | |
Stephane Chatty | 57fd637 | 2009-05-20 15:49:35 +0200 | [diff] [blame] | 448 | /* width/height mapped on TouchMajor/TouchMinor/Orientation */ |
| 449 | case HID_DG_WIDTH: |
| 450 | hid_map_usage(hi, usage, bit, max, |
| 451 | EV_ABS, ABS_MT_TOUCH_MAJOR); |
| 452 | return 1; |
| 453 | case HID_DG_HEIGHT: |
| 454 | hid_map_usage(hi, usage, bit, max, |
| 455 | EV_ABS, ABS_MT_TOUCH_MINOR); |
| 456 | input_set_abs_params(hi->input, ABS_MT_ORIENTATION, |
| 457 | 0, 1, 0, 0); |
| 458 | return 1; |
| 459 | } |
| 460 | return 0; |
| 461 | |
| 462 | case 0xff000000: |
| 463 | /* we do not want to map these: no input-oriented meaning */ |
| 464 | return -1; |
Rafi Rubin | 94011f9 | 2008-11-19 15:54:46 +0100 | [diff] [blame] | 465 | } |
Stephane Chatty | 57fd637 | 2009-05-20 15:49:35 +0200 | [diff] [blame] | 466 | |
Rafi Rubin | 94011f9 | 2008-11-19 15:54:46 +0100 | [diff] [blame] | 467 | return 0; |
| 468 | } |
| 469 | |
| 470 | static int ntrig_input_mapped(struct hid_device *hdev, struct hid_input *hi, |
| 471 | struct hid_field *field, struct hid_usage *usage, |
| 472 | unsigned long **bit, int *max) |
| 473 | { |
Rafi Rubin | dbf2b17 | 2010-02-12 21:13:05 -0500 | [diff] [blame] | 474 | /* No special mappings needed for the pen and single touch */ |
| 475 | if (field->physical) |
Rafi Rubin | 943ed46 | 2010-02-11 22:14:05 -0500 | [diff] [blame] | 476 | return 0; |
Rafi Rubin | b0549cf | 2010-02-11 22:14:06 -0500 | [diff] [blame] | 477 | |
Rafi Rubin | 94011f9 | 2008-11-19 15:54:46 +0100 | [diff] [blame] | 478 | if (usage->type == EV_KEY || usage->type == EV_REL |
| 479 | || usage->type == EV_ABS) |
| 480 | clear_bit(usage->code, *bit); |
| 481 | |
| 482 | return 0; |
| 483 | } |
Stephane Chatty | 57fd637 | 2009-05-20 15:49:35 +0200 | [diff] [blame] | 484 | |
| 485 | /* |
| 486 | * this function is called upon all reports |
| 487 | * so that we can filter contact point information, |
| 488 | * decide whether we are in multi or single touch mode |
| 489 | * and call input_mt_sync after each point if necessary |
| 490 | */ |
| 491 | static int ntrig_event (struct hid_device *hid, struct hid_field *field, |
| 492 | struct hid_usage *usage, __s32 value) |
| 493 | { |
| 494 | struct input_dev *input = field->hidinput->input; |
| 495 | struct ntrig_data *nd = hid_get_drvdata(hid); |
| 496 | |
Rafi Rubin | 943ed46 | 2010-02-11 22:14:05 -0500 | [diff] [blame] | 497 | /* No special handling needed for the pen */ |
| 498 | if (field->application == HID_DG_PEN) |
| 499 | return 0; |
| 500 | |
Stephane Chatty | 57fd637 | 2009-05-20 15:49:35 +0200 | [diff] [blame] | 501 | if (hid->claimed & HID_CLAIMED_INPUT) { |
| 502 | switch (usage->hid) { |
Rafi Rubin | dbf2b17 | 2010-02-12 21:13:05 -0500 | [diff] [blame] | 503 | case 0xff000001: |
| 504 | /* Tag indicating the start of a multitouch group */ |
| 505 | nd->reading_mt = 1; |
Rafi Rubin | 250d377 | 2010-05-03 05:08:29 -0400 | [diff] [blame] | 506 | nd->first_contact_touch = 0; |
Rafi Rubin | dbf2b17 | 2010-02-12 21:13:05 -0500 | [diff] [blame] | 507 | break; |
Rafi Rubin | 2886539 | 2010-03-10 16:10:28 +0100 | [diff] [blame] | 508 | case HID_DG_TIPSWITCH: |
Rafi Rubin | 250d377 | 2010-05-03 05:08:29 -0400 | [diff] [blame] | 509 | nd->tipswitch = value; |
Rafi Rubin | 2886539 | 2010-03-10 16:10:28 +0100 | [diff] [blame] | 510 | /* Prevent emission of touch until validated */ |
| 511 | return 1; |
Rafi Rubin | dbf2b17 | 2010-02-12 21:13:05 -0500 | [diff] [blame] | 512 | case HID_DG_CONFIDENCE: |
| 513 | nd->confidence = value; |
| 514 | break; |
Stephane Chatty | 57fd637 | 2009-05-20 15:49:35 +0200 | [diff] [blame] | 515 | case HID_GD_X: |
| 516 | nd->x = value; |
Rafi Rubin | dbf2b17 | 2010-02-12 21:13:05 -0500 | [diff] [blame] | 517 | /* Clear the contact footer */ |
| 518 | nd->mt_foot_count = 0; |
Stephane Chatty | 57fd637 | 2009-05-20 15:49:35 +0200 | [diff] [blame] | 519 | break; |
| 520 | case HID_GD_Y: |
| 521 | nd->y = value; |
| 522 | break; |
| 523 | case HID_DG_CONTACTID: |
| 524 | nd->id = value; |
Stephane Chatty | 57fd637 | 2009-05-20 15:49:35 +0200 | [diff] [blame] | 525 | break; |
| 526 | case HID_DG_WIDTH: |
| 527 | nd->w = value; |
| 528 | break; |
| 529 | case HID_DG_HEIGHT: |
| 530 | nd->h = value; |
| 531 | /* |
| 532 | * when in single touch mode, this is the last |
| 533 | * report received in a finger event. We want |
| 534 | * to emit a normal (X, Y) position |
| 535 | */ |
Rafi Rubin | dbf2b17 | 2010-02-12 21:13:05 -0500 | [diff] [blame] | 536 | if (!nd->reading_mt) { |
Rafi Rubin | 250d377 | 2010-05-03 05:08:29 -0400 | [diff] [blame] | 537 | /* |
| 538 | * TipSwitch indicates the presence of a |
| 539 | * finger in single touch mode. |
| 540 | */ |
Rafi Rubin | 2170c5a | 2010-04-09 17:58:25 -0400 | [diff] [blame] | 541 | input_report_key(input, BTN_TOUCH, |
Rafi Rubin | 250d377 | 2010-05-03 05:08:29 -0400 | [diff] [blame] | 542 | nd->tipswitch); |
| 543 | input_report_key(input, BTN_TOOL_DOUBLETAP, |
| 544 | nd->tipswitch); |
Stephane Chatty | 57fd637 | 2009-05-20 15:49:35 +0200 | [diff] [blame] | 545 | input_event(input, EV_ABS, ABS_X, nd->x); |
| 546 | input_event(input, EV_ABS, ABS_Y, nd->y); |
| 547 | } |
| 548 | break; |
Stephane Chatty | 57fd637 | 2009-05-20 15:49:35 +0200 | [diff] [blame] | 549 | case 0xff000002: |
| 550 | /* |
| 551 | * we receive this when the device is in multitouch |
| 552 | * mode. The first of the three values tagged with |
| 553 | * this usage tells if the contact point is real |
| 554 | * or a placeholder |
| 555 | */ |
Rafi Rubin | dbf2b17 | 2010-02-12 21:13:05 -0500 | [diff] [blame] | 556 | |
| 557 | /* Shouldn't get more than 4 footer packets, so skip */ |
| 558 | if (nd->mt_foot_count >= 4) |
Stephane Chatty | 57fd637 | 2009-05-20 15:49:35 +0200 | [diff] [blame] | 559 | break; |
Rafi Rubin | dbf2b17 | 2010-02-12 21:13:05 -0500 | [diff] [blame] | 560 | |
| 561 | nd->mt_footer[nd->mt_foot_count++] = value; |
| 562 | |
| 563 | /* if the footer isn't complete break */ |
| 564 | if (nd->mt_foot_count != 4) |
| 565 | break; |
| 566 | |
Rafi Rubin | 369db2a | 2010-05-04 14:20:15 -0400 | [diff] [blame] | 567 | /* Pen activity signal. */ |
Rafi Rubin | dbf2b17 | 2010-02-12 21:13:05 -0500 | [diff] [blame] | 568 | if (nd->mt_footer[2]) { |
Rafi Rubin | 369db2a | 2010-05-04 14:20:15 -0400 | [diff] [blame] | 569 | /* |
| 570 | * When the pen deactivates touch, we see a |
| 571 | * bogus frame with ContactCount > 0. |
| 572 | * We can |
| 573 | * save a bit of work by ensuring act_state < 0 |
| 574 | * even if deactivation slack is turned off. |
| 575 | */ |
| 576 | nd->act_state = deactivate_slack - 1; |
Rafi Rubin | dbf2b17 | 2010-02-12 21:13:05 -0500 | [diff] [blame] | 577 | nd->confidence = 0; |
| 578 | break; |
| 579 | } |
| 580 | |
Rafi Rubin | 369db2a | 2010-05-04 14:20:15 -0400 | [diff] [blame] | 581 | /* |
| 582 | * The first footer value indicates the presence of a |
| 583 | * finger. |
| 584 | */ |
| 585 | if (nd->mt_footer[0]) { |
| 586 | /* |
| 587 | * We do not want to process contacts under |
| 588 | * the size threshold, but do not want to |
| 589 | * ignore them for activation state |
| 590 | */ |
| 591 | if (nd->w < nd->min_width || |
| 592 | nd->h < nd->min_height) |
| 593 | nd->confidence = 0; |
| 594 | } else |
Rafi Rubin | dbf2b17 | 2010-02-12 21:13:05 -0500 | [diff] [blame] | 595 | break; |
Rafi Rubin | 369db2a | 2010-05-04 14:20:15 -0400 | [diff] [blame] | 596 | |
| 597 | if (nd->act_state > 0) { |
| 598 | /* |
| 599 | * Contact meets the activation size threshold |
| 600 | */ |
| 601 | if (nd->w >= nd->activation_width && |
| 602 | nd->h >= nd->activation_height) { |
| 603 | if (nd->id) |
| 604 | /* |
| 605 | * first contact, activate now |
| 606 | */ |
| 607 | nd->act_state = 0; |
| 608 | else { |
| 609 | /* |
| 610 | * avoid corrupting this frame |
| 611 | * but ensure next frame will |
| 612 | * be active |
| 613 | */ |
| 614 | nd->act_state = 1; |
| 615 | break; |
| 616 | } |
| 617 | } else |
| 618 | /* |
| 619 | * Defer adjusting the activation state |
| 620 | * until the end of the frame. |
| 621 | */ |
| 622 | break; |
Rafi Rubin | dbf2b17 | 2010-02-12 21:13:05 -0500 | [diff] [blame] | 623 | } |
| 624 | |
Rafi Rubin | 369db2a | 2010-05-04 14:20:15 -0400 | [diff] [blame] | 625 | /* Discarding this contact */ |
| 626 | if (!nd->confidence) |
| 627 | break; |
| 628 | |
Stephane Chatty | 57fd637 | 2009-05-20 15:49:35 +0200 | [diff] [blame] | 629 | /* emit a normal (X, Y) for the first point only */ |
| 630 | if (nd->id == 0) { |
Rafi Rubin | 250d377 | 2010-05-03 05:08:29 -0400 | [diff] [blame] | 631 | /* |
| 632 | * TipSwitch is superfluous in multitouch |
| 633 | * mode. The footer events tell us |
| 634 | * if there is a finger on the screen or |
| 635 | * not. |
| 636 | */ |
| 637 | nd->first_contact_touch = nd->confidence; |
Stephane Chatty | 57fd637 | 2009-05-20 15:49:35 +0200 | [diff] [blame] | 638 | input_event(input, EV_ABS, ABS_X, nd->x); |
| 639 | input_event(input, EV_ABS, ABS_Y, nd->y); |
| 640 | } |
Rafi Rubin | 369db2a | 2010-05-04 14:20:15 -0400 | [diff] [blame] | 641 | |
| 642 | /* Emit MT events */ |
Stephane Chatty | 57fd637 | 2009-05-20 15:49:35 +0200 | [diff] [blame] | 643 | input_event(input, EV_ABS, ABS_MT_POSITION_X, nd->x); |
| 644 | input_event(input, EV_ABS, ABS_MT_POSITION_Y, nd->y); |
Rafi Rubin | 369db2a | 2010-05-04 14:20:15 -0400 | [diff] [blame] | 645 | |
| 646 | /* |
| 647 | * Translate from height and width to size |
| 648 | * and orientation. |
| 649 | */ |
Stephane Chatty | 57fd637 | 2009-05-20 15:49:35 +0200 | [diff] [blame] | 650 | if (nd->w > nd->h) { |
| 651 | input_event(input, EV_ABS, |
| 652 | ABS_MT_ORIENTATION, 1); |
| 653 | input_event(input, EV_ABS, |
| 654 | ABS_MT_TOUCH_MAJOR, nd->w); |
| 655 | input_event(input, EV_ABS, |
| 656 | ABS_MT_TOUCH_MINOR, nd->h); |
| 657 | } else { |
| 658 | input_event(input, EV_ABS, |
| 659 | ABS_MT_ORIENTATION, 0); |
| 660 | input_event(input, EV_ABS, |
| 661 | ABS_MT_TOUCH_MAJOR, nd->h); |
| 662 | input_event(input, EV_ABS, |
| 663 | ABS_MT_TOUCH_MINOR, nd->w); |
| 664 | } |
| 665 | input_mt_sync(field->hidinput->input); |
Rafi Rubin | dbf2b17 | 2010-02-12 21:13:05 -0500 | [diff] [blame] | 666 | break; |
| 667 | |
| 668 | case HID_DG_CONTACTCOUNT: /* End of a multitouch group */ |
Rafi Rubin | 369db2a | 2010-05-04 14:20:15 -0400 | [diff] [blame] | 669 | if (!nd->reading_mt) /* Just to be sure */ |
Rafi Rubin | dbf2b17 | 2010-02-12 21:13:05 -0500 | [diff] [blame] | 670 | break; |
| 671 | |
| 672 | nd->reading_mt = 0; |
| 673 | |
Rafi Rubin | 369db2a | 2010-05-04 14:20:15 -0400 | [diff] [blame] | 674 | |
| 675 | /* |
| 676 | * Activation state machine logic: |
| 677 | * |
| 678 | * Fundamental states: |
| 679 | * state > 0: Inactive |
| 680 | * state <= 0: Active |
| 681 | * state < -deactivate_slack: |
| 682 | * Pen termination of touch |
| 683 | * |
| 684 | * Specific values of interest |
| 685 | * state == activate_slack |
| 686 | * no valid input since the last reset |
| 687 | * |
| 688 | * state == 0 |
| 689 | * general operational state |
| 690 | * |
| 691 | * state == -deactivate_slack |
| 692 | * read sufficient empty frames to accept |
| 693 | * the end of input and reset |
| 694 | */ |
| 695 | |
| 696 | if (nd->act_state > 0) { /* Currently inactive */ |
| 697 | if (value) |
| 698 | /* |
| 699 | * Consider each live contact as |
| 700 | * evidence of intentional activity. |
| 701 | */ |
| 702 | nd->act_state = (nd->act_state > value) |
| 703 | ? nd->act_state - value |
| 704 | : 0; |
| 705 | else |
| 706 | /* |
| 707 | * Empty frame before we hit the |
| 708 | * activity threshold, reset. |
| 709 | */ |
| 710 | nd->act_state = nd->activate_slack; |
| 711 | |
| 712 | /* |
| 713 | * Entered this block inactive and no |
| 714 | * coordinates sent this frame, so hold off |
| 715 | * on button state. |
| 716 | */ |
| 717 | break; |
| 718 | } else { /* Currently active */ |
| 719 | if (value && nd->act_state >= |
| 720 | nd->deactivate_slack) |
| 721 | /* |
| 722 | * Live point: clear accumulated |
| 723 | * deactivation count. |
| 724 | */ |
| 725 | nd->act_state = 0; |
| 726 | else if (nd->act_state <= nd->deactivate_slack) |
| 727 | /* |
| 728 | * We've consumed the deactivation |
| 729 | * slack, time to deactivate and reset. |
| 730 | */ |
| 731 | nd->act_state = |
| 732 | nd->activate_slack; |
| 733 | else { /* Move towards deactivation */ |
| 734 | nd->act_state--; |
| 735 | break; |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | if (nd->first_contact_touch && nd->act_state <= 0) { |
| 740 | /* |
| 741 | * Check to see if we're ready to start |
| 742 | * emitting touch events. |
| 743 | * |
| 744 | * Note: activation slack will decrease over |
| 745 | * the course of the frame, and it will be |
| 746 | * inconsistent from the start to the end of |
| 747 | * the frame. However if the frame starts |
| 748 | * with slack, first_contact_touch will still |
| 749 | * be 0 and we will not get to this point. |
| 750 | */ |
Rafi Rubin | ed7e2ca | 2010-05-03 05:08:30 -0400 | [diff] [blame] | 751 | input_report_key(input, BTN_TOOL_DOUBLETAP, 1); |
Rafi Rubin | dbf2b17 | 2010-02-12 21:13:05 -0500 | [diff] [blame] | 752 | input_report_key(input, BTN_TOUCH, 1); |
| 753 | } else { |
Rafi Rubin | ed7e2ca | 2010-05-03 05:08:30 -0400 | [diff] [blame] | 754 | input_report_key(input, BTN_TOOL_DOUBLETAP, 0); |
Rafi Rubin | 2886539 | 2010-03-10 16:10:28 +0100 | [diff] [blame] | 755 | input_report_key(input, BTN_TOUCH, 0); |
Rafi Rubin | dbf2b17 | 2010-02-12 21:13:05 -0500 | [diff] [blame] | 756 | } |
Stephane Chatty | 57fd637 | 2009-05-20 15:49:35 +0200 | [diff] [blame] | 757 | break; |
| 758 | |
| 759 | default: |
Rafi Rubin | 369db2a | 2010-05-04 14:20:15 -0400 | [diff] [blame] | 760 | /* fall-back to the generic hidinput handling */ |
Stephane Chatty | 57fd637 | 2009-05-20 15:49:35 +0200 | [diff] [blame] | 761 | return 0; |
| 762 | } |
| 763 | } |
| 764 | |
| 765 | /* we have handled the hidinput part, now remains hiddev */ |
Rafi Rubin | 943ed46 | 2010-02-11 22:14:05 -0500 | [diff] [blame] | 766 | if ((hid->claimed & HID_CLAIMED_HIDDEV) && hid->hiddev_hid_event) |
| 767 | hid->hiddev_hid_event(hid, field, usage, value); |
Stephane Chatty | 57fd637 | 2009-05-20 15:49:35 +0200 | [diff] [blame] | 768 | |
| 769 | return 1; |
| 770 | } |
| 771 | |
| 772 | static int ntrig_probe(struct hid_device *hdev, const struct hid_device_id *id) |
| 773 | { |
| 774 | int ret; |
| 775 | struct ntrig_data *nd; |
Rafi Rubin | 943ed46 | 2010-02-11 22:14:05 -0500 | [diff] [blame] | 776 | struct hid_input *hidinput; |
| 777 | struct input_dev *input; |
Stephane Chatty | 6549981 | 2010-04-06 22:22:58 +0200 | [diff] [blame] | 778 | struct hid_report *report; |
Rafi Rubin | 943ed46 | 2010-02-11 22:14:05 -0500 | [diff] [blame] | 779 | |
| 780 | if (id->driver_data) |
| 781 | hdev->quirks |= HID_QUIRK_MULTI_INPUT; |
Stephane Chatty | 57fd637 | 2009-05-20 15:49:35 +0200 | [diff] [blame] | 782 | |
| 783 | nd = kmalloc(sizeof(struct ntrig_data), GFP_KERNEL); |
| 784 | if (!nd) { |
| 785 | dev_err(&hdev->dev, "cannot allocate N-Trig data\n"); |
| 786 | return -ENOMEM; |
| 787 | } |
Rafi Rubin | dbf2b17 | 2010-02-12 21:13:05 -0500 | [diff] [blame] | 788 | |
| 789 | nd->reading_mt = 0; |
Rafi Rubin | 369db2a | 2010-05-04 14:20:15 -0400 | [diff] [blame] | 790 | nd->min_width = 0; |
| 791 | nd->min_height = 0; |
| 792 | nd->activate_slack = activate_slack; |
| 793 | nd->act_state = activate_slack; |
| 794 | nd->deactivate_slack = -deactivate_slack; |
| 795 | nd->sensor_logical_width = 0; |
| 796 | nd->sensor_logical_height = 0; |
| 797 | nd->sensor_physical_width = 0; |
| 798 | nd->sensor_physical_height = 0; |
| 799 | |
Stephane Chatty | 57fd637 | 2009-05-20 15:49:35 +0200 | [diff] [blame] | 800 | hid_set_drvdata(hdev, nd); |
| 801 | |
| 802 | ret = hid_parse(hdev); |
Rafi Rubin | 943ed46 | 2010-02-11 22:14:05 -0500 | [diff] [blame] | 803 | if (ret) { |
| 804 | dev_err(&hdev->dev, "parse failed\n"); |
| 805 | goto err_free; |
| 806 | } |
Stephane Chatty | 57fd637 | 2009-05-20 15:49:35 +0200 | [diff] [blame] | 807 | |
Rafi Rubin | 943ed46 | 2010-02-11 22:14:05 -0500 | [diff] [blame] | 808 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); |
| 809 | if (ret) { |
| 810 | dev_err(&hdev->dev, "hw start failed\n"); |
| 811 | goto err_free; |
| 812 | } |
Rafi Rubin | 837b475 | 2009-06-23 14:09:26 -0400 | [diff] [blame] | 813 | |
Rafi Rubin | 943ed46 | 2010-02-11 22:14:05 -0500 | [diff] [blame] | 814 | |
| 815 | list_for_each_entry(hidinput, &hdev->inputs, list) { |
Rafi Rubin | 2886539 | 2010-03-10 16:10:28 +0100 | [diff] [blame] | 816 | if (hidinput->report->maxfield < 1) |
| 817 | continue; |
| 818 | |
Rafi Rubin | 943ed46 | 2010-02-11 22:14:05 -0500 | [diff] [blame] | 819 | input = hidinput->input; |
| 820 | switch (hidinput->report->field[0]->application) { |
| 821 | case HID_DG_PEN: |
| 822 | input->name = "N-Trig Pen"; |
| 823 | break; |
| 824 | case HID_DG_TOUCHSCREEN: |
Rafi Rubin | 2886539 | 2010-03-10 16:10:28 +0100 | [diff] [blame] | 825 | /* These keys are redundant for fingers, clear them |
| 826 | * to prevent incorrect identification */ |
Rafi Rubin | dbf2b17 | 2010-02-12 21:13:05 -0500 | [diff] [blame] | 827 | __clear_bit(BTN_TOOL_PEN, input->keybit); |
Rafi Rubin | 2886539 | 2010-03-10 16:10:28 +0100 | [diff] [blame] | 828 | __clear_bit(BTN_TOOL_FINGER, input->keybit); |
| 829 | __clear_bit(BTN_0, input->keybit); |
Rafi Rubin | dbf2b17 | 2010-02-12 21:13:05 -0500 | [diff] [blame] | 830 | __set_bit(BTN_TOOL_DOUBLETAP, input->keybit); |
Rafi Rubin | 943ed46 | 2010-02-11 22:14:05 -0500 | [diff] [blame] | 831 | /* |
| 832 | * The physical touchscreen (single touch) |
| 833 | * input has a value for physical, whereas |
| 834 | * the multitouch only has logical input |
| 835 | * fields. |
| 836 | */ |
| 837 | input->name = |
| 838 | (hidinput->report->field[0] |
| 839 | ->physical) ? |
| 840 | "N-Trig Touchscreen" : |
| 841 | "N-Trig MultiTouch"; |
| 842 | break; |
| 843 | } |
| 844 | } |
| 845 | |
Jiri Kosina | c085855 | 2010-04-07 12:10:29 +0200 | [diff] [blame] | 846 | /* This is needed for devices with more recent firmware versions */ |
| 847 | report = hdev->report_enum[HID_FEATURE_REPORT].report_id_hash[0x0a]; |
Stephane Chatty | 6549981 | 2010-04-06 22:22:58 +0200 | [diff] [blame] | 848 | if (report) |
| 849 | usbhid_submit_report(hdev, report, USB_DIR_OUT); |
| 850 | |
Rafi Rubin | eab32f5 | 2010-05-04 14:20:17 -0400 | [diff] [blame] | 851 | ret = sysfs_create_group(&hdev->dev.kobj, |
| 852 | &ntrig_attribute_group); |
Stephane Chatty | 6549981 | 2010-04-06 22:22:58 +0200 | [diff] [blame] | 853 | |
Rafi Rubin | 943ed46 | 2010-02-11 22:14:05 -0500 | [diff] [blame] | 854 | return 0; |
| 855 | err_free: |
| 856 | kfree(nd); |
Stephane Chatty | 57fd637 | 2009-05-20 15:49:35 +0200 | [diff] [blame] | 857 | return ret; |
| 858 | } |
| 859 | |
| 860 | static void ntrig_remove(struct hid_device *hdev) |
| 861 | { |
Rafi Rubin | eab32f5 | 2010-05-04 14:20:17 -0400 | [diff] [blame] | 862 | sysfs_remove_group(&hdev->dev.kobj, |
| 863 | &ntrig_attribute_group); |
Stephane Chatty | 57fd637 | 2009-05-20 15:49:35 +0200 | [diff] [blame] | 864 | hid_hw_stop(hdev); |
| 865 | kfree(hid_get_drvdata(hdev)); |
| 866 | } |
| 867 | |
Rafi Rubin | 94011f9 | 2008-11-19 15:54:46 +0100 | [diff] [blame] | 868 | static const struct hid_device_id ntrig_devices[] = { |
| 869 | { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN), |
| 870 | .driver_data = NTRIG_DUPLICATE_USAGES }, |
| 871 | { } |
| 872 | }; |
| 873 | MODULE_DEVICE_TABLE(hid, ntrig_devices); |
| 874 | |
Stephane Chatty | 57fd637 | 2009-05-20 15:49:35 +0200 | [diff] [blame] | 875 | static const struct hid_usage_id ntrig_grabbed_usages[] = { |
| 876 | { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID }, |
Rafi Rubin | 943ed46 | 2010-02-11 22:14:05 -0500 | [diff] [blame] | 877 | { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1 } |
Stephane Chatty | 57fd637 | 2009-05-20 15:49:35 +0200 | [diff] [blame] | 878 | }; |
| 879 | |
Rafi Rubin | 94011f9 | 2008-11-19 15:54:46 +0100 | [diff] [blame] | 880 | static struct hid_driver ntrig_driver = { |
| 881 | .name = "ntrig", |
| 882 | .id_table = ntrig_devices, |
Stephane Chatty | 57fd637 | 2009-05-20 15:49:35 +0200 | [diff] [blame] | 883 | .probe = ntrig_probe, |
| 884 | .remove = ntrig_remove, |
Rafi Rubin | 94011f9 | 2008-11-19 15:54:46 +0100 | [diff] [blame] | 885 | .input_mapping = ntrig_input_mapping, |
| 886 | .input_mapped = ntrig_input_mapped, |
Stephane Chatty | 57fd637 | 2009-05-20 15:49:35 +0200 | [diff] [blame] | 887 | .usage_table = ntrig_grabbed_usages, |
| 888 | .event = ntrig_event, |
Rafi Rubin | 94011f9 | 2008-11-19 15:54:46 +0100 | [diff] [blame] | 889 | }; |
| 890 | |
Peter Huewe | a24f423 | 2009-07-02 19:08:38 +0200 | [diff] [blame] | 891 | static int __init ntrig_init(void) |
Rafi Rubin | 94011f9 | 2008-11-19 15:54:46 +0100 | [diff] [blame] | 892 | { |
| 893 | return hid_register_driver(&ntrig_driver); |
| 894 | } |
| 895 | |
Peter Huewe | a24f423 | 2009-07-02 19:08:38 +0200 | [diff] [blame] | 896 | static void __exit ntrig_exit(void) |
Rafi Rubin | 94011f9 | 2008-11-19 15:54:46 +0100 | [diff] [blame] | 897 | { |
| 898 | hid_unregister_driver(&ntrig_driver); |
| 899 | } |
| 900 | |
| 901 | module_init(ntrig_init); |
| 902 | module_exit(ntrig_exit); |
| 903 | MODULE_LICENSE("GPL"); |