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