Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 1 | /* |
| 2 | * HID driver for multitouch panels |
| 3 | * |
| 4 | * Copyright (c) 2010-2011 Stephane Chatty <chatty@enac.fr> |
| 5 | * Copyright (c) 2010-2011 Benjamin Tissoires <benjamin.tissoires@gmail.com> |
| 6 | * Copyright (c) 2010-2011 Ecole Nationale de l'Aviation Civile, France |
| 7 | * |
Richard Nauber | 4875ac1 | 2011-03-09 06:20:57 +0100 | [diff] [blame] | 8 | * This code is partly based on hid-egalax.c: |
| 9 | * |
| 10 | * Copyright (c) 2010 Stephane Chatty <chatty@enac.fr> |
| 11 | * Copyright (c) 2010 Henrik Rydberg <rydberg@euromail.se> |
| 12 | * Copyright (c) 2010 Canonical, Ltd. |
| 13 | * |
Benjamin Tissoires | f786bba | 2011-03-22 17:34:01 +0100 | [diff] [blame] | 14 | * This code is partly based on hid-3m-pct.c: |
| 15 | * |
| 16 | * Copyright (c) 2009-2010 Stephane Chatty <chatty@enac.fr> |
| 17 | * Copyright (c) 2010 Henrik Rydberg <rydberg@euromail.se> |
| 18 | * Copyright (c) 2010 Canonical, Ltd. |
| 19 | * |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | /* |
| 23 | * This program is free software; you can redistribute it and/or modify it |
| 24 | * under the terms of the GNU General Public License as published by the Free |
| 25 | * Software Foundation; either version 2 of the License, or (at your option) |
| 26 | * any later version. |
| 27 | */ |
| 28 | |
| 29 | #include <linux/device.h> |
| 30 | #include <linux/hid.h> |
| 31 | #include <linux/module.h> |
| 32 | #include <linux/slab.h> |
| 33 | #include <linux/usb.h> |
| 34 | #include <linux/input/mt.h> |
| 35 | #include "usbhid/usbhid.h" |
| 36 | |
| 37 | |
| 38 | MODULE_AUTHOR("Stephane Chatty <chatty@enac.fr>"); |
Benjamin Tissoires | ef2fafb | 2011-01-31 11:28:21 +0100 | [diff] [blame] | 39 | MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>"); |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 40 | MODULE_DESCRIPTION("HID multitouch panels"); |
| 41 | MODULE_LICENSE("GPL"); |
| 42 | |
| 43 | #include "hid-ids.h" |
| 44 | |
| 45 | /* quirks to control the device */ |
| 46 | #define MT_QUIRK_NOT_SEEN_MEANS_UP (1 << 0) |
| 47 | #define MT_QUIRK_SLOT_IS_CONTACTID (1 << 1) |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 48 | #define MT_QUIRK_CYPRESS (1 << 2) |
Benjamin Tissoires | 5572da0 | 2011-01-07 23:47:27 +0100 | [diff] [blame] | 49 | #define MT_QUIRK_SLOT_IS_CONTACTNUMBER (1 << 3) |
Stephane Chatty | a062cc5 | 2011-09-17 22:27:30 +0200 | [diff] [blame] | 50 | #define MT_QUIRK_ALWAYS_VALID (1 << 4) |
| 51 | #define MT_QUIRK_VALID_IS_INRANGE (1 << 5) |
| 52 | #define MT_QUIRK_VALID_IS_CONFIDENCE (1 << 6) |
Stephane Chatty | a062cc5 | 2011-09-17 22:27:30 +0200 | [diff] [blame] | 53 | #define MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE (1 << 8) |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 54 | |
| 55 | struct mt_slot { |
| 56 | __s32 x, y, p, w, h; |
| 57 | __s32 contactid; /* the device ContactID assigned to this slot */ |
| 58 | bool touch_state; /* is the touch valid? */ |
| 59 | bool seen_in_this_frame;/* has this slot been updated */ |
| 60 | }; |
| 61 | |
Benjamin Tissoires | eec29e3 | 2011-11-23 10:54:28 +0100 | [diff] [blame] | 62 | struct mt_class { |
| 63 | __s32 name; /* MT_CLS */ |
| 64 | __s32 quirks; |
| 65 | __s32 sn_move; /* Signal/noise ratio for move events */ |
| 66 | __s32 sn_width; /* Signal/noise ratio for width events */ |
| 67 | __s32 sn_height; /* Signal/noise ratio for height events */ |
| 68 | __s32 sn_pressure; /* Signal/noise ratio for pressure events */ |
| 69 | __u8 maxcontacts; |
| 70 | }; |
| 71 | |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 72 | struct mt_device { |
| 73 | struct mt_slot curdata; /* placeholder of incoming data */ |
Benjamin Tissoires | eec29e3 | 2011-11-23 10:54:28 +0100 | [diff] [blame] | 74 | struct mt_class mtclass; /* our mt device class */ |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 75 | unsigned last_field_index; /* last field index of the report */ |
| 76 | unsigned last_slot_field; /* the last field of a slot */ |
Benjamin Tissoires | b84bd27 | 2011-06-12 08:22:08 +0200 | [diff] [blame] | 77 | int last_mt_collection; /* last known mt-related collection */ |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 78 | __s8 inputmode; /* InputMode HID feature, -1 if non-existent */ |
| 79 | __u8 num_received; /* how many contacts we received */ |
| 80 | __u8 num_expected; /* expected last contact index */ |
Benjamin Tissoires | 9498f95 | 2011-03-18 14:27:52 +0100 | [diff] [blame] | 81 | __u8 maxcontacts; |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 82 | bool curvalid; /* is the current contact valid? */ |
Benjamin Tissoires | 9498f95 | 2011-03-18 14:27:52 +0100 | [diff] [blame] | 83 | struct mt_slot *slots; |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 84 | }; |
| 85 | |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 86 | /* classes of device behavior */ |
Benjamin Tissoires | 2240828 | 2011-05-20 15:59:34 +0200 | [diff] [blame] | 87 | #define MT_CLS_DEFAULT 0x0001 |
| 88 | |
Stephane Chatty | a062cc5 | 2011-09-17 22:27:30 +0200 | [diff] [blame] | 89 | #define MT_CLS_SERIAL 0x0002 |
| 90 | #define MT_CLS_CONFIDENCE 0x0003 |
Benjamin Tissoires | 5e7ea11 | 2011-11-29 13:13:10 +0100 | [diff] [blame^] | 91 | #define MT_CLS_CONFIDENCE_CONTACT_ID 0x0004 |
| 92 | #define MT_CLS_CONFIDENCE_MINUS_ONE 0x0005 |
| 93 | #define MT_CLS_DUAL_INRANGE_CONTACTID 0x0006 |
| 94 | #define MT_CLS_DUAL_INRANGE_CONTACTNUMBER 0x0007 |
| 95 | #define MT_CLS_DUAL_NSMU_CONTACTID 0x0008 |
Benjamin Tissoires | 2240828 | 2011-05-20 15:59:34 +0200 | [diff] [blame] | 96 | |
| 97 | /* vendor specific classes */ |
| 98 | #define MT_CLS_3M 0x0101 |
| 99 | #define MT_CLS_CYPRESS 0x0102 |
| 100 | #define MT_CLS_EGALAX 0x0103 |
Benjamin Tissoires | 1b723e8 | 2011-11-23 10:54:34 +0100 | [diff] [blame] | 101 | #define MT_CLS_EGALAX_SERIAL 0x0104 |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 102 | |
Benjamin Tissoires | 9498f95 | 2011-03-18 14:27:52 +0100 | [diff] [blame] | 103 | #define MT_DEFAULT_MAXCONTACT 10 |
| 104 | |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 105 | /* |
| 106 | * these device-dependent functions determine what slot corresponds |
| 107 | * to a valid contact that was just read. |
| 108 | */ |
| 109 | |
Benjamin Tissoires | a3b5e57 | 2011-01-07 23:46:30 +0100 | [diff] [blame] | 110 | static int cypress_compute_slot(struct mt_device *td) |
| 111 | { |
| 112 | if (td->curdata.contactid != 0 || td->num_received == 0) |
| 113 | return td->curdata.contactid; |
| 114 | else |
| 115 | return -1; |
| 116 | } |
| 117 | |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 118 | static int find_slot_from_contactid(struct mt_device *td) |
| 119 | { |
| 120 | int i; |
Benjamin Tissoires | 9498f95 | 2011-03-18 14:27:52 +0100 | [diff] [blame] | 121 | for (i = 0; i < td->maxcontacts; ++i) { |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 122 | if (td->slots[i].contactid == td->curdata.contactid && |
| 123 | td->slots[i].touch_state) |
| 124 | return i; |
| 125 | } |
Benjamin Tissoires | 9498f95 | 2011-03-18 14:27:52 +0100 | [diff] [blame] | 126 | for (i = 0; i < td->maxcontacts; ++i) { |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 127 | if (!td->slots[i].seen_in_this_frame && |
| 128 | !td->slots[i].touch_state) |
| 129 | return i; |
| 130 | } |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 131 | /* should not occurs. If this happens that means |
| 132 | * that the device sent more touches that it says |
| 133 | * in the report descriptor. It is ignored then. */ |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 134 | return -1; |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | struct mt_class mt_classes[] = { |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 138 | { .name = MT_CLS_DEFAULT, |
Benjamin Tissoires | 9498f95 | 2011-03-18 14:27:52 +0100 | [diff] [blame] | 139 | .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP }, |
Stephane Chatty | a062cc5 | 2011-09-17 22:27:30 +0200 | [diff] [blame] | 140 | { .name = MT_CLS_SERIAL, |
| 141 | .quirks = MT_QUIRK_ALWAYS_VALID}, |
Benjamin Tissoires | 2240828 | 2011-05-20 15:59:34 +0200 | [diff] [blame] | 142 | { .name = MT_CLS_CONFIDENCE, |
| 143 | .quirks = MT_QUIRK_VALID_IS_CONFIDENCE }, |
Benjamin Tissoires | 5e7ea11 | 2011-11-29 13:13:10 +0100 | [diff] [blame^] | 144 | { .name = MT_CLS_CONFIDENCE_CONTACT_ID, |
| 145 | .quirks = MT_QUIRK_VALID_IS_CONFIDENCE | |
| 146 | MT_QUIRK_SLOT_IS_CONTACTID }, |
Benjamin Tissoires | 2240828 | 2011-05-20 15:59:34 +0200 | [diff] [blame] | 147 | { .name = MT_CLS_CONFIDENCE_MINUS_ONE, |
| 148 | .quirks = MT_QUIRK_VALID_IS_CONFIDENCE | |
| 149 | MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE }, |
Benjamin Tissoires | 1e9cf35 | 2011-01-31 11:28:20 +0100 | [diff] [blame] | 150 | { .name = MT_CLS_DUAL_INRANGE_CONTACTID, |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 151 | .quirks = MT_QUIRK_VALID_IS_INRANGE | |
| 152 | MT_QUIRK_SLOT_IS_CONTACTID, |
| 153 | .maxcontacts = 2 }, |
Benjamin Tissoires | 1e9cf35 | 2011-01-31 11:28:20 +0100 | [diff] [blame] | 154 | { .name = MT_CLS_DUAL_INRANGE_CONTACTNUMBER, |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 155 | .quirks = MT_QUIRK_VALID_IS_INRANGE | |
| 156 | MT_QUIRK_SLOT_IS_CONTACTNUMBER, |
| 157 | .maxcontacts = 2 }, |
Benjamin Tissoires | 2240828 | 2011-05-20 15:59:34 +0200 | [diff] [blame] | 158 | { .name = MT_CLS_DUAL_NSMU_CONTACTID, |
| 159 | .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP | |
| 160 | MT_QUIRK_SLOT_IS_CONTACTID, |
| 161 | .maxcontacts = 2 }, |
| 162 | |
| 163 | /* |
| 164 | * vendor specific classes |
| 165 | */ |
| 166 | { .name = MT_CLS_3M, |
| 167 | .quirks = MT_QUIRK_VALID_IS_CONFIDENCE | |
| 168 | MT_QUIRK_SLOT_IS_CONTACTID, |
| 169 | .sn_move = 2048, |
| 170 | .sn_width = 128, |
| 171 | .sn_height = 128 }, |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 172 | { .name = MT_CLS_CYPRESS, |
| 173 | .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP | |
| 174 | MT_QUIRK_CYPRESS, |
| 175 | .maxcontacts = 10 }, |
Richard Nauber | 4875ac1 | 2011-03-09 06:20:57 +0100 | [diff] [blame] | 176 | { .name = MT_CLS_EGALAX, |
| 177 | .quirks = MT_QUIRK_SLOT_IS_CONTACTID | |
Benjamin Tissoires | 2261bb9 | 2011-11-23 10:54:29 +0100 | [diff] [blame] | 178 | MT_QUIRK_VALID_IS_INRANGE, |
Richard Nauber | 4875ac1 | 2011-03-09 06:20:57 +0100 | [diff] [blame] | 179 | .sn_move = 4096, |
| 180 | .sn_pressure = 32, |
| 181 | }, |
Benjamin Tissoires | 1b723e8 | 2011-11-23 10:54:34 +0100 | [diff] [blame] | 182 | { .name = MT_CLS_EGALAX_SERIAL, |
| 183 | .quirks = MT_QUIRK_SLOT_IS_CONTACTID | |
| 184 | MT_QUIRK_ALWAYS_VALID, |
| 185 | .sn_move = 4096, |
| 186 | .sn_pressure = 32, |
| 187 | }, |
Benjamin Tissoires | 043b403 | 2011-03-18 14:27:53 +0100 | [diff] [blame] | 188 | |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 189 | { } |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 190 | }; |
| 191 | |
Benjamin Tissoires | eec29e3 | 2011-11-23 10:54:28 +0100 | [diff] [blame] | 192 | static ssize_t mt_show_quirks(struct device *dev, |
| 193 | struct device_attribute *attr, |
| 194 | char *buf) |
| 195 | { |
| 196 | struct hid_device *hdev = container_of(dev, struct hid_device, dev); |
| 197 | struct mt_device *td = hid_get_drvdata(hdev); |
| 198 | |
| 199 | return sprintf(buf, "%u\n", td->mtclass.quirks); |
| 200 | } |
| 201 | |
| 202 | static ssize_t mt_set_quirks(struct device *dev, |
| 203 | struct device_attribute *attr, |
| 204 | const char *buf, size_t count) |
| 205 | { |
| 206 | struct hid_device *hdev = container_of(dev, struct hid_device, dev); |
| 207 | struct mt_device *td = hid_get_drvdata(hdev); |
| 208 | |
| 209 | unsigned long val; |
| 210 | |
| 211 | if (kstrtoul(buf, 0, &val)) |
| 212 | return -EINVAL; |
| 213 | |
| 214 | td->mtclass.quirks = val; |
| 215 | |
| 216 | return count; |
| 217 | } |
| 218 | |
| 219 | static DEVICE_ATTR(quirks, S_IWUSR | S_IRUGO, mt_show_quirks, mt_set_quirks); |
| 220 | |
| 221 | static struct attribute *sysfs_attrs[] = { |
| 222 | &dev_attr_quirks.attr, |
| 223 | NULL |
| 224 | }; |
| 225 | |
| 226 | static struct attribute_group mt_attribute_group = { |
| 227 | .attrs = sysfs_attrs |
| 228 | }; |
| 229 | |
Henrik Rydberg | f635bd1 | 2011-02-24 19:30:59 +0100 | [diff] [blame] | 230 | static void mt_feature_mapping(struct hid_device *hdev, |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 231 | struct hid_field *field, struct hid_usage *usage) |
| 232 | { |
Benjamin Tissoires | 9498f95 | 2011-03-18 14:27:52 +0100 | [diff] [blame] | 233 | struct mt_device *td = hid_get_drvdata(hdev); |
| 234 | |
| 235 | switch (usage->hid) { |
| 236 | case HID_DG_INPUTMODE: |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 237 | td->inputmode = field->report->id; |
Benjamin Tissoires | 9498f95 | 2011-03-18 14:27:52 +0100 | [diff] [blame] | 238 | break; |
| 239 | case HID_DG_CONTACTMAX: |
| 240 | td->maxcontacts = field->value[0]; |
Benjamin Tissoires | eec29e3 | 2011-11-23 10:54:28 +0100 | [diff] [blame] | 241 | if (td->mtclass.maxcontacts) |
Benjamin Tissoires | 9498f95 | 2011-03-18 14:27:52 +0100 | [diff] [blame] | 242 | /* check if the maxcontacts is given by the class */ |
Benjamin Tissoires | eec29e3 | 2011-11-23 10:54:28 +0100 | [diff] [blame] | 243 | td->maxcontacts = td->mtclass.maxcontacts; |
Benjamin Tissoires | 9498f95 | 2011-03-18 14:27:52 +0100 | [diff] [blame] | 244 | |
| 245 | break; |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 246 | } |
| 247 | } |
| 248 | |
| 249 | static void set_abs(struct input_dev *input, unsigned int code, |
| 250 | struct hid_field *field, int snratio) |
| 251 | { |
| 252 | int fmin = field->logical_minimum; |
| 253 | int fmax = field->logical_maximum; |
| 254 | int fuzz = snratio ? (fmax - fmin) / snratio : 0; |
| 255 | input_set_abs_params(input, code, fmin, fmax, fuzz, 0); |
| 256 | } |
| 257 | |
| 258 | static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi, |
| 259 | struct hid_field *field, struct hid_usage *usage, |
| 260 | unsigned long **bit, int *max) |
| 261 | { |
| 262 | struct mt_device *td = hid_get_drvdata(hdev); |
Benjamin Tissoires | eec29e3 | 2011-11-23 10:54:28 +0100 | [diff] [blame] | 263 | struct mt_class *cls = &td->mtclass; |
Richard Nauber | 4875ac1 | 2011-03-09 06:20:57 +0100 | [diff] [blame] | 264 | |
Jeff Brown | 658d4ae | 2011-08-15 16:44:28 -0700 | [diff] [blame] | 265 | /* Only map fields from TouchScreen or TouchPad collections. |
| 266 | * We need to ignore fields that belong to other collections |
| 267 | * such as Mouse that might have the same GenericDesktop usages. */ |
| 268 | if (field->application == HID_DG_TOUCHSCREEN) |
| 269 | set_bit(INPUT_PROP_DIRECT, hi->input->propbit); |
| 270 | else if (field->application == HID_DG_TOUCHPAD) |
| 271 | set_bit(INPUT_PROP_POINTER, hi->input->propbit); |
| 272 | else |
| 273 | return 0; |
| 274 | |
Benjamin Tissoires | 2261bb9 | 2011-11-23 10:54:29 +0100 | [diff] [blame] | 275 | /* eGalax devices provide a Digitizer.Stylus input which overrides |
| 276 | * the correct Digitizers.Finger X/Y ranges. |
| 277 | * Let's just ignore this input. */ |
| 278 | if (field->physical == HID_DG_STYLUS) |
| 279 | return -1; |
| 280 | |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 281 | switch (usage->hid & HID_USAGE_PAGE) { |
| 282 | |
| 283 | case HID_UP_GENDESK: |
| 284 | switch (usage->hid) { |
| 285 | case HID_GD_X: |
| 286 | hid_map_usage(hi, usage, bit, max, |
| 287 | EV_ABS, ABS_MT_POSITION_X); |
| 288 | set_abs(hi->input, ABS_MT_POSITION_X, field, |
| 289 | cls->sn_move); |
| 290 | /* touchscreen emulation */ |
| 291 | set_abs(hi->input, ABS_X, field, cls->sn_move); |
Benjamin Tissoires | b84bd27 | 2011-06-12 08:22:08 +0200 | [diff] [blame] | 292 | if (td->last_mt_collection == usage->collection_index) { |
| 293 | td->last_slot_field = usage->hid; |
| 294 | td->last_field_index = field->index; |
| 295 | } |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 296 | return 1; |
| 297 | case HID_GD_Y: |
| 298 | hid_map_usage(hi, usage, bit, max, |
| 299 | EV_ABS, ABS_MT_POSITION_Y); |
| 300 | set_abs(hi->input, ABS_MT_POSITION_Y, field, |
| 301 | cls->sn_move); |
| 302 | /* touchscreen emulation */ |
| 303 | set_abs(hi->input, ABS_Y, field, cls->sn_move); |
Benjamin Tissoires | b84bd27 | 2011-06-12 08:22:08 +0200 | [diff] [blame] | 304 | if (td->last_mt_collection == usage->collection_index) { |
| 305 | td->last_slot_field = usage->hid; |
| 306 | td->last_field_index = field->index; |
| 307 | } |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 308 | return 1; |
| 309 | } |
| 310 | return 0; |
| 311 | |
| 312 | case HID_UP_DIGITIZER: |
| 313 | switch (usage->hid) { |
| 314 | case HID_DG_INRANGE: |
Benjamin Tissoires | b84bd27 | 2011-06-12 08:22:08 +0200 | [diff] [blame] | 315 | if (td->last_mt_collection == usage->collection_index) { |
| 316 | td->last_slot_field = usage->hid; |
| 317 | td->last_field_index = field->index; |
| 318 | } |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 319 | return 1; |
| 320 | case HID_DG_CONFIDENCE: |
Benjamin Tissoires | b84bd27 | 2011-06-12 08:22:08 +0200 | [diff] [blame] | 321 | if (td->last_mt_collection == usage->collection_index) { |
| 322 | td->last_slot_field = usage->hid; |
| 323 | td->last_field_index = field->index; |
| 324 | } |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 325 | return 1; |
| 326 | case HID_DG_TIPSWITCH: |
| 327 | hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_TOUCH); |
| 328 | input_set_capability(hi->input, EV_KEY, BTN_TOUCH); |
Benjamin Tissoires | b84bd27 | 2011-06-12 08:22:08 +0200 | [diff] [blame] | 329 | if (td->last_mt_collection == usage->collection_index) { |
| 330 | td->last_slot_field = usage->hid; |
| 331 | td->last_field_index = field->index; |
| 332 | } |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 333 | return 1; |
| 334 | case HID_DG_CONTACTID: |
Benjamin Tissoires | 50bc03a | 2011-06-21 15:01:53 +0200 | [diff] [blame] | 335 | if (!td->maxcontacts) |
| 336 | td->maxcontacts = MT_DEFAULT_MAXCONTACT; |
Benjamin Tissoires | 9498f95 | 2011-03-18 14:27:52 +0100 | [diff] [blame] | 337 | input_mt_init_slots(hi->input, td->maxcontacts); |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 338 | td->last_slot_field = usage->hid; |
Benjamin Tissoires | 2955cae | 2011-04-21 14:15:59 +0200 | [diff] [blame] | 339 | td->last_field_index = field->index; |
Benjamin Tissoires | b84bd27 | 2011-06-12 08:22:08 +0200 | [diff] [blame] | 340 | td->last_mt_collection = usage->collection_index; |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 341 | return 1; |
| 342 | case HID_DG_WIDTH: |
| 343 | hid_map_usage(hi, usage, bit, max, |
| 344 | EV_ABS, ABS_MT_TOUCH_MAJOR); |
Benjamin Tissoires | f786bba | 2011-03-22 17:34:01 +0100 | [diff] [blame] | 345 | set_abs(hi->input, ABS_MT_TOUCH_MAJOR, field, |
| 346 | cls->sn_width); |
Benjamin Tissoires | b84bd27 | 2011-06-12 08:22:08 +0200 | [diff] [blame] | 347 | if (td->last_mt_collection == usage->collection_index) { |
| 348 | td->last_slot_field = usage->hid; |
| 349 | td->last_field_index = field->index; |
| 350 | } |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 351 | return 1; |
| 352 | case HID_DG_HEIGHT: |
| 353 | hid_map_usage(hi, usage, bit, max, |
| 354 | EV_ABS, ABS_MT_TOUCH_MINOR); |
Benjamin Tissoires | f786bba | 2011-03-22 17:34:01 +0100 | [diff] [blame] | 355 | set_abs(hi->input, ABS_MT_TOUCH_MINOR, field, |
| 356 | cls->sn_height); |
Benjamin Tissoires | 1e648a1 | 2011-03-18 14:27:55 +0100 | [diff] [blame] | 357 | input_set_abs_params(hi->input, |
| 358 | ABS_MT_ORIENTATION, 0, 1, 0, 0); |
Benjamin Tissoires | b84bd27 | 2011-06-12 08:22:08 +0200 | [diff] [blame] | 359 | if (td->last_mt_collection == usage->collection_index) { |
| 360 | td->last_slot_field = usage->hid; |
| 361 | td->last_field_index = field->index; |
| 362 | } |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 363 | return 1; |
| 364 | case HID_DG_TIPPRESSURE: |
| 365 | hid_map_usage(hi, usage, bit, max, |
| 366 | EV_ABS, ABS_MT_PRESSURE); |
| 367 | set_abs(hi->input, ABS_MT_PRESSURE, field, |
| 368 | cls->sn_pressure); |
| 369 | /* touchscreen emulation */ |
| 370 | set_abs(hi->input, ABS_PRESSURE, field, |
| 371 | cls->sn_pressure); |
Benjamin Tissoires | b84bd27 | 2011-06-12 08:22:08 +0200 | [diff] [blame] | 372 | if (td->last_mt_collection == usage->collection_index) { |
| 373 | td->last_slot_field = usage->hid; |
| 374 | td->last_field_index = field->index; |
| 375 | } |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 376 | return 1; |
| 377 | case HID_DG_CONTACTCOUNT: |
Benjamin Tissoires | b84bd27 | 2011-06-12 08:22:08 +0200 | [diff] [blame] | 378 | if (td->last_mt_collection == usage->collection_index) |
| 379 | td->last_field_index = field->index; |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 380 | return 1; |
| 381 | case HID_DG_CONTACTMAX: |
| 382 | /* we don't set td->last_slot_field as contactcount and |
| 383 | * contact max are global to the report */ |
Benjamin Tissoires | b84bd27 | 2011-06-12 08:22:08 +0200 | [diff] [blame] | 384 | if (td->last_mt_collection == usage->collection_index) |
| 385 | td->last_field_index = field->index; |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 386 | return -1; |
| 387 | } |
| 388 | /* let hid-input decide for the others */ |
| 389 | return 0; |
| 390 | |
| 391 | case 0xff000000: |
| 392 | /* we do not want to map these: no input-oriented meaning */ |
| 393 | return -1; |
| 394 | } |
| 395 | |
| 396 | return 0; |
| 397 | } |
| 398 | |
| 399 | static int mt_input_mapped(struct hid_device *hdev, struct hid_input *hi, |
| 400 | struct hid_field *field, struct hid_usage *usage, |
| 401 | unsigned long **bit, int *max) |
| 402 | { |
| 403 | if (usage->type == EV_KEY || usage->type == EV_ABS) |
| 404 | set_bit(usage->type, hi->input->evbit); |
| 405 | |
| 406 | return -1; |
| 407 | } |
| 408 | |
| 409 | static int mt_compute_slot(struct mt_device *td) |
| 410 | { |
Benjamin Tissoires | eec29e3 | 2011-11-23 10:54:28 +0100 | [diff] [blame] | 411 | __s32 quirks = td->mtclass.quirks; |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 412 | |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 413 | if (quirks & MT_QUIRK_SLOT_IS_CONTACTID) |
| 414 | return td->curdata.contactid; |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 415 | |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 416 | if (quirks & MT_QUIRK_CYPRESS) |
Benjamin Tissoires | a3b5e57 | 2011-01-07 23:46:30 +0100 | [diff] [blame] | 417 | return cypress_compute_slot(td); |
| 418 | |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 419 | if (quirks & MT_QUIRK_SLOT_IS_CONTACTNUMBER) |
| 420 | return td->num_received; |
Benjamin Tissoires | 5572da0 | 2011-01-07 23:47:27 +0100 | [diff] [blame] | 421 | |
Benjamin Tissoires | 4a6ee68 | 2011-04-22 11:51:48 +0200 | [diff] [blame] | 422 | if (quirks & MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE) |
| 423 | return td->curdata.contactid - 1; |
| 424 | |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 425 | return find_slot_from_contactid(td); |
| 426 | } |
| 427 | |
| 428 | /* |
| 429 | * this function is called when a whole contact has been processed, |
| 430 | * so that it can assign it to a slot and store the data there |
| 431 | */ |
| 432 | static void mt_complete_slot(struct mt_device *td) |
| 433 | { |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 434 | td->curdata.seen_in_this_frame = true; |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 435 | if (td->curvalid) { |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 436 | int slotnum = mt_compute_slot(td); |
| 437 | |
Benjamin Tissoires | 9498f95 | 2011-03-18 14:27:52 +0100 | [diff] [blame] | 438 | if (slotnum >= 0 && slotnum < td->maxcontacts) |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 439 | td->slots[slotnum] = td->curdata; |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 440 | } |
| 441 | td->num_received++; |
| 442 | } |
| 443 | |
| 444 | |
| 445 | /* |
| 446 | * this function is called when a whole packet has been received and processed, |
| 447 | * so that it can decide what to send to the input layer. |
| 448 | */ |
| 449 | static void mt_emit_event(struct mt_device *td, struct input_dev *input) |
| 450 | { |
| 451 | int i; |
| 452 | |
Benjamin Tissoires | 9498f95 | 2011-03-18 14:27:52 +0100 | [diff] [blame] | 453 | for (i = 0; i < td->maxcontacts; ++i) { |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 454 | struct mt_slot *s = &(td->slots[i]); |
Benjamin Tissoires | eec29e3 | 2011-11-23 10:54:28 +0100 | [diff] [blame] | 455 | if ((td->mtclass.quirks & MT_QUIRK_NOT_SEEN_MEANS_UP) && |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 456 | !s->seen_in_this_frame) { |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 457 | s->touch_state = false; |
| 458 | } |
| 459 | |
| 460 | input_mt_slot(input, i); |
| 461 | input_mt_report_slot_state(input, MT_TOOL_FINGER, |
| 462 | s->touch_state); |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 463 | if (s->touch_state) { |
Benjamin Tissoires | f786bba | 2011-03-22 17:34:01 +0100 | [diff] [blame] | 464 | /* this finger is on the screen */ |
| 465 | int wide = (s->w > s->h); |
| 466 | /* divided by two to match visual scale of touch */ |
| 467 | int major = max(s->w, s->h) >> 1; |
| 468 | int minor = min(s->w, s->h) >> 1; |
| 469 | |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 470 | input_event(input, EV_ABS, ABS_MT_POSITION_X, s->x); |
| 471 | input_event(input, EV_ABS, ABS_MT_POSITION_Y, s->y); |
Benjamin Tissoires | f786bba | 2011-03-22 17:34:01 +0100 | [diff] [blame] | 472 | input_event(input, EV_ABS, ABS_MT_ORIENTATION, wide); |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 473 | input_event(input, EV_ABS, ABS_MT_PRESSURE, s->p); |
Benjamin Tissoires | f786bba | 2011-03-22 17:34:01 +0100 | [diff] [blame] | 474 | input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, major); |
| 475 | input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, minor); |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 476 | } |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 477 | s->seen_in_this_frame = false; |
| 478 | |
| 479 | } |
| 480 | |
| 481 | input_mt_report_pointer_emulation(input, true); |
| 482 | input_sync(input); |
| 483 | td->num_received = 0; |
| 484 | } |
| 485 | |
| 486 | |
| 487 | |
| 488 | static int mt_event(struct hid_device *hid, struct hid_field *field, |
| 489 | struct hid_usage *usage, __s32 value) |
| 490 | { |
| 491 | struct mt_device *td = hid_get_drvdata(hid); |
Benjamin Tissoires | eec29e3 | 2011-11-23 10:54:28 +0100 | [diff] [blame] | 492 | __s32 quirks = td->mtclass.quirks; |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 493 | |
Benjamin Tissoires | 9498f95 | 2011-03-18 14:27:52 +0100 | [diff] [blame] | 494 | if (hid->claimed & HID_CLAIMED_INPUT && td->slots) { |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 495 | switch (usage->hid) { |
| 496 | case HID_DG_INRANGE: |
Stephane Chatty | a062cc5 | 2011-09-17 22:27:30 +0200 | [diff] [blame] | 497 | if (quirks & MT_QUIRK_ALWAYS_VALID) |
| 498 | td->curvalid = true; |
| 499 | else if (quirks & MT_QUIRK_VALID_IS_INRANGE) |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 500 | td->curvalid = value; |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 501 | break; |
| 502 | case HID_DG_TIPSWITCH: |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 503 | if (quirks & MT_QUIRK_NOT_SEEN_MEANS_UP) |
| 504 | td->curvalid = value; |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 505 | td->curdata.touch_state = value; |
| 506 | break; |
| 507 | case HID_DG_CONFIDENCE: |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 508 | if (quirks & MT_QUIRK_VALID_IS_CONFIDENCE) |
| 509 | td->curvalid = value; |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 510 | break; |
| 511 | case HID_DG_CONTACTID: |
| 512 | td->curdata.contactid = value; |
| 513 | break; |
| 514 | case HID_DG_TIPPRESSURE: |
| 515 | td->curdata.p = value; |
| 516 | break; |
| 517 | case HID_GD_X: |
| 518 | td->curdata.x = value; |
| 519 | break; |
| 520 | case HID_GD_Y: |
| 521 | td->curdata.y = value; |
| 522 | break; |
| 523 | case HID_DG_WIDTH: |
| 524 | td->curdata.w = value; |
| 525 | break; |
| 526 | case HID_DG_HEIGHT: |
| 527 | td->curdata.h = value; |
| 528 | break; |
| 529 | case HID_DG_CONTACTCOUNT: |
| 530 | /* |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 531 | * Includes multi-packet support where subsequent |
| 532 | * packets are sent with zero contactcount. |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 533 | */ |
| 534 | if (value) |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 535 | td->num_expected = value; |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 536 | break; |
| 537 | |
| 538 | default: |
| 539 | /* fallback to the generic hidinput handling */ |
| 540 | return 0; |
| 541 | } |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 542 | |
Henrik Rydberg | f153fc3 | 2011-03-09 06:35:25 +0100 | [diff] [blame] | 543 | if (usage->hid == td->last_slot_field) { |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 544 | mt_complete_slot(td); |
Henrik Rydberg | f153fc3 | 2011-03-09 06:35:25 +0100 | [diff] [blame] | 545 | } |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 546 | |
| 547 | if (field->index == td->last_field_index |
| 548 | && td->num_received >= td->num_expected) |
| 549 | mt_emit_event(td, field->hidinput->input); |
| 550 | |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 551 | } |
| 552 | |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 553 | /* we have handled the hidinput part, now remains hiddev */ |
| 554 | if (hid->claimed & HID_CLAIMED_HIDDEV && hid->hiddev_hid_event) |
| 555 | hid->hiddev_hid_event(hid, field, usage, value); |
| 556 | |
| 557 | return 1; |
| 558 | } |
| 559 | |
| 560 | static void mt_set_input_mode(struct hid_device *hdev) |
| 561 | { |
| 562 | struct mt_device *td = hid_get_drvdata(hdev); |
| 563 | struct hid_report *r; |
| 564 | struct hid_report_enum *re; |
| 565 | |
| 566 | if (td->inputmode < 0) |
| 567 | return; |
| 568 | |
| 569 | re = &(hdev->report_enum[HID_FEATURE_REPORT]); |
| 570 | r = re->report_id_hash[td->inputmode]; |
| 571 | if (r) { |
| 572 | r->field[0]->value[0] = 0x02; |
| 573 | usbhid_submit_report(hdev, r, USB_DIR_OUT); |
| 574 | } |
| 575 | } |
| 576 | |
| 577 | static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) |
| 578 | { |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 579 | int ret, i; |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 580 | struct mt_device *td; |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 581 | struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */ |
| 582 | |
| 583 | for (i = 0; mt_classes[i].name ; i++) { |
| 584 | if (id->driver_data == mt_classes[i].name) { |
| 585 | mtclass = &(mt_classes[i]); |
| 586 | break; |
| 587 | } |
| 588 | } |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 589 | |
Henrik Rydberg | d682bd7 | 2011-11-01 15:26:31 +0100 | [diff] [blame] | 590 | /* This allows the driver to correctly support devices |
| 591 | * that emit events over several HID messages. |
| 592 | */ |
| 593 | hdev->quirks |= HID_QUIRK_NO_INPUT_SYNC; |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 594 | |
Benjamin Tissoires | 9498f95 | 2011-03-18 14:27:52 +0100 | [diff] [blame] | 595 | td = kzalloc(sizeof(struct mt_device), GFP_KERNEL); |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 596 | if (!td) { |
| 597 | dev_err(&hdev->dev, "cannot allocate multitouch data\n"); |
| 598 | return -ENOMEM; |
| 599 | } |
Benjamin Tissoires | eec29e3 | 2011-11-23 10:54:28 +0100 | [diff] [blame] | 600 | td->mtclass = *mtclass; |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 601 | td->inputmode = -1; |
Benjamin Tissoires | b84bd27 | 2011-06-12 08:22:08 +0200 | [diff] [blame] | 602 | td->last_mt_collection = -1; |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 603 | hid_set_drvdata(hdev, td); |
| 604 | |
| 605 | ret = hid_parse(hdev); |
| 606 | if (ret != 0) |
| 607 | goto fail; |
| 608 | |
| 609 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 610 | if (ret) |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 611 | goto fail; |
| 612 | |
Benjamin Tissoires | 9498f95 | 2011-03-18 14:27:52 +0100 | [diff] [blame] | 613 | td->slots = kzalloc(td->maxcontacts * sizeof(struct mt_slot), |
| 614 | GFP_KERNEL); |
| 615 | if (!td->slots) { |
| 616 | dev_err(&hdev->dev, "cannot allocate multitouch slots\n"); |
| 617 | hid_hw_stop(hdev); |
| 618 | ret = -ENOMEM; |
| 619 | goto fail; |
| 620 | } |
| 621 | |
Benjamin Tissoires | eec29e3 | 2011-11-23 10:54:28 +0100 | [diff] [blame] | 622 | ret = sysfs_create_group(&hdev->dev.kobj, &mt_attribute_group); |
| 623 | |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 624 | mt_set_input_mode(hdev); |
| 625 | |
| 626 | return 0; |
| 627 | |
| 628 | fail: |
| 629 | kfree(td); |
| 630 | return ret; |
| 631 | } |
| 632 | |
| 633 | #ifdef CONFIG_PM |
| 634 | static int mt_reset_resume(struct hid_device *hdev) |
| 635 | { |
| 636 | mt_set_input_mode(hdev); |
| 637 | return 0; |
| 638 | } |
| 639 | #endif |
| 640 | |
| 641 | static void mt_remove(struct hid_device *hdev) |
| 642 | { |
| 643 | struct mt_device *td = hid_get_drvdata(hdev); |
Benjamin Tissoires | eec29e3 | 2011-11-23 10:54:28 +0100 | [diff] [blame] | 644 | sysfs_remove_group(&hdev->dev.kobj, &mt_attribute_group); |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 645 | hid_hw_stop(hdev); |
Benjamin Tissoires | 9498f95 | 2011-03-18 14:27:52 +0100 | [diff] [blame] | 646 | kfree(td->slots); |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 647 | kfree(td); |
| 648 | hid_set_drvdata(hdev, NULL); |
| 649 | } |
| 650 | |
| 651 | static const struct hid_device_id mt_devices[] = { |
| 652 | |
Benjamin Tissoires | f786bba | 2011-03-22 17:34:01 +0100 | [diff] [blame] | 653 | /* 3M panels */ |
| 654 | { .driver_data = MT_CLS_3M, |
| 655 | HID_USB_DEVICE(USB_VENDOR_ID_3M, |
| 656 | USB_DEVICE_ID_3M1968) }, |
| 657 | { .driver_data = MT_CLS_3M, |
| 658 | HID_USB_DEVICE(USB_VENDOR_ID_3M, |
| 659 | USB_DEVICE_ID_3M2256) }, |
| 660 | |
Benjamin Tissoires | e6aac34 | 2011-05-19 14:18:13 +0200 | [diff] [blame] | 661 | /* ActionStar panels */ |
| 662 | { .driver_data = MT_CLS_DEFAULT, |
| 663 | HID_USB_DEVICE(USB_VENDOR_ID_ACTIONSTAR, |
| 664 | USB_DEVICE_ID_ACTIONSTAR_1011) }, |
| 665 | |
Benjamin Tissoires | a841b62 | 2011-03-18 14:27:54 +0100 | [diff] [blame] | 666 | /* Cando panels */ |
| 667 | { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER, |
| 668 | HID_USB_DEVICE(USB_VENDOR_ID_CANDO, |
| 669 | USB_DEVICE_ID_CANDO_MULTI_TOUCH) }, |
| 670 | { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER, |
| 671 | HID_USB_DEVICE(USB_VENDOR_ID_CANDO, |
| 672 | USB_DEVICE_ID_CANDO_MULTI_TOUCH_10_1) }, |
| 673 | { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER, |
| 674 | HID_USB_DEVICE(USB_VENDOR_ID_CANDO, |
| 675 | USB_DEVICE_ID_CANDO_MULTI_TOUCH_11_6) }, |
| 676 | { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER, |
| 677 | HID_USB_DEVICE(USB_VENDOR_ID_CANDO, |
| 678 | USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6) }, |
| 679 | |
Austin Zhang | 942fd42 | 2011-05-28 02:03:47 +0800 | [diff] [blame] | 680 | /* Chunghwa Telecom touch panels */ |
| 681 | { .driver_data = MT_CLS_DEFAULT, |
| 682 | HID_USB_DEVICE(USB_VENDOR_ID_CHUNGHWAT, |
| 683 | USB_DEVICE_ID_CHUNGHWAT_MULTITOUCH) }, |
| 684 | |
Benjamin Tissoires | 79603dc | 2011-05-19 14:18:14 +0200 | [diff] [blame] | 685 | /* CVTouch panels */ |
| 686 | { .driver_data = MT_CLS_DEFAULT, |
| 687 | HID_USB_DEVICE(USB_VENDOR_ID_CVTOUCH, |
| 688 | USB_DEVICE_ID_CVTOUCH_SCREEN) }, |
| 689 | |
Benjamin Tissoires | a3b5e57 | 2011-01-07 23:46:30 +0100 | [diff] [blame] | 690 | /* Cypress panel */ |
| 691 | { .driver_data = MT_CLS_CYPRESS, |
| 692 | HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, |
| 693 | USB_DEVICE_ID_CYPRESS_TRUETOUCH) }, |
| 694 | |
Benjamin Tissoires | 2240828 | 2011-05-20 15:59:34 +0200 | [diff] [blame] | 695 | /* eGalax devices (resistive) */ |
Benjamin Tissoires | e36f690 | 2011-11-23 10:54:31 +0100 | [diff] [blame] | 696 | { .driver_data = MT_CLS_EGALAX, |
Benjamin Tissoires | 2240828 | 2011-05-20 15:59:34 +0200 | [diff] [blame] | 697 | HID_USB_DEVICE(USB_VENDOR_ID_DWAV, |
Benjamin Tissoires | e36f690 | 2011-11-23 10:54:31 +0100 | [diff] [blame] | 698 | USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480D) }, |
| 699 | { .driver_data = MT_CLS_EGALAX, |
Benjamin Tissoires | 2240828 | 2011-05-20 15:59:34 +0200 | [diff] [blame] | 700 | HID_USB_DEVICE(USB_VENDOR_ID_DWAV, |
Benjamin Tissoires | e36f690 | 2011-11-23 10:54:31 +0100 | [diff] [blame] | 701 | USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480E) }, |
Benjamin Tissoires | 2240828 | 2011-05-20 15:59:34 +0200 | [diff] [blame] | 702 | |
| 703 | /* eGalax devices (capacitive) */ |
Benjamin Tissoires | e36f690 | 2011-11-23 10:54:31 +0100 | [diff] [blame] | 704 | { .driver_data = MT_CLS_EGALAX, |
Benjamin Tissoires | 2240828 | 2011-05-20 15:59:34 +0200 | [diff] [blame] | 705 | HID_USB_DEVICE(USB_VENDOR_ID_DWAV, |
Benjamin Tissoires | e36f690 | 2011-11-23 10:54:31 +0100 | [diff] [blame] | 706 | USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_720C) }, |
| 707 | { .driver_data = MT_CLS_EGALAX, |
Benjamin Tissoires | 2240828 | 2011-05-20 15:59:34 +0200 | [diff] [blame] | 708 | HID_USB_DEVICE(USB_VENDOR_ID_DWAV, |
Benjamin Tissoires | e36f690 | 2011-11-23 10:54:31 +0100 | [diff] [blame] | 709 | USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_726B) }, |
| 710 | { .driver_data = MT_CLS_EGALAX, |
Benjamin Tissoires | 2240828 | 2011-05-20 15:59:34 +0200 | [diff] [blame] | 711 | HID_USB_DEVICE(USB_VENDOR_ID_DWAV, |
Benjamin Tissoires | e36f690 | 2011-11-23 10:54:31 +0100 | [diff] [blame] | 712 | USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72A1) }, |
| 713 | { .driver_data = MT_CLS_EGALAX, |
Chris Bagwell | 1fd8f04 | 2011-11-23 10:54:27 +0100 | [diff] [blame] | 714 | HID_USB_DEVICE(USB_VENDOR_ID_DWAV, |
Benjamin Tissoires | 66f0612 | 2011-11-23 10:54:33 +0100 | [diff] [blame] | 715 | USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72FA) }, |
| 716 | { .driver_data = MT_CLS_EGALAX, |
| 717 | HID_USB_DEVICE(USB_VENDOR_ID_DWAV, |
Marek Vasut | bb9ff21 | 2011-11-23 10:54:32 +0100 | [diff] [blame] | 718 | USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7302) }, |
Benjamin Tissoires | 1b723e8 | 2011-11-23 10:54:34 +0100 | [diff] [blame] | 719 | { .driver_data = MT_CLS_EGALAX_SERIAL, |
Marek Vasut | bb9ff21 | 2011-11-23 10:54:32 +0100 | [diff] [blame] | 720 | HID_USB_DEVICE(USB_VENDOR_ID_DWAV, |
Benjamin Tissoires | e36f690 | 2011-11-23 10:54:31 +0100 | [diff] [blame] | 721 | USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_A001) }, |
Benjamin Tissoires | 2240828 | 2011-05-20 15:59:34 +0200 | [diff] [blame] | 722 | |
Benjamin Tissoires | c04abee | 2011-05-19 11:37:29 +0200 | [diff] [blame] | 723 | /* Elo TouchSystems IntelliTouch Plus panel */ |
| 724 | { .driver_data = MT_CLS_DUAL_NSMU_CONTACTID, |
| 725 | HID_USB_DEVICE(USB_VENDOR_ID_ELO, |
| 726 | USB_DEVICE_ID_ELO_TS2515) }, |
| 727 | |
Benjamin Tissoires | 5572da0 | 2011-01-07 23:47:27 +0100 | [diff] [blame] | 728 | /* GeneralTouch panel */ |
Benjamin Tissoires | 1e9cf35 | 2011-01-31 11:28:20 +0100 | [diff] [blame] | 729 | { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER, |
Benjamin Tissoires | 5572da0 | 2011-01-07 23:47:27 +0100 | [diff] [blame] | 730 | HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, |
| 731 | USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS) }, |
| 732 | |
Benjamin Tissoires | ee0fbd1 | 2011-05-19 14:18:15 +0200 | [diff] [blame] | 733 | /* GoodTouch panels */ |
| 734 | { .driver_data = MT_CLS_DEFAULT, |
| 735 | HID_USB_DEVICE(USB_VENDOR_ID_GOODTOUCH, |
| 736 | USB_DEVICE_ID_GOODTOUCH_000f) }, |
| 737 | |
Stephane Chatty | a062cc5 | 2011-09-17 22:27:30 +0200 | [diff] [blame] | 738 | /* Ideacom panel */ |
| 739 | { .driver_data = MT_CLS_SERIAL, |
| 740 | HID_USB_DEVICE(USB_VENDOR_ID_IDEACOM, |
| 741 | USB_DEVICE_ID_IDEACOM_IDC6650) }, |
| 742 | |
Austin Zhang | 4e61f0d | 2011-05-09 23:54:14 +0800 | [diff] [blame] | 743 | /* Ilitek dual touch panel */ |
| 744 | { .driver_data = MT_CLS_DEFAULT, |
| 745 | HID_USB_DEVICE(USB_VENDOR_ID_ILITEK, |
| 746 | USB_DEVICE_ID_ILITEK_MULTITOUCH) }, |
| 747 | |
Benjamin Tissoires | 4dfcced | 2011-01-31 11:28:22 +0100 | [diff] [blame] | 748 | /* IRTOUCH panels */ |
| 749 | { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID, |
| 750 | HID_USB_DEVICE(USB_VENDOR_ID_IRTOUCHSYSTEMS, |
| 751 | USB_DEVICE_ID_IRTOUCH_INFRARED_USB) }, |
| 752 | |
Jeff Brown | c50bb1a | 2011-08-15 21:12:09 -0700 | [diff] [blame] | 753 | /* LG Display panels */ |
| 754 | { .driver_data = MT_CLS_DEFAULT, |
| 755 | HID_USB_DEVICE(USB_VENDOR_ID_LG, |
| 756 | USB_DEVICE_ID_LG_MULTITOUCH) }, |
| 757 | |
Benjamin Tissoires | df167c4 | 2011-05-18 15:27:24 +0200 | [diff] [blame] | 758 | /* Lumio panels */ |
| 759 | { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE, |
| 760 | HID_USB_DEVICE(USB_VENDOR_ID_LUMIO, |
| 761 | USB_DEVICE_ID_CRYSTALTOUCH) }, |
Benjamin Tissoires | c3ead6d | 2011-06-21 15:01:55 +0200 | [diff] [blame] | 762 | { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE, |
| 763 | HID_USB_DEVICE(USB_VENDOR_ID_LUMIO, |
| 764 | USB_DEVICE_ID_CRYSTALTOUCH_DUAL) }, |
Benjamin Tissoires | df167c4 | 2011-05-18 15:27:24 +0200 | [diff] [blame] | 765 | |
Benjamin Tissoires | 4a6ee68 | 2011-04-22 11:51:48 +0200 | [diff] [blame] | 766 | /* MosArt panels */ |
| 767 | { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE, |
| 768 | HID_USB_DEVICE(USB_VENDOR_ID_ASUS, |
| 769 | USB_DEVICE_ID_ASUS_T91MT)}, |
| 770 | { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE, |
| 771 | HID_USB_DEVICE(USB_VENDOR_ID_ASUS, |
| 772 | USB_DEVICE_ID_ASUSTEK_MULTITOUCH_YFO) }, |
| 773 | { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE, |
| 774 | HID_USB_DEVICE(USB_VENDOR_ID_TURBOX, |
| 775 | USB_DEVICE_ID_TURBOX_TOUCHSCREEN_MOSART) }, |
| 776 | |
John Sung | 6ab3a9a | 2011-04-21 16:21:52 +0200 | [diff] [blame] | 777 | /* PenMount panels */ |
| 778 | { .driver_data = MT_CLS_CONFIDENCE, |
| 779 | HID_USB_DEVICE(USB_VENDOR_ID_PENMOUNT, |
| 780 | USB_DEVICE_ID_PENMOUNT_PCI) }, |
| 781 | |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 782 | /* PixCir-based panels */ |
Benjamin Tissoires | 1e9cf35 | 2011-01-31 11:28:20 +0100 | [diff] [blame] | 783 | { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID, |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 784 | HID_USB_DEVICE(USB_VENDOR_ID_HANVON, |
| 785 | USB_DEVICE_ID_HANVON_MULTITOUCH) }, |
Benjamin Tissoires | 1e9cf35 | 2011-01-31 11:28:20 +0100 | [diff] [blame] | 786 | { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID, |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 787 | HID_USB_DEVICE(USB_VENDOR_ID_CANDO, |
| 788 | USB_DEVICE_ID_CANDO_PIXCIR_MULTI_TOUCH) }, |
| 789 | |
Benjamin Tissoires | 5e7ea11 | 2011-11-29 13:13:10 +0100 | [diff] [blame^] | 790 | /* Quanta-based panels */ |
| 791 | { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID, |
| 792 | HID_USB_DEVICE(USB_VENDOR_ID_QUANTA, |
| 793 | USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH) }, |
| 794 | { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID, |
| 795 | HID_USB_DEVICE(USB_VENDOR_ID_QUANTA, |
| 796 | USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3001) }, |
| 797 | { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID, |
| 798 | HID_USB_DEVICE(USB_VENDOR_ID_QUANTA, |
| 799 | USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3008) }, |
| 800 | |
Benjamin Tissoires | 043b403 | 2011-03-18 14:27:53 +0100 | [diff] [blame] | 801 | /* Stantum panels */ |
Benjamin Tissoires | bf5af9b | 2011-05-19 14:18:18 +0200 | [diff] [blame] | 802 | { .driver_data = MT_CLS_CONFIDENCE, |
Benjamin Tissoires | 043b403 | 2011-03-18 14:27:53 +0100 | [diff] [blame] | 803 | HID_USB_DEVICE(USB_VENDOR_ID_STANTUM, |
| 804 | USB_DEVICE_ID_MTP)}, |
Benjamin Tissoires | bf5af9b | 2011-05-19 14:18:18 +0200 | [diff] [blame] | 805 | { .driver_data = MT_CLS_CONFIDENCE, |
Benjamin Tissoires | 85a6008 | 2011-06-21 15:01:54 +0200 | [diff] [blame] | 806 | HID_USB_DEVICE(USB_VENDOR_ID_STANTUM_STM, |
Benjamin Tissoires | 043b403 | 2011-03-18 14:27:53 +0100 | [diff] [blame] | 807 | USB_DEVICE_ID_MTP_STM)}, |
Benjamin Tissoires | bf5af9b | 2011-05-19 14:18:18 +0200 | [diff] [blame] | 808 | { .driver_data = MT_CLS_CONFIDENCE, |
Benjamin Tissoires | 85a6008 | 2011-06-21 15:01:54 +0200 | [diff] [blame] | 809 | HID_USB_DEVICE(USB_VENDOR_ID_STANTUM_SITRONIX, |
Benjamin Tissoires | 043b403 | 2011-03-18 14:27:53 +0100 | [diff] [blame] | 810 | USB_DEVICE_ID_MTP_SITRONIX)}, |
| 811 | |
Benjamin Tissoires | 5e74e56 | 2011-05-19 14:18:16 +0200 | [diff] [blame] | 812 | /* Touch International panels */ |
| 813 | { .driver_data = MT_CLS_DEFAULT, |
| 814 | HID_USB_DEVICE(USB_VENDOR_ID_TOUCH_INTL, |
| 815 | USB_DEVICE_ID_TOUCH_INTL_MULTI_TOUCH) }, |
| 816 | |
Benjamin Tissoires | 617b64f | 2011-05-19 14:18:17 +0200 | [diff] [blame] | 817 | /* Unitec panels */ |
| 818 | { .driver_data = MT_CLS_DEFAULT, |
| 819 | HID_USB_DEVICE(USB_VENDOR_ID_UNITEC, |
| 820 | USB_DEVICE_ID_UNITEC_USB_TOUCH_0709) }, |
| 821 | { .driver_data = MT_CLS_DEFAULT, |
| 822 | HID_USB_DEVICE(USB_VENDOR_ID_UNITEC, |
| 823 | USB_DEVICE_ID_UNITEC_USB_TOUCH_0A19) }, |
ice chien | bc8a2a9 | 2011-07-15 16:58:06 +0800 | [diff] [blame] | 824 | /* XAT */ |
| 825 | { .driver_data = MT_CLS_DEFAULT, |
| 826 | HID_USB_DEVICE(USB_VENDOR_ID_XAT, |
| 827 | USB_DEVICE_ID_XAT_CSR) }, |
Benjamin Tissoires | 617b64f | 2011-05-19 14:18:17 +0200 | [diff] [blame] | 828 | |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 829 | { } |
| 830 | }; |
| 831 | MODULE_DEVICE_TABLE(hid, mt_devices); |
| 832 | |
| 833 | static const struct hid_usage_id mt_grabbed_usages[] = { |
| 834 | { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID }, |
| 835 | { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1} |
| 836 | }; |
| 837 | |
| 838 | static struct hid_driver mt_driver = { |
| 839 | .name = "hid-multitouch", |
| 840 | .id_table = mt_devices, |
| 841 | .probe = mt_probe, |
| 842 | .remove = mt_remove, |
| 843 | .input_mapping = mt_input_mapping, |
| 844 | .input_mapped = mt_input_mapped, |
| 845 | .feature_mapping = mt_feature_mapping, |
| 846 | .usage_table = mt_grabbed_usages, |
| 847 | .event = mt_event, |
| 848 | #ifdef CONFIG_PM |
| 849 | .reset_resume = mt_reset_resume, |
| 850 | #endif |
| 851 | }; |
| 852 | |
| 853 | static int __init mt_init(void) |
| 854 | { |
| 855 | return hid_register_driver(&mt_driver); |
| 856 | } |
| 857 | |
| 858 | static void __exit mt_exit(void) |
| 859 | { |
| 860 | hid_unregister_driver(&mt_driver); |
| 861 | } |
| 862 | |
| 863 | module_init(mt_init); |
| 864 | module_exit(mt_exit); |