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 | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | /* |
| 17 | * This program is free software; you can redistribute it and/or modify it |
| 18 | * under the terms of the GNU General Public License as published by the Free |
| 19 | * Software Foundation; either version 2 of the License, or (at your option) |
| 20 | * any later version. |
| 21 | */ |
| 22 | |
| 23 | #include <linux/device.h> |
| 24 | #include <linux/hid.h> |
| 25 | #include <linux/module.h> |
| 26 | #include <linux/slab.h> |
| 27 | #include <linux/usb.h> |
| 28 | #include <linux/input/mt.h> |
| 29 | #include "usbhid/usbhid.h" |
| 30 | |
| 31 | |
| 32 | MODULE_AUTHOR("Stephane Chatty <chatty@enac.fr>"); |
Benjamin Tissoires | ef2fafb | 2011-01-31 11:28:21 +0100 | [diff] [blame] | 33 | MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>"); |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 34 | MODULE_DESCRIPTION("HID multitouch panels"); |
| 35 | MODULE_LICENSE("GPL"); |
| 36 | |
| 37 | #include "hid-ids.h" |
| 38 | |
| 39 | /* quirks to control the device */ |
| 40 | #define MT_QUIRK_NOT_SEEN_MEANS_UP (1 << 0) |
| 41 | #define MT_QUIRK_SLOT_IS_CONTACTID (1 << 1) |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 42 | #define MT_QUIRK_CYPRESS (1 << 2) |
Benjamin Tissoires | 5572da0 | 2011-01-07 23:47:27 +0100 | [diff] [blame] | 43 | #define MT_QUIRK_SLOT_IS_CONTACTNUMBER (1 << 3) |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 44 | #define MT_QUIRK_VALID_IS_INRANGE (1 << 4) |
| 45 | #define MT_QUIRK_VALID_IS_CONFIDENCE (1 << 5) |
Richard Nauber | 4875ac1 | 2011-03-09 06:20:57 +0100 | [diff] [blame] | 46 | #define MT_QUIRK_EGALAX_XYZ_FIXUP (1 << 6) |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 47 | |
| 48 | struct mt_slot { |
| 49 | __s32 x, y, p, w, h; |
| 50 | __s32 contactid; /* the device ContactID assigned to this slot */ |
| 51 | bool touch_state; /* is the touch valid? */ |
| 52 | bool seen_in_this_frame;/* has this slot been updated */ |
| 53 | }; |
| 54 | |
| 55 | struct mt_device { |
| 56 | struct mt_slot curdata; /* placeholder of incoming data */ |
| 57 | struct mt_class *mtclass; /* our mt device class */ |
| 58 | unsigned last_field_index; /* last field index of the report */ |
| 59 | unsigned last_slot_field; /* the last field of a slot */ |
| 60 | __s8 inputmode; /* InputMode HID feature, -1 if non-existent */ |
| 61 | __u8 num_received; /* how many contacts we received */ |
| 62 | __u8 num_expected; /* expected last contact index */ |
Benjamin Tissoires | 9498f95 | 2011-03-18 14:27:52 +0100 | [diff] [blame^] | 63 | __u8 maxcontacts; |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 64 | bool curvalid; /* is the current contact valid? */ |
Benjamin Tissoires | 9498f95 | 2011-03-18 14:27:52 +0100 | [diff] [blame^] | 65 | struct mt_slot *slots; |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | struct mt_class { |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 69 | __s32 name; /* MT_CLS */ |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 70 | __s32 quirks; |
| 71 | __s32 sn_move; /* Signal/noise ratio for move events */ |
| 72 | __s32 sn_pressure; /* Signal/noise ratio for pressure events */ |
| 73 | __u8 maxcontacts; |
| 74 | }; |
| 75 | |
| 76 | /* classes of device behavior */ |
Benjamin Tissoires | 1e9cf35 | 2011-01-31 11:28:20 +0100 | [diff] [blame] | 77 | #define MT_CLS_DEFAULT 1 |
| 78 | #define MT_CLS_DUAL_INRANGE_CONTACTID 2 |
| 79 | #define MT_CLS_DUAL_INRANGE_CONTACTNUMBER 3 |
| 80 | #define MT_CLS_CYPRESS 4 |
Richard Nauber | 4875ac1 | 2011-03-09 06:20:57 +0100 | [diff] [blame] | 81 | #define MT_CLS_EGALAX 5 |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 82 | |
Benjamin Tissoires | 9498f95 | 2011-03-18 14:27:52 +0100 | [diff] [blame^] | 83 | #define MT_DEFAULT_MAXCONTACT 10 |
| 84 | |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 85 | /* |
| 86 | * these device-dependent functions determine what slot corresponds |
| 87 | * to a valid contact that was just read. |
| 88 | */ |
| 89 | |
Benjamin Tissoires | a3b5e57 | 2011-01-07 23:46:30 +0100 | [diff] [blame] | 90 | static int cypress_compute_slot(struct mt_device *td) |
| 91 | { |
| 92 | if (td->curdata.contactid != 0 || td->num_received == 0) |
| 93 | return td->curdata.contactid; |
| 94 | else |
| 95 | return -1; |
| 96 | } |
| 97 | |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 98 | static int find_slot_from_contactid(struct mt_device *td) |
| 99 | { |
| 100 | int i; |
Benjamin Tissoires | 9498f95 | 2011-03-18 14:27:52 +0100 | [diff] [blame^] | 101 | for (i = 0; i < td->maxcontacts; ++i) { |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 102 | if (td->slots[i].contactid == td->curdata.contactid && |
| 103 | td->slots[i].touch_state) |
| 104 | return i; |
| 105 | } |
Benjamin Tissoires | 9498f95 | 2011-03-18 14:27:52 +0100 | [diff] [blame^] | 106 | for (i = 0; i < td->maxcontacts; ++i) { |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 107 | if (!td->slots[i].seen_in_this_frame && |
| 108 | !td->slots[i].touch_state) |
| 109 | return i; |
| 110 | } |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 111 | /* should not occurs. If this happens that means |
| 112 | * that the device sent more touches that it says |
| 113 | * in the report descriptor. It is ignored then. */ |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 114 | return -1; |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | struct mt_class mt_classes[] = { |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 118 | { .name = MT_CLS_DEFAULT, |
Benjamin Tissoires | 9498f95 | 2011-03-18 14:27:52 +0100 | [diff] [blame^] | 119 | .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP }, |
Benjamin Tissoires | 1e9cf35 | 2011-01-31 11:28:20 +0100 | [diff] [blame] | 120 | { .name = MT_CLS_DUAL_INRANGE_CONTACTID, |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 121 | .quirks = MT_QUIRK_VALID_IS_INRANGE | |
| 122 | MT_QUIRK_SLOT_IS_CONTACTID, |
| 123 | .maxcontacts = 2 }, |
Benjamin Tissoires | 1e9cf35 | 2011-01-31 11:28:20 +0100 | [diff] [blame] | 124 | { .name = MT_CLS_DUAL_INRANGE_CONTACTNUMBER, |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 125 | .quirks = MT_QUIRK_VALID_IS_INRANGE | |
| 126 | MT_QUIRK_SLOT_IS_CONTACTNUMBER, |
| 127 | .maxcontacts = 2 }, |
| 128 | { .name = MT_CLS_CYPRESS, |
| 129 | .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP | |
| 130 | MT_QUIRK_CYPRESS, |
| 131 | .maxcontacts = 10 }, |
| 132 | |
Richard Nauber | 4875ac1 | 2011-03-09 06:20:57 +0100 | [diff] [blame] | 133 | { .name = MT_CLS_EGALAX, |
| 134 | .quirks = MT_QUIRK_SLOT_IS_CONTACTID | |
| 135 | MT_QUIRK_VALID_IS_INRANGE | |
| 136 | MT_QUIRK_EGALAX_XYZ_FIXUP, |
| 137 | .maxcontacts = 2, |
| 138 | .sn_move = 4096, |
| 139 | .sn_pressure = 32, |
| 140 | }, |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 141 | { } |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 142 | }; |
| 143 | |
Henrik Rydberg | f635bd1 | 2011-02-24 19:30:59 +0100 | [diff] [blame] | 144 | static void mt_feature_mapping(struct hid_device *hdev, |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 145 | struct hid_field *field, struct hid_usage *usage) |
| 146 | { |
Benjamin Tissoires | 9498f95 | 2011-03-18 14:27:52 +0100 | [diff] [blame^] | 147 | struct mt_device *td = hid_get_drvdata(hdev); |
| 148 | |
| 149 | switch (usage->hid) { |
| 150 | case HID_DG_INPUTMODE: |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 151 | td->inputmode = field->report->id; |
Benjamin Tissoires | 9498f95 | 2011-03-18 14:27:52 +0100 | [diff] [blame^] | 152 | break; |
| 153 | case HID_DG_CONTACTMAX: |
| 154 | td->maxcontacts = field->value[0]; |
| 155 | if (td->mtclass->maxcontacts) |
| 156 | /* check if the maxcontacts is given by the class */ |
| 157 | td->maxcontacts = td->mtclass->maxcontacts; |
| 158 | |
| 159 | break; |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 160 | } |
| 161 | } |
| 162 | |
| 163 | static void set_abs(struct input_dev *input, unsigned int code, |
| 164 | struct hid_field *field, int snratio) |
| 165 | { |
| 166 | int fmin = field->logical_minimum; |
| 167 | int fmax = field->logical_maximum; |
| 168 | int fuzz = snratio ? (fmax - fmin) / snratio : 0; |
| 169 | input_set_abs_params(input, code, fmin, fmax, fuzz, 0); |
| 170 | } |
| 171 | |
| 172 | static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi, |
| 173 | struct hid_field *field, struct hid_usage *usage, |
| 174 | unsigned long **bit, int *max) |
| 175 | { |
| 176 | struct mt_device *td = hid_get_drvdata(hdev); |
| 177 | struct mt_class *cls = td->mtclass; |
Richard Nauber | 4875ac1 | 2011-03-09 06:20:57 +0100 | [diff] [blame] | 178 | __s32 quirks = cls->quirks; |
| 179 | |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 180 | switch (usage->hid & HID_USAGE_PAGE) { |
| 181 | |
| 182 | case HID_UP_GENDESK: |
| 183 | switch (usage->hid) { |
| 184 | case HID_GD_X: |
Richard Nauber | 4875ac1 | 2011-03-09 06:20:57 +0100 | [diff] [blame] | 185 | if (quirks & MT_QUIRK_EGALAX_XYZ_FIXUP) |
| 186 | field->logical_maximum = 32760; |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 187 | hid_map_usage(hi, usage, bit, max, |
| 188 | EV_ABS, ABS_MT_POSITION_X); |
| 189 | set_abs(hi->input, ABS_MT_POSITION_X, field, |
| 190 | cls->sn_move); |
| 191 | /* touchscreen emulation */ |
| 192 | set_abs(hi->input, ABS_X, field, cls->sn_move); |
| 193 | td->last_slot_field = usage->hid; |
| 194 | return 1; |
| 195 | case HID_GD_Y: |
Richard Nauber | 4875ac1 | 2011-03-09 06:20:57 +0100 | [diff] [blame] | 196 | if (quirks & MT_QUIRK_EGALAX_XYZ_FIXUP) |
| 197 | field->logical_maximum = 32760; |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 198 | hid_map_usage(hi, usage, bit, max, |
| 199 | EV_ABS, ABS_MT_POSITION_Y); |
| 200 | set_abs(hi->input, ABS_MT_POSITION_Y, field, |
| 201 | cls->sn_move); |
| 202 | /* touchscreen emulation */ |
| 203 | set_abs(hi->input, ABS_Y, field, cls->sn_move); |
| 204 | td->last_slot_field = usage->hid; |
| 205 | return 1; |
| 206 | } |
| 207 | return 0; |
| 208 | |
| 209 | case HID_UP_DIGITIZER: |
| 210 | switch (usage->hid) { |
| 211 | case HID_DG_INRANGE: |
| 212 | td->last_slot_field = usage->hid; |
| 213 | return 1; |
| 214 | case HID_DG_CONFIDENCE: |
| 215 | td->last_slot_field = usage->hid; |
| 216 | return 1; |
| 217 | case HID_DG_TIPSWITCH: |
| 218 | hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_TOUCH); |
| 219 | input_set_capability(hi->input, EV_KEY, BTN_TOUCH); |
| 220 | td->last_slot_field = usage->hid; |
| 221 | return 1; |
| 222 | case HID_DG_CONTACTID: |
Benjamin Tissoires | 9498f95 | 2011-03-18 14:27:52 +0100 | [diff] [blame^] | 223 | input_mt_init_slots(hi->input, td->maxcontacts); |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 224 | td->last_slot_field = usage->hid; |
| 225 | return 1; |
| 226 | case HID_DG_WIDTH: |
| 227 | hid_map_usage(hi, usage, bit, max, |
| 228 | EV_ABS, ABS_MT_TOUCH_MAJOR); |
| 229 | td->last_slot_field = usage->hid; |
| 230 | return 1; |
| 231 | case HID_DG_HEIGHT: |
| 232 | hid_map_usage(hi, usage, bit, max, |
| 233 | EV_ABS, ABS_MT_TOUCH_MINOR); |
| 234 | field->logical_maximum = 1; |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 235 | field->logical_minimum = 0; |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 236 | set_abs(hi->input, ABS_MT_ORIENTATION, field, 0); |
| 237 | td->last_slot_field = usage->hid; |
| 238 | return 1; |
| 239 | case HID_DG_TIPPRESSURE: |
Richard Nauber | 4875ac1 | 2011-03-09 06:20:57 +0100 | [diff] [blame] | 240 | if (quirks & MT_QUIRK_EGALAX_XYZ_FIXUP) |
| 241 | field->logical_minimum = 0; |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 242 | hid_map_usage(hi, usage, bit, max, |
| 243 | EV_ABS, ABS_MT_PRESSURE); |
| 244 | set_abs(hi->input, ABS_MT_PRESSURE, field, |
| 245 | cls->sn_pressure); |
| 246 | /* touchscreen emulation */ |
| 247 | set_abs(hi->input, ABS_PRESSURE, field, |
| 248 | cls->sn_pressure); |
| 249 | td->last_slot_field = usage->hid; |
| 250 | return 1; |
| 251 | case HID_DG_CONTACTCOUNT: |
| 252 | td->last_field_index = field->report->maxfield - 1; |
| 253 | return 1; |
| 254 | case HID_DG_CONTACTMAX: |
| 255 | /* we don't set td->last_slot_field as contactcount and |
| 256 | * contact max are global to the report */ |
| 257 | return -1; |
| 258 | } |
| 259 | /* let hid-input decide for the others */ |
| 260 | return 0; |
| 261 | |
| 262 | case 0xff000000: |
| 263 | /* we do not want to map these: no input-oriented meaning */ |
| 264 | return -1; |
| 265 | } |
| 266 | |
| 267 | return 0; |
| 268 | } |
| 269 | |
| 270 | static int mt_input_mapped(struct hid_device *hdev, struct hid_input *hi, |
| 271 | struct hid_field *field, struct hid_usage *usage, |
| 272 | unsigned long **bit, int *max) |
| 273 | { |
| 274 | if (usage->type == EV_KEY || usage->type == EV_ABS) |
| 275 | set_bit(usage->type, hi->input->evbit); |
| 276 | |
| 277 | return -1; |
| 278 | } |
| 279 | |
| 280 | static int mt_compute_slot(struct mt_device *td) |
| 281 | { |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 282 | __s32 quirks = td->mtclass->quirks; |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 283 | |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 284 | if (quirks & MT_QUIRK_SLOT_IS_CONTACTID) |
| 285 | return td->curdata.contactid; |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 286 | |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 287 | if (quirks & MT_QUIRK_CYPRESS) |
Benjamin Tissoires | a3b5e57 | 2011-01-07 23:46:30 +0100 | [diff] [blame] | 288 | return cypress_compute_slot(td); |
| 289 | |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 290 | if (quirks & MT_QUIRK_SLOT_IS_CONTACTNUMBER) |
| 291 | return td->num_received; |
Benjamin Tissoires | 5572da0 | 2011-01-07 23:47:27 +0100 | [diff] [blame] | 292 | |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 293 | return find_slot_from_contactid(td); |
| 294 | } |
| 295 | |
| 296 | /* |
| 297 | * this function is called when a whole contact has been processed, |
| 298 | * so that it can assign it to a slot and store the data there |
| 299 | */ |
| 300 | static void mt_complete_slot(struct mt_device *td) |
| 301 | { |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 302 | td->curdata.seen_in_this_frame = true; |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 303 | if (td->curvalid) { |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 304 | int slotnum = mt_compute_slot(td); |
| 305 | |
Benjamin Tissoires | 9498f95 | 2011-03-18 14:27:52 +0100 | [diff] [blame^] | 306 | if (slotnum >= 0 && slotnum < td->maxcontacts) |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 307 | td->slots[slotnum] = td->curdata; |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 308 | } |
| 309 | td->num_received++; |
| 310 | } |
| 311 | |
| 312 | |
| 313 | /* |
| 314 | * this function is called when a whole packet has been received and processed, |
| 315 | * so that it can decide what to send to the input layer. |
| 316 | */ |
| 317 | static void mt_emit_event(struct mt_device *td, struct input_dev *input) |
| 318 | { |
| 319 | int i; |
| 320 | |
Benjamin Tissoires | 9498f95 | 2011-03-18 14:27:52 +0100 | [diff] [blame^] | 321 | for (i = 0; i < td->maxcontacts; ++i) { |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 322 | struct mt_slot *s = &(td->slots[i]); |
| 323 | if ((td->mtclass->quirks & MT_QUIRK_NOT_SEEN_MEANS_UP) && |
| 324 | !s->seen_in_this_frame) { |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 325 | s->touch_state = false; |
| 326 | } |
| 327 | |
| 328 | input_mt_slot(input, i); |
| 329 | input_mt_report_slot_state(input, MT_TOOL_FINGER, |
| 330 | s->touch_state); |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 331 | if (s->touch_state) { |
| 332 | input_event(input, EV_ABS, ABS_MT_POSITION_X, s->x); |
| 333 | input_event(input, EV_ABS, ABS_MT_POSITION_Y, s->y); |
| 334 | input_event(input, EV_ABS, ABS_MT_PRESSURE, s->p); |
| 335 | input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, s->w); |
| 336 | input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, s->h); |
| 337 | } |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 338 | s->seen_in_this_frame = false; |
| 339 | |
| 340 | } |
| 341 | |
| 342 | input_mt_report_pointer_emulation(input, true); |
| 343 | input_sync(input); |
| 344 | td->num_received = 0; |
| 345 | } |
| 346 | |
| 347 | |
| 348 | |
| 349 | static int mt_event(struct hid_device *hid, struct hid_field *field, |
| 350 | struct hid_usage *usage, __s32 value) |
| 351 | { |
| 352 | struct mt_device *td = hid_get_drvdata(hid); |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 353 | __s32 quirks = td->mtclass->quirks; |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 354 | |
Benjamin Tissoires | 9498f95 | 2011-03-18 14:27:52 +0100 | [diff] [blame^] | 355 | if (hid->claimed & HID_CLAIMED_INPUT && td->slots) { |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 356 | switch (usage->hid) { |
| 357 | case HID_DG_INRANGE: |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 358 | if (quirks & MT_QUIRK_VALID_IS_INRANGE) |
| 359 | td->curvalid = value; |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 360 | break; |
| 361 | case HID_DG_TIPSWITCH: |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 362 | if (quirks & MT_QUIRK_NOT_SEEN_MEANS_UP) |
| 363 | td->curvalid = value; |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 364 | td->curdata.touch_state = value; |
| 365 | break; |
| 366 | case HID_DG_CONFIDENCE: |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 367 | if (quirks & MT_QUIRK_VALID_IS_CONFIDENCE) |
| 368 | td->curvalid = value; |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 369 | break; |
| 370 | case HID_DG_CONTACTID: |
| 371 | td->curdata.contactid = value; |
| 372 | break; |
| 373 | case HID_DG_TIPPRESSURE: |
| 374 | td->curdata.p = value; |
| 375 | break; |
| 376 | case HID_GD_X: |
| 377 | td->curdata.x = value; |
| 378 | break; |
| 379 | case HID_GD_Y: |
| 380 | td->curdata.y = value; |
| 381 | break; |
| 382 | case HID_DG_WIDTH: |
| 383 | td->curdata.w = value; |
| 384 | break; |
| 385 | case HID_DG_HEIGHT: |
| 386 | td->curdata.h = value; |
| 387 | break; |
| 388 | case HID_DG_CONTACTCOUNT: |
| 389 | /* |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 390 | * Includes multi-packet support where subsequent |
| 391 | * packets are sent with zero contactcount. |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 392 | */ |
| 393 | if (value) |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 394 | td->num_expected = value; |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 395 | break; |
| 396 | |
| 397 | default: |
| 398 | /* fallback to the generic hidinput handling */ |
| 399 | return 0; |
| 400 | } |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 401 | |
Henrik Rydberg | f153fc3 | 2011-03-09 06:35:25 +0100 | [diff] [blame] | 402 | if (usage->hid == td->last_slot_field) { |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 403 | mt_complete_slot(td); |
Henrik Rydberg | f153fc3 | 2011-03-09 06:35:25 +0100 | [diff] [blame] | 404 | if (!td->last_field_index) |
| 405 | mt_emit_event(td, field->hidinput->input); |
| 406 | } |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 407 | |
| 408 | if (field->index == td->last_field_index |
| 409 | && td->num_received >= td->num_expected) |
| 410 | mt_emit_event(td, field->hidinput->input); |
| 411 | |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 412 | } |
| 413 | |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 414 | /* we have handled the hidinput part, now remains hiddev */ |
| 415 | if (hid->claimed & HID_CLAIMED_HIDDEV && hid->hiddev_hid_event) |
| 416 | hid->hiddev_hid_event(hid, field, usage, value); |
| 417 | |
| 418 | return 1; |
| 419 | } |
| 420 | |
| 421 | static void mt_set_input_mode(struct hid_device *hdev) |
| 422 | { |
| 423 | struct mt_device *td = hid_get_drvdata(hdev); |
| 424 | struct hid_report *r; |
| 425 | struct hid_report_enum *re; |
| 426 | |
| 427 | if (td->inputmode < 0) |
| 428 | return; |
| 429 | |
| 430 | re = &(hdev->report_enum[HID_FEATURE_REPORT]); |
| 431 | r = re->report_id_hash[td->inputmode]; |
| 432 | if (r) { |
| 433 | r->field[0]->value[0] = 0x02; |
| 434 | usbhid_submit_report(hdev, r, USB_DIR_OUT); |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) |
| 439 | { |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 440 | int ret, i; |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 441 | struct mt_device *td; |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 442 | struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */ |
| 443 | |
| 444 | for (i = 0; mt_classes[i].name ; i++) { |
| 445 | if (id->driver_data == mt_classes[i].name) { |
| 446 | mtclass = &(mt_classes[i]); |
| 447 | break; |
| 448 | } |
| 449 | } |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 450 | |
| 451 | /* This allows the driver to correctly support devices |
| 452 | * that emit events over several HID messages. |
| 453 | */ |
| 454 | hdev->quirks |= HID_QUIRK_NO_INPUT_SYNC; |
| 455 | |
Benjamin Tissoires | 9498f95 | 2011-03-18 14:27:52 +0100 | [diff] [blame^] | 456 | td = kzalloc(sizeof(struct mt_device), GFP_KERNEL); |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 457 | if (!td) { |
| 458 | dev_err(&hdev->dev, "cannot allocate multitouch data\n"); |
| 459 | return -ENOMEM; |
| 460 | } |
| 461 | td->mtclass = mtclass; |
| 462 | td->inputmode = -1; |
| 463 | hid_set_drvdata(hdev, td); |
| 464 | |
| 465 | ret = hid_parse(hdev); |
| 466 | if (ret != 0) |
| 467 | goto fail; |
| 468 | |
| 469 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); |
Benjamin Tissoires | 2d93666 | 2011-01-11 16:45:54 +0100 | [diff] [blame] | 470 | if (ret) |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 471 | goto fail; |
| 472 | |
Benjamin Tissoires | 9498f95 | 2011-03-18 14:27:52 +0100 | [diff] [blame^] | 473 | if (!td->maxcontacts) |
| 474 | td->maxcontacts = MT_DEFAULT_MAXCONTACT; |
| 475 | |
| 476 | td->slots = kzalloc(td->maxcontacts * sizeof(struct mt_slot), |
| 477 | GFP_KERNEL); |
| 478 | if (!td->slots) { |
| 479 | dev_err(&hdev->dev, "cannot allocate multitouch slots\n"); |
| 480 | hid_hw_stop(hdev); |
| 481 | ret = -ENOMEM; |
| 482 | goto fail; |
| 483 | } |
| 484 | |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 485 | mt_set_input_mode(hdev); |
| 486 | |
| 487 | return 0; |
| 488 | |
| 489 | fail: |
| 490 | kfree(td); |
| 491 | return ret; |
| 492 | } |
| 493 | |
| 494 | #ifdef CONFIG_PM |
| 495 | static int mt_reset_resume(struct hid_device *hdev) |
| 496 | { |
| 497 | mt_set_input_mode(hdev); |
| 498 | return 0; |
| 499 | } |
| 500 | #endif |
| 501 | |
| 502 | static void mt_remove(struct hid_device *hdev) |
| 503 | { |
| 504 | struct mt_device *td = hid_get_drvdata(hdev); |
| 505 | hid_hw_stop(hdev); |
Benjamin Tissoires | 9498f95 | 2011-03-18 14:27:52 +0100 | [diff] [blame^] | 506 | kfree(td->slots); |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 507 | kfree(td); |
| 508 | hid_set_drvdata(hdev, NULL); |
| 509 | } |
| 510 | |
| 511 | static const struct hid_device_id mt_devices[] = { |
| 512 | |
Benjamin Tissoires | a3b5e57 | 2011-01-07 23:46:30 +0100 | [diff] [blame] | 513 | /* Cypress panel */ |
| 514 | { .driver_data = MT_CLS_CYPRESS, |
| 515 | HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, |
| 516 | USB_DEVICE_ID_CYPRESS_TRUETOUCH) }, |
| 517 | |
Benjamin Tissoires | 5572da0 | 2011-01-07 23:47:27 +0100 | [diff] [blame] | 518 | /* GeneralTouch panel */ |
Benjamin Tissoires | 1e9cf35 | 2011-01-31 11:28:20 +0100 | [diff] [blame] | 519 | { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER, |
Benjamin Tissoires | 5572da0 | 2011-01-07 23:47:27 +0100 | [diff] [blame] | 520 | HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, |
| 521 | USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS) }, |
| 522 | |
Benjamin Tissoires | 4dfcced | 2011-01-31 11:28:22 +0100 | [diff] [blame] | 523 | /* IRTOUCH panels */ |
| 524 | { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID, |
| 525 | HID_USB_DEVICE(USB_VENDOR_ID_IRTOUCHSYSTEMS, |
| 526 | USB_DEVICE_ID_IRTOUCH_INFRARED_USB) }, |
| 527 | |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 528 | /* PixCir-based panels */ |
Benjamin Tissoires | 1e9cf35 | 2011-01-31 11:28:20 +0100 | [diff] [blame] | 529 | { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID, |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 530 | HID_USB_DEVICE(USB_VENDOR_ID_HANVON, |
| 531 | USB_DEVICE_ID_HANVON_MULTITOUCH) }, |
Benjamin Tissoires | 1e9cf35 | 2011-01-31 11:28:20 +0100 | [diff] [blame] | 532 | { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID, |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 533 | HID_USB_DEVICE(USB_VENDOR_ID_CANDO, |
| 534 | USB_DEVICE_ID_CANDO_PIXCIR_MULTI_TOUCH) }, |
| 535 | |
Richard Nauber | 4875ac1 | 2011-03-09 06:20:57 +0100 | [diff] [blame] | 536 | /* Resistive eGalax devices */ |
| 537 | { .driver_data = MT_CLS_EGALAX, |
| 538 | HID_USB_DEVICE(USB_VENDOR_ID_DWAV, |
| 539 | USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH) }, |
| 540 | { .driver_data = MT_CLS_EGALAX, |
| 541 | HID_USB_DEVICE(USB_VENDOR_ID_DWAV, |
| 542 | USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH3) }, |
| 543 | |
| 544 | /* Capacitive eGalax devices */ |
| 545 | { .driver_data = MT_CLS_EGALAX, |
| 546 | HID_USB_DEVICE(USB_VENDOR_ID_DWAV, |
| 547 | USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH1) }, |
| 548 | { .driver_data = MT_CLS_EGALAX, |
| 549 | HID_USB_DEVICE(USB_VENDOR_ID_DWAV, |
| 550 | USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH2) }, |
| 551 | { .driver_data = MT_CLS_EGALAX, |
| 552 | HID_USB_DEVICE(USB_VENDOR_ID_DWAV, |
| 553 | USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH4) }, |
| 554 | |
Benjamin Tissoires | 5519cab | 2011-01-07 23:45:50 +0100 | [diff] [blame] | 555 | { } |
| 556 | }; |
| 557 | MODULE_DEVICE_TABLE(hid, mt_devices); |
| 558 | |
| 559 | static const struct hid_usage_id mt_grabbed_usages[] = { |
| 560 | { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID }, |
| 561 | { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1} |
| 562 | }; |
| 563 | |
| 564 | static struct hid_driver mt_driver = { |
| 565 | .name = "hid-multitouch", |
| 566 | .id_table = mt_devices, |
| 567 | .probe = mt_probe, |
| 568 | .remove = mt_remove, |
| 569 | .input_mapping = mt_input_mapping, |
| 570 | .input_mapped = mt_input_mapped, |
| 571 | .feature_mapping = mt_feature_mapping, |
| 572 | .usage_table = mt_grabbed_usages, |
| 573 | .event = mt_event, |
| 574 | #ifdef CONFIG_PM |
| 575 | .reset_resume = mt_reset_resume, |
| 576 | #endif |
| 577 | }; |
| 578 | |
| 579 | static int __init mt_init(void) |
| 580 | { |
| 581 | return hid_register_driver(&mt_driver); |
| 582 | } |
| 583 | |
| 584 | static void __exit mt_exit(void) |
| 585 | { |
| 586 | hid_unregister_driver(&mt_driver); |
| 587 | } |
| 588 | |
| 589 | module_init(mt_init); |
| 590 | module_exit(mt_exit); |