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