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