blob: cd207e99d26afca0bbb541871f842c5b353961cb [file] [log] [blame]
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001/*
2 * HID driver for multitouch panels
3 *
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +01004 * Copyright (c) 2010-2012 Stephane Chatty <chatty@enac.fr>
Benjamin Tissoiresb0a78682013-02-25 11:31:49 +01005 * Copyright (c) 2010-2013 Benjamin Tissoires <benjamin.tissoires@gmail.com>
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +01006 * Copyright (c) 2010-2012 Ecole Nationale de l'Aviation Civile, France
Benjamin Tissoiresb0a78682013-02-25 11:31:49 +01007 * Copyright (c) 2012-2013 Red Hat, Inc
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01008 *
Richard Nauber4875ac12011-03-09 06:20:57 +01009 * This code is partly based on hid-egalax.c:
10 *
11 * Copyright (c) 2010 Stephane Chatty <chatty@enac.fr>
12 * Copyright (c) 2010 Henrik Rydberg <rydberg@euromail.se>
13 * Copyright (c) 2010 Canonical, Ltd.
14 *
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +010015 * This code is partly based on hid-3m-pct.c:
16 *
17 * Copyright (c) 2009-2010 Stephane Chatty <chatty@enac.fr>
18 * Copyright (c) 2010 Henrik Rydberg <rydberg@euromail.se>
19 * Copyright (c) 2010 Canonical, Ltd.
20 *
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010021 */
22
23/*
24 * This program is free software; you can redistribute it and/or modify it
25 * under the terms of the GNU General Public License as published by the Free
26 * Software Foundation; either version 2 of the License, or (at your option)
27 * any later version.
28 */
29
Benjamin Tissoiresb0a78682013-02-25 11:31:49 +010030/*
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +020031 * This driver is regularly tested thanks to the test suite in hid-tools[1].
Benjamin Tissoiresb0a78682013-02-25 11:31:49 +010032 * Please run these regression tests before patching this module so that
33 * your patch won't break existing known devices.
34 *
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +020035 * [1] https://gitlab.freedesktop.org/libevdev/hid-tools
Benjamin Tissoiresb0a78682013-02-25 11:31:49 +010036 */
37
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010038#include <linux/device.h>
39#include <linux/hid.h>
40#include <linux/module.h>
41#include <linux/slab.h>
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010042#include <linux/input/mt.h>
Nicolas Boichat29cc3092017-08-22 09:10:11 +080043#include <linux/jiffies.h>
Benjamin Tissoires49a5a822013-03-22 18:38:33 +010044#include <linux/string.h>
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +020045#include <linux/timer.h>
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010046
47
48MODULE_AUTHOR("Stephane Chatty <chatty@enac.fr>");
Benjamin Tissoiresef2fafb2011-01-31 11:28:21 +010049MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>");
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010050MODULE_DESCRIPTION("HID multitouch panels");
51MODULE_LICENSE("GPL");
52
53#include "hid-ids.h"
54
55/* quirks to control the device */
Benjamin Tissoiresfd911892017-06-15 15:32:03 +020056#define MT_QUIRK_NOT_SEEN_MEANS_UP BIT(0)
57#define MT_QUIRK_SLOT_IS_CONTACTID BIT(1)
58#define MT_QUIRK_CYPRESS BIT(2)
59#define MT_QUIRK_SLOT_IS_CONTACTNUMBER BIT(3)
60#define MT_QUIRK_ALWAYS_VALID BIT(4)
61#define MT_QUIRK_VALID_IS_INRANGE BIT(5)
62#define MT_QUIRK_VALID_IS_CONFIDENCE BIT(6)
63#define MT_QUIRK_CONFIDENCE BIT(7)
64#define MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE BIT(8)
65#define MT_QUIRK_NO_AREA BIT(9)
66#define MT_QUIRK_IGNORE_DUPLICATES BIT(10)
67#define MT_QUIRK_HOVERING BIT(11)
68#define MT_QUIRK_CONTACT_CNT_ACCURATE BIT(12)
69#define MT_QUIRK_FORCE_GET_FEATURE BIT(13)
70#define MT_QUIRK_FIX_CONST_CONTACT_ID BIT(14)
71#define MT_QUIRK_TOUCH_SIZE_SCALING BIT(15)
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +020072#define MT_QUIRK_STICKY_FINGERS BIT(16)
João Paulo Rechi Vita957b8df2017-07-24 14:22:25 -070073#define MT_QUIRK_ASUS_CUSTOM_UP BIT(17)
Benjamin Tissoiresd9c57a72018-03-20 12:04:45 +010074#define MT_QUIRK_WIN8_PTP_BUTTONS BIT(18)
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010075
Andrew Duggan9abebed2014-03-19 13:39:03 -070076#define MT_INPUTMODE_TOUCHSCREEN 0x02
77#define MT_INPUTMODE_TOUCHPAD 0x03
78
Seth Forshee2c6e0272015-03-11 17:26:41 -050079#define MT_BUTTONTYPE_CLICKPAD 0
80
Benjamin Tissoires02946f42018-04-24 10:04:37 +020081enum latency_mode {
82 HID_LATENCY_NORMAL = 0,
83 HID_LATENCY_HIGH = 1,
84};
85
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +020086#define MT_IO_FLAGS_RUNNING 0
Benjamin Tissoires96098272017-06-15 15:32:05 +020087#define MT_IO_FLAGS_ACTIVE_SLOTS 1
88#define MT_IO_FLAGS_PENDING_SLOTS 2
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +020089
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010090struct mt_slot {
Wei-Ning Huang00720272017-10-12 14:21:43 +080091 __s32 x, y, cx, cy, p, w, h, a;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010092 __s32 contactid; /* the device ContactID assigned to this slot */
93 bool touch_state; /* is the touch valid? */
Benjamin Tissoires9b3bb9b82012-11-14 16:59:24 +010094 bool inrange_state; /* is the finger in proximity of the sensor? */
Allen Hung6dd2e272016-06-23 16:31:30 +080095 bool confidence_state; /* is the touch made by a finger? */
Wei-Ning Huang00720272017-10-12 14:21:43 +080096 bool has_azimuth; /* the contact reports azimuth */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010097};
98
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +020099struct mt_application {
100 struct list_head list;
101 unsigned int application;
102 struct mt_slot curdata; /* placeholder of incoming data */
103
104 int cc_index; /* contact count field index in the report */
105 int cc_value_index; /* contact count value index in the field */
106 int scantime_index; /* scantime field index in the report */
107 int scantime_val_index; /* scantime value index in the field */
108 unsigned int last_slot_field; /* the last field of a slot */
109 bool curvalid; /* is the current contact valid? */
110
111 int left_button_state; /* left button state */
112 unsigned int mt_flags; /* flags to pass to input-mt */
113
114 __u8 num_received; /* how many contacts we received */
115 __u8 num_expected; /* expected last contact index */
116 __u8 buttons_count; /* number of physical buttons per touchpad */
117 __u8 touches_by_report; /* how many touches are present in one report:
118 * 1 means we should use a serial protocol
119 * > 1 means hybrid (multitouch) protocol
120 */
121
122 __s32 dev_time; /* the scan time provided by the device */
123 unsigned long jiffies; /* the frame's jiffies */
124 int timestamp; /* the timestamp to be sent */
125 int prev_scantime; /* scantime reported previously */
126
127 bool have_contact_count;
128};
129
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100130struct mt_class {
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100131 __s32 name; /* MT_CLS */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100132 __s32 quirks;
133 __s32 sn_move; /* Signal/noise ratio for move events */
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100134 __s32 sn_width; /* Signal/noise ratio for width events */
135 __s32 sn_height; /* Signal/noise ratio for height events */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100136 __s32 sn_pressure; /* Signal/noise ratio for pressure events */
137 __u8 maxcontacts;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100138 bool is_indirect; /* true for touchpads */
Benjamin Tissoires6aef7042014-02-28 11:41:25 -0500139 bool export_all_inputs; /* do not ignore mouse, keyboards, etc... */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100140};
141
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200142struct mt_fields {
143 unsigned usages[HID_MAX_FIELDS];
144 unsigned int length;
145};
146
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100147struct mt_device {
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100148 struct mt_class mtclass; /* our mt device class */
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +0200149 struct timer_list release_timer; /* to release sticky fingers */
Kees Cook0ee32772017-10-04 17:53:24 -0700150 struct hid_device *hdev; /* hid_device we're attached to */
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200151 struct mt_fields *fields; /* temporary placeholder for storing the
152 multitouch fields */
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +0200153 unsigned long mt_io_flags; /* mt flags (MT_IO_FLAGS_*) */
Benjamin Tissoires55978fa2013-01-31 17:22:24 +0100154 unsigned mt_report_id; /* the report ID of the multitouch device */
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +0200155 __u8 inputmode_value; /* InputMode HID feature value */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100156 __u8 maxcontacts;
Seth Forshee2c6e0272015-03-11 17:26:41 -0500157 bool is_buttonpad; /* is this device a button pad? */
Henrik Rydberg76f59022012-09-01 20:11:34 +0200158 bool serial_maybe; /* need to check for serial protocol */
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200159
160 struct list_head applications;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100161};
162
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200163static void mt_post_parse_default_settings(struct mt_device *td,
164 struct mt_application *app);
165static void mt_post_parse(struct mt_device *td, struct mt_application *app);
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +0100166
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100167/* classes of device behavior */
Benjamin Tissoires22408282011-05-20 15:59:34 +0200168#define MT_CLS_DEFAULT 0x0001
169
Stephane Chattya062cc52011-09-17 22:27:30 +0200170#define MT_CLS_SERIAL 0x0002
171#define MT_CLS_CONFIDENCE 0x0003
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +0100172#define MT_CLS_CONFIDENCE_CONTACT_ID 0x0004
173#define MT_CLS_CONFIDENCE_MINUS_ONE 0x0005
174#define MT_CLS_DUAL_INRANGE_CONTACTID 0x0006
175#define MT_CLS_DUAL_INRANGE_CONTACTNUMBER 0x0007
Benjamin Tissoires0fa9c612014-02-28 11:41:23 -0500176/* reserved 0x0008 */
Aaron Tianb7ea95f2011-12-15 11:09:06 +0800177#define MT_CLS_INRANGE_CONTACTNUMBER 0x0009
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +0100178#define MT_CLS_NSMU 0x000a
Benjamin Tissoires0fa9c612014-02-28 11:41:23 -0500179/* reserved 0x0010 */
180/* reserved 0x0011 */
Benjamin Tissoiresf961bd32013-08-22 14:51:08 +0200181#define MT_CLS_WIN_8 0x0012
Benjamin Tissoires6aef7042014-02-28 11:41:25 -0500182#define MT_CLS_EXPORT_ALL_INPUTS 0x0013
Masaki Ota504c9322017-06-16 09:29:39 +0900183#define MT_CLS_WIN_8_DUAL 0x0014
Benjamin Tissoires22408282011-05-20 15:59:34 +0200184
185/* vendor specific classes */
186#define MT_CLS_3M 0x0101
Benjamin Tissoires0fa9c612014-02-28 11:41:23 -0500187/* reserved 0x0102 */
Benjamin Tissoires22408282011-05-20 15:59:34 +0200188#define MT_CLS_EGALAX 0x0103
Benjamin Tissoires1b723e82011-11-23 10:54:34 +0100189#define MT_CLS_EGALAX_SERIAL 0x0104
Benjamin Tissoires847672c2012-02-04 17:08:50 +0100190#define MT_CLS_TOPSEED 0x0105
Denis Kovalev2258e862012-02-14 00:50:33 -0800191#define MT_CLS_PANASONIC 0x0106
Henrik Rydberg77723e32012-09-07 19:37:40 +0200192#define MT_CLS_FLATFROG 0x0107
Jiri Kosinacdcd3ac2012-10-01 14:38:54 +0200193#define MT_CLS_GENERALTOUCH_TWOFINGERS 0x0108
194#define MT_CLS_GENERALTOUCH_PWT_TENFINGERS 0x0109
Benjamin Tissoiresf3287a92017-01-30 10:48:06 +0100195#define MT_CLS_LG 0x010a
João Paulo Rechi Vita957b8df2017-07-24 14:22:25 -0700196#define MT_CLS_ASUS 0x010b
Mathieu Magnaudetda10bc22014-11-22 12:02:07 +0100197#define MT_CLS_VTL 0x0110
Wei-Ning Huang0e822322017-06-21 10:43:25 +0800198#define MT_CLS_GOOGLE 0x0111
Benjamin Tissoires843e4752018-03-20 12:04:46 +0100199#define MT_CLS_RAZER_BLADE_STEALTH 0x0112
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100200
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100201#define MT_DEFAULT_MAXCONTACT 10
Benjamin Tissoiresafbcb042012-11-14 16:59:18 +0100202#define MT_MAX_MAXCONTACT 250
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100203
Nicolas Boichat29cc3092017-08-22 09:10:11 +0800204/*
205 * Resync device and local timestamps after that many microseconds without
206 * receiving data.
207 */
208#define MAX_TIMESTAMP_INTERVAL 1000000
209
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200210#define MT_USB_DEVICE(v, p) HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH, v, p)
211#define MT_BT_DEVICE(v, p) HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_MULTITOUCH, v, p)
212
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100213/*
214 * these device-dependent functions determine what slot corresponds
215 * to a valid contact that was just read.
216 */
217
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200218static int cypress_compute_slot(struct mt_application *app)
Benjamin Tissoiresa3b5e572011-01-07 23:46:30 +0100219{
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200220 if (app->curdata.contactid != 0 || app->num_received == 0)
221 return app->curdata.contactid;
Benjamin Tissoiresa3b5e572011-01-07 23:46:30 +0100222 else
223 return -1;
224}
225
Benjamin Tissoirescf6d15d2018-07-13 16:13:44 +0200226static const struct mt_class mt_classes[] = {
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100227 { .name = MT_CLS_DEFAULT,
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +0100228 .quirks = MT_QUIRK_ALWAYS_VALID |
229 MT_QUIRK_CONTACT_CNT_ACCURATE },
230 { .name = MT_CLS_NSMU,
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100231 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP },
Stephane Chattya062cc52011-09-17 22:27:30 +0200232 { .name = MT_CLS_SERIAL,
233 .quirks = MT_QUIRK_ALWAYS_VALID},
Benjamin Tissoires22408282011-05-20 15:59:34 +0200234 { .name = MT_CLS_CONFIDENCE,
235 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE },
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +0100236 { .name = MT_CLS_CONFIDENCE_CONTACT_ID,
237 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
238 MT_QUIRK_SLOT_IS_CONTACTID },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200239 { .name = MT_CLS_CONFIDENCE_MINUS_ONE,
240 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
241 MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE },
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +0100242 { .name = MT_CLS_DUAL_INRANGE_CONTACTID,
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100243 .quirks = MT_QUIRK_VALID_IS_INRANGE |
244 MT_QUIRK_SLOT_IS_CONTACTID,
245 .maxcontacts = 2 },
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +0100246 { .name = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100247 .quirks = MT_QUIRK_VALID_IS_INRANGE |
248 MT_QUIRK_SLOT_IS_CONTACTNUMBER,
249 .maxcontacts = 2 },
Aaron Tianb7ea95f2011-12-15 11:09:06 +0800250 { .name = MT_CLS_INRANGE_CONTACTNUMBER,
251 .quirks = MT_QUIRK_VALID_IS_INRANGE |
252 MT_QUIRK_SLOT_IS_CONTACTNUMBER },
Benjamin Tissoiresf961bd32013-08-22 14:51:08 +0200253 { .name = MT_CLS_WIN_8,
254 .quirks = MT_QUIRK_ALWAYS_VALID |
255 MT_QUIRK_IGNORE_DUPLICATES |
256 MT_QUIRK_HOVERING |
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +0200257 MT_QUIRK_CONTACT_CNT_ACCURATE |
Benjamin Tissoiresd9c57a72018-03-20 12:04:45 +0100258 MT_QUIRK_STICKY_FINGERS |
259 MT_QUIRK_WIN8_PTP_BUTTONS },
Benjamin Tissoires6aef7042014-02-28 11:41:25 -0500260 { .name = MT_CLS_EXPORT_ALL_INPUTS,
261 .quirks = MT_QUIRK_ALWAYS_VALID |
262 MT_QUIRK_CONTACT_CNT_ACCURATE,
263 .export_all_inputs = true },
Masaki Ota504c9322017-06-16 09:29:39 +0900264 { .name = MT_CLS_WIN_8_DUAL,
265 .quirks = MT_QUIRK_ALWAYS_VALID |
266 MT_QUIRK_IGNORE_DUPLICATES |
267 MT_QUIRK_HOVERING |
Benjamin Tissoiresd9c57a72018-03-20 12:04:45 +0100268 MT_QUIRK_CONTACT_CNT_ACCURATE |
269 MT_QUIRK_WIN8_PTP_BUTTONS,
Masaki Ota504c9322017-06-16 09:29:39 +0900270 .export_all_inputs = true },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200271
272 /*
273 * vendor specific classes
274 */
275 { .name = MT_CLS_3M,
276 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
HungNien Chene9d0a262017-03-06 11:30:14 +0800277 MT_QUIRK_SLOT_IS_CONTACTID |
278 MT_QUIRK_TOUCH_SIZE_SCALING,
Benjamin Tissoires22408282011-05-20 15:59:34 +0200279 .sn_move = 2048,
280 .sn_width = 128,
Henrik Rydbergc5d40be2012-09-05 16:58:12 +0200281 .sn_height = 128,
282 .maxcontacts = 60,
283 },
Richard Nauber4875ac12011-03-09 06:20:57 +0100284 { .name = MT_CLS_EGALAX,
285 .quirks = MT_QUIRK_SLOT_IS_CONTACTID |
Benjamin Tissoires2261bb92011-11-23 10:54:29 +0100286 MT_QUIRK_VALID_IS_INRANGE,
Richard Nauber4875ac12011-03-09 06:20:57 +0100287 .sn_move = 4096,
288 .sn_pressure = 32,
289 },
Benjamin Tissoires1b723e82011-11-23 10:54:34 +0100290 { .name = MT_CLS_EGALAX_SERIAL,
291 .quirks = MT_QUIRK_SLOT_IS_CONTACTID |
292 MT_QUIRK_ALWAYS_VALID,
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100293 .sn_move = 4096,
294 .sn_pressure = 32,
295 },
Benjamin Tissoires847672c2012-02-04 17:08:50 +0100296 { .name = MT_CLS_TOPSEED,
297 .quirks = MT_QUIRK_ALWAYS_VALID,
298 .is_indirect = true,
299 .maxcontacts = 2,
300 },
Denis Kovalev2258e862012-02-14 00:50:33 -0800301 { .name = MT_CLS_PANASONIC,
302 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP,
303 .maxcontacts = 4 },
Xianhan Yuf5ff4e12012-09-28 10:18:59 +0800304 { .name = MT_CLS_GENERALTOUCH_TWOFINGERS,
305 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
306 MT_QUIRK_VALID_IS_INRANGE |
Luosong7b226292013-10-02 11:20:00 +0200307 MT_QUIRK_SLOT_IS_CONTACTID,
Xianhan Yuf5ff4e12012-09-28 10:18:59 +0800308 .maxcontacts = 2
309 },
310 { .name = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
311 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
Luosong7b226292013-10-02 11:20:00 +0200312 MT_QUIRK_SLOT_IS_CONTACTID
Xianhan Yuf5ff4e12012-09-28 10:18:59 +0800313 },
Benjamin Tissoires043b4032011-03-18 14:27:53 +0100314
Henrik Rydberg77723e32012-09-07 19:37:40 +0200315 { .name = MT_CLS_FLATFROG,
316 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
317 MT_QUIRK_NO_AREA,
318 .sn_move = 2048,
319 .maxcontacts = 40,
320 },
Benjamin Tissoiresf3287a92017-01-30 10:48:06 +0100321 { .name = MT_CLS_LG,
322 .quirks = MT_QUIRK_ALWAYS_VALID |
323 MT_QUIRK_FIX_CONST_CONTACT_ID |
324 MT_QUIRK_IGNORE_DUPLICATES |
325 MT_QUIRK_HOVERING |
326 MT_QUIRK_CONTACT_CNT_ACCURATE },
João Paulo Rechi Vita957b8df2017-07-24 14:22:25 -0700327 { .name = MT_CLS_ASUS,
328 .quirks = MT_QUIRK_ALWAYS_VALID |
329 MT_QUIRK_CONTACT_CNT_ACCURATE |
330 MT_QUIRK_ASUS_CUSTOM_UP },
Mathieu Magnaudetda10bc22014-11-22 12:02:07 +0100331 { .name = MT_CLS_VTL,
332 .quirks = MT_QUIRK_ALWAYS_VALID |
333 MT_QUIRK_CONTACT_CNT_ACCURATE |
334 MT_QUIRK_FORCE_GET_FEATURE,
335 },
Wei-Ning Huang0e822322017-06-21 10:43:25 +0800336 { .name = MT_CLS_GOOGLE,
337 .quirks = MT_QUIRK_ALWAYS_VALID |
338 MT_QUIRK_CONTACT_CNT_ACCURATE |
339 MT_QUIRK_SLOT_IS_CONTACTID |
340 MT_QUIRK_HOVERING
341 },
Benjamin Tissoires843e4752018-03-20 12:04:46 +0100342 { .name = MT_CLS_RAZER_BLADE_STEALTH,
343 .quirks = MT_QUIRK_ALWAYS_VALID |
344 MT_QUIRK_IGNORE_DUPLICATES |
345 MT_QUIRK_HOVERING |
346 MT_QUIRK_CONTACT_CNT_ACCURATE |
347 MT_QUIRK_WIN8_PTP_BUTTONS,
348 },
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100349 { }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100350};
351
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100352static ssize_t mt_show_quirks(struct device *dev,
353 struct device_attribute *attr,
354 char *buf)
355{
Geliang Tangee79a8f2015-12-27 17:25:21 +0800356 struct hid_device *hdev = to_hid_device(dev);
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100357 struct mt_device *td = hid_get_drvdata(hdev);
358
359 return sprintf(buf, "%u\n", td->mtclass.quirks);
360}
361
362static ssize_t mt_set_quirks(struct device *dev,
363 struct device_attribute *attr,
364 const char *buf, size_t count)
365{
Geliang Tangee79a8f2015-12-27 17:25:21 +0800366 struct hid_device *hdev = to_hid_device(dev);
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100367 struct mt_device *td = hid_get_drvdata(hdev);
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200368 struct mt_application *application;
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100369
370 unsigned long val;
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200371 bool confidence_found = false;
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100372
373 if (kstrtoul(buf, 0, &val))
374 return -EINVAL;
375
376 td->mtclass.quirks = val;
377
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200378 list_for_each_entry(application, &td->applications, list) {
379 if (application->have_contact_count)
380 confidence_found = true;
381 }
382
383 if (!confidence_found)
Benjamin Tissoiresc2517f62013-01-31 17:22:25 +0100384 td->mtclass.quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE;
385
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100386 return count;
387}
388
389static DEVICE_ATTR(quirks, S_IWUSR | S_IRUGO, mt_show_quirks, mt_set_quirks);
390
391static struct attribute *sysfs_attrs[] = {
392 &dev_attr_quirks.attr,
393 NULL
394};
395
Arvind Yadav9182fb92017-08-03 16:56:43 +0530396static const struct attribute_group mt_attribute_group = {
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100397 .attrs = sysfs_attrs
398};
399
Mika Westerberg6d4f5442015-10-07 15:33:43 +0300400static void mt_get_feature(struct hid_device *hdev, struct hid_report *report)
401{
Aaron Ma3064a032018-02-03 23:57:15 +0800402 int ret;
403 u32 size = hid_report_len(report);
Mika Westerberg6d4f5442015-10-07 15:33:43 +0300404 u8 *buf;
405
406 /*
Benjamin Tissoiresb897f6d2016-11-25 14:27:22 +0100407 * Do not fetch the feature report if the device has been explicitly
408 * marked as non-capable.
Mika Westerberg6d4f5442015-10-07 15:33:43 +0300409 */
Benjamin Tissoiresadaabbf2018-03-20 12:04:50 +0100410 if (hdev->quirks & HID_QUIRK_NO_INIT_REPORTS)
Mika Westerberg6d4f5442015-10-07 15:33:43 +0300411 return;
412
413 buf = hid_alloc_report_buf(report, GFP_KERNEL);
414 if (!buf)
415 return;
416
417 ret = hid_hw_raw_request(hdev, report->id, buf, size,
418 HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
419 if (ret < 0) {
420 dev_warn(&hdev->dev, "failed to fetch feature %d\n",
421 report->id);
422 } else {
423 ret = hid_report_raw_event(hdev, HID_FEATURE_REPORT, buf,
424 size, 0);
425 if (ret)
426 dev_warn(&hdev->dev, "failed to report feature\n");
427 }
428
429 kfree(buf);
430}
431
Henrik Rydbergf635bd12011-02-24 19:30:59 +0100432static void mt_feature_mapping(struct hid_device *hdev,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100433 struct hid_field *field, struct hid_usage *usage)
434{
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100435 struct mt_device *td = hid_get_drvdata(hdev);
436
437 switch (usage->hid) {
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100438 case HID_DG_CONTACTMAX:
Mika Westerberg6d4f5442015-10-07 15:33:43 +0300439 mt_get_feature(hdev, field->report);
440
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100441 td->maxcontacts = field->value[0];
Benjamin Tissoiresafbcb042012-11-14 16:59:18 +0100442 if (!td->maxcontacts &&
443 field->logical_maximum <= MT_MAX_MAXCONTACT)
444 td->maxcontacts = field->logical_maximum;
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100445 if (td->mtclass.maxcontacts)
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100446 /* check if the maxcontacts is given by the class */
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100447 td->maxcontacts = td->mtclass.maxcontacts;
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100448
449 break;
Seth Forshee2c6e0272015-03-11 17:26:41 -0500450 case HID_DG_BUTTONTYPE:
451 if (usage->usage_index >= field->report_count) {
452 dev_err(&hdev->dev, "HID_DG_BUTTONTYPE out of range\n");
453 break;
454 }
455
Mika Westerberg6d4f5442015-10-07 15:33:43 +0300456 mt_get_feature(hdev, field->report);
Seth Forshee2c6e0272015-03-11 17:26:41 -0500457 if (field->value[usage->usage_index] == MT_BUTTONTYPE_CLICKPAD)
458 td->is_buttonpad = true;
459
460 break;
Benjamin Tissoires45c5c682016-03-07 11:02:38 +0100461 case 0xff0000c5:
462 /* Retrieve the Win8 blob once to enable some devices */
463 if (usage->usage_index == 0)
464 mt_get_feature(hdev, field->report);
465 break;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100466 }
467}
468
469static void set_abs(struct input_dev *input, unsigned int code,
470 struct hid_field *field, int snratio)
471{
472 int fmin = field->logical_minimum;
473 int fmax = field->logical_maximum;
474 int fuzz = snratio ? (fmax - fmin) / snratio : 0;
475 input_set_abs_params(input, code, fmin, fmax, fuzz, 0);
Benjamin Tissoires37cf6e62012-11-14 16:59:13 +0100476 input_abs_set_res(input, code, hidinput_calc_abs_res(field, code));
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100477}
478
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200479static struct mt_application *mt_allocate_application(struct mt_device *td,
480 unsigned int application)
481{
482 struct mt_application *mt_application;
483
484 mt_application = devm_kzalloc(&td->hdev->dev, sizeof(*mt_application),
485 GFP_KERNEL);
486 if (!mt_application)
487 return NULL;
488
489 mt_application->application = application;
490
491 if (application == HID_DG_TOUCHSCREEN)
492 mt_application->mt_flags |= INPUT_MT_DIRECT;
493
494 /*
495 * Model touchscreens providing buttons as touchpads.
496 */
497 if (application == HID_DG_TOUCHPAD) {
498 mt_application->mt_flags |= INPUT_MT_POINTER;
499 td->inputmode_value = MT_INPUTMODE_TOUCHPAD;
500 }
501
502 mt_application->cc_index = -1;
503 mt_application->scantime_index = -1;
504
505 list_add_tail(&mt_application->list, &td->applications);
506
507 return mt_application;
508}
509
510static struct mt_application *mt_find_application(struct mt_device *td,
511 unsigned int application)
512{
513 struct mt_application *tmp, *mt_application = NULL;
514
515 list_for_each_entry(tmp, &td->applications, list) {
516 if (application == tmp->application) {
517 mt_application = tmp;
518 break;
519 }
520 }
521
522 if (!mt_application)
523 mt_application = mt_allocate_application(td, application);
524
525 return mt_application;
526}
527
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200528static void mt_store_field(struct hid_usage *usage, struct mt_device *td,
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100529 struct hid_input *hi)
530{
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200531 struct mt_fields *f = td->fields;
532
533 if (f->length >= HID_MAX_FIELDS)
534 return;
535
536 f->usages[f->length++] = usage->hid;
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100537}
538
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +0100539static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100540 struct hid_field *field, struct hid_usage *usage,
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200541 unsigned long **bit, int *max, struct mt_application *app)
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100542{
543 struct mt_device *td = hid_get_drvdata(hdev);
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100544 struct mt_class *cls = &td->mtclass;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100545 int code;
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100546 struct hid_usage *prev_usage = NULL;
Richard Nauber4875ac12011-03-09 06:20:57 +0100547
Henrik Rydberg76f59022012-09-01 20:11:34 +0200548 /*
549 * Model touchscreens providing buttons as touchpads.
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100550 */
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200551 if ((usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON) {
552 app->mt_flags |= INPUT_MT_POINTER;
Andrew Duggan9abebed2014-03-19 13:39:03 -0700553 td->inputmode_value = MT_INPUTMODE_TOUCHPAD;
554 }
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100555
Benjamin Tissoires015fdaa2015-03-06 11:14:42 -0500556 /* count the buttons on touchpads */
557 if ((usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON)
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200558 app->buttons_count++;
Benjamin Tissoires015fdaa2015-03-06 11:14:42 -0500559
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100560 if (usage->usage_index)
561 prev_usage = &field->usage[usage->usage_index - 1];
562
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100563 switch (usage->hid & HID_USAGE_PAGE) {
564
565 case HID_UP_GENDESK:
566 switch (usage->hid) {
567 case HID_GD_X:
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200568 if (prev_usage && (prev_usage->hid == usage->hid))
569 code = ABS_MT_TOOL_X;
570 else
571 code = ABS_MT_POSITION_X;
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100572
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200573 hid_map_usage(hi, usage, bit, max, EV_ABS, code);
574 set_abs(hi->input, code, field, cls->sn_move);
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200575 mt_store_field(usage, td, hi);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100576 return 1;
577 case HID_GD_Y:
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200578 if (prev_usage && (prev_usage->hid == usage->hid))
579 code = ABS_MT_TOOL_Y;
580 else
581 code = ABS_MT_POSITION_Y;
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100582
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200583 hid_map_usage(hi, usage, bit, max, EV_ABS, code);
584 set_abs(hi->input, code, field, cls->sn_move);
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200585 mt_store_field(usage, td, hi);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100586 return 1;
587 }
588 return 0;
589
590 case HID_UP_DIGITIZER:
591 switch (usage->hid) {
592 case HID_DG_INRANGE:
Benjamin Tissoires9b3bb9b82012-11-14 16:59:24 +0100593 if (cls->quirks & MT_QUIRK_HOVERING) {
594 hid_map_usage(hi, usage, bit, max,
595 EV_ABS, ABS_MT_DISTANCE);
596 input_set_abs_params(hi->input,
597 ABS_MT_DISTANCE, 0, 1, 0, 0);
598 }
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200599 mt_store_field(usage, td, hi);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100600 return 1;
601 case HID_DG_CONFIDENCE:
Masaki Ota504c9322017-06-16 09:29:39 +0900602 if ((cls->name == MT_CLS_WIN_8 ||
603 cls->name == MT_CLS_WIN_8_DUAL) &&
Allen Hung6dd2e272016-06-23 16:31:30 +0800604 field->application == HID_DG_TOUCHPAD)
605 cls->quirks |= MT_QUIRK_CONFIDENCE;
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200606 mt_store_field(usage, td, hi);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100607 return 1;
608 case HID_DG_TIPSWITCH:
609 hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_TOUCH);
610 input_set_capability(hi->input, EV_KEY, BTN_TOUCH);
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200611 mt_store_field(usage, td, hi);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100612 return 1;
613 case HID_DG_CONTACTID:
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200614 mt_store_field(usage, td, hi);
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200615 app->touches_by_report++;
Benjamin Tissoires55978fa2013-01-31 17:22:24 +0100616 td->mt_report_id = field->report->id;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100617 return 1;
618 case HID_DG_WIDTH:
619 hid_map_usage(hi, usage, bit, max,
620 EV_ABS, ABS_MT_TOUCH_MAJOR);
Henrik Rydberg77723e32012-09-07 19:37:40 +0200621 if (!(cls->quirks & MT_QUIRK_NO_AREA))
622 set_abs(hi->input, ABS_MT_TOUCH_MAJOR, field,
623 cls->sn_width);
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200624 mt_store_field(usage, td, hi);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100625 return 1;
626 case HID_DG_HEIGHT:
627 hid_map_usage(hi, usage, bit, max,
628 EV_ABS, ABS_MT_TOUCH_MINOR);
Henrik Rydberg77723e32012-09-07 19:37:40 +0200629 if (!(cls->quirks & MT_QUIRK_NO_AREA)) {
630 set_abs(hi->input, ABS_MT_TOUCH_MINOR, field,
631 cls->sn_height);
Wei-Ning Huang00720272017-10-12 14:21:43 +0800632
633 /*
634 * Only set ABS_MT_ORIENTATION if it is not
635 * already set by the HID_DG_AZIMUTH usage.
636 */
637 if (!test_bit(ABS_MT_ORIENTATION,
638 hi->input->absbit))
639 input_set_abs_params(hi->input,
640 ABS_MT_ORIENTATION, 0, 1, 0, 0);
Henrik Rydberg77723e32012-09-07 19:37:40 +0200641 }
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200642 mt_store_field(usage, td, hi);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100643 return 1;
644 case HID_DG_TIPPRESSURE:
645 hid_map_usage(hi, usage, bit, max,
646 EV_ABS, ABS_MT_PRESSURE);
647 set_abs(hi->input, ABS_MT_PRESSURE, field,
648 cls->sn_pressure);
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200649 mt_store_field(usage, td, hi);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100650 return 1;
Nicolas Boichat29cc3092017-08-22 09:10:11 +0800651 case HID_DG_SCANTIME:
652 hid_map_usage(hi, usage, bit, max,
653 EV_MSC, MSC_TIMESTAMP);
654 input_set_capability(hi->input, EV_MSC, MSC_TIMESTAMP);
Hans de Goedeaf8dc4d2017-11-22 12:57:08 +0100655 /* Ignore if indexes are out of bounds. */
656 if (field->index >= field->report->maxfield ||
657 usage->usage_index >= field->report_count)
658 return 1;
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200659 app->scantime_index = field->index;
660 app->scantime_val_index = usage->usage_index;
Nicolas Boichat29cc3092017-08-22 09:10:11 +0800661 return 1;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100662 case HID_DG_CONTACTCOUNT:
Benjamin Tissoires8821f5d2013-09-11 21:56:58 +0200663 /* Ignore if indexes are out of bounds. */
664 if (field->index >= field->report->maxfield ||
665 usage->usage_index >= field->report_count)
666 return 1;
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200667 app->cc_index = field->index;
668 app->cc_value_index = usage->usage_index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100669 return 1;
Wei-Ning Huang00720272017-10-12 14:21:43 +0800670 case HID_DG_AZIMUTH:
671 hid_map_usage(hi, usage, bit, max,
672 EV_ABS, ABS_MT_ORIENTATION);
673 /*
674 * Azimuth has the range of [0, MAX) representing a full
675 * revolution. Set ABS_MT_ORIENTATION to a quarter of
676 * MAX according the definition of ABS_MT_ORIENTATION
677 */
678 input_set_abs_params(hi->input, ABS_MT_ORIENTATION,
679 -field->logical_maximum / 4,
680 field->logical_maximum / 4,
681 cls->sn_move ?
682 field->logical_maximum / cls->sn_move : 0, 0);
683 mt_store_field(usage, td, hi);
684 return 1;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100685 case HID_DG_CONTACTMAX:
686 /* we don't set td->last_slot_field as contactcount and
687 * contact max are global to the report */
688 return -1;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100689 case HID_DG_TOUCH:
690 /* Legacy devices use TIPSWITCH and not TOUCH.
691 * Let's just ignore this field. */
692 return -1;
Alan Cox65b258e2012-10-25 15:35:25 +0100693 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100694 /* let hid-input decide for the others */
695 return 0;
696
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100697 case HID_UP_BUTTON:
698 code = BTN_MOUSE + ((usage->hid - 1) & HID_USAGE);
Benjamin Tissoires594312b2016-11-25 11:08:10 +0100699 /*
700 * MS PTP spec says that external buttons left and right have
701 * usages 2 and 3.
702 */
Benjamin Tissoiresd9c57a72018-03-20 12:04:45 +0100703 if ((cls->quirks & MT_QUIRK_WIN8_PTP_BUTTONS) &&
Benjamin Tissoires594312b2016-11-25 11:08:10 +0100704 field->application == HID_DG_TOUCHPAD &&
705 (usage->hid & HID_USAGE) > 1)
706 code--;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100707 hid_map_usage(hi, usage, bit, max, EV_KEY, code);
708 input_set_capability(hi->input, EV_KEY, code);
709 return 1;
710
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100711 case 0xff000000:
712 /* we do not want to map these: no input-oriented meaning */
713 return -1;
714 }
715
716 return 0;
717}
718
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200719static int mt_compute_slot(struct mt_device *td, struct mt_application *app,
720 struct input_dev *input)
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100721{
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100722 __s32 quirks = td->mtclass.quirks;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100723
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100724 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID)
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200725 return app->curdata.contactid;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100726
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100727 if (quirks & MT_QUIRK_CYPRESS)
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200728 return cypress_compute_slot(app);
Benjamin Tissoiresa3b5e572011-01-07 23:46:30 +0100729
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100730 if (quirks & MT_QUIRK_SLOT_IS_CONTACTNUMBER)
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200731 return app->num_received;
Benjamin Tissoires5572da02011-01-07 23:47:27 +0100732
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +0200733 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE)
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200734 return app->curdata.contactid - 1;
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +0200735
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200736 return input_mt_get_slot_by_key(input, app->curdata.contactid);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100737}
738
739/*
740 * this function is called when a whole contact has been processed,
741 * so that it can assign it to a slot and store the data there
742 */
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200743static void mt_complete_slot(struct mt_device *td, struct mt_application *app,
744 struct input_dev *input)
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100745{
Benjamin Tissoiresc2517f62013-01-31 17:22:25 +0100746 if ((td->mtclass.quirks & MT_QUIRK_CONTACT_CNT_ACCURATE) &&
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200747 app->num_received >= app->num_expected)
Benjamin Tissoiresc2517f62013-01-31 17:22:25 +0100748 return;
749
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200750 if (app->curvalid || (td->mtclass.quirks & MT_QUIRK_ALWAYS_VALID)) {
Allen Hung6dd2e272016-06-23 16:31:30 +0800751 int active;
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200752 int slotnum = mt_compute_slot(td, app, input);
753 struct mt_slot *s = &app->curdata;
Benjamin Tissoires28728392012-11-14 16:59:23 +0100754 struct input_mt *mt = input->mt;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100755
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200756 if (slotnum < 0 || slotnum >= td->maxcontacts)
757 return;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100758
Benjamin Tissoires28728392012-11-14 16:59:23 +0100759 if ((td->mtclass.quirks & MT_QUIRK_IGNORE_DUPLICATES) && mt) {
760 struct input_mt_slot *slot = &mt->slots[slotnum];
761 if (input_mt_is_active(slot) &&
762 input_mt_is_used(mt, slot))
763 return;
764 }
765
Allen Hung6dd2e272016-06-23 16:31:30 +0800766 if (!(td->mtclass.quirks & MT_QUIRK_CONFIDENCE))
Gustavo A. R. Silva001fab42018-03-05 18:10:46 -0600767 s->confidence_state = true;
Allen Hung6dd2e272016-06-23 16:31:30 +0800768 active = (s->touch_state || s->inrange_state) &&
769 s->confidence_state;
770
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200771 input_mt_slot(input, slotnum);
Allen Hung6dd2e272016-06-23 16:31:30 +0800772 input_mt_report_slot_state(input, MT_TOOL_FINGER, active);
773 if (active) {
Benjamin Tissoires9b3bb9b82012-11-14 16:59:24 +0100774 /* this finger is in proximity of the sensor */
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100775 int wide = (s->w > s->h);
HungNien Chene9d0a262017-03-06 11:30:14 +0800776 int major = max(s->w, s->h);
777 int minor = min(s->w, s->h);
Wei-Ning Huang00720272017-10-12 14:21:43 +0800778 int orientation = wide;
779
780 if (s->has_azimuth)
781 orientation = s->a;
HungNien Chene9d0a262017-03-06 11:30:14 +0800782
783 /*
784 * divided by two to match visual scale of touch
785 * for devices with this quirk
786 */
787 if (td->mtclass.quirks & MT_QUIRK_TOUCH_SIZE_SCALING) {
788 major = major >> 1;
789 minor = minor >> 1;
790 }
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100791
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100792 input_event(input, EV_ABS, ABS_MT_POSITION_X, s->x);
793 input_event(input, EV_ABS, ABS_MT_POSITION_Y, s->y);
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100794 input_event(input, EV_ABS, ABS_MT_TOOL_X, s->cx);
795 input_event(input, EV_ABS, ABS_MT_TOOL_Y, s->cy);
Benjamin Tissoires9b3bb9b82012-11-14 16:59:24 +0100796 input_event(input, EV_ABS, ABS_MT_DISTANCE,
797 !s->touch_state);
Wei-Ning Huang00720272017-10-12 14:21:43 +0800798 input_event(input, EV_ABS, ABS_MT_ORIENTATION,
799 orientation);
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100800 input_event(input, EV_ABS, ABS_MT_PRESSURE, s->p);
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100801 input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, major);
802 input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, minor);
Benjamin Tissoires96098272017-06-15 15:32:05 +0200803
804 set_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags);
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100805 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100806 }
807
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200808 app->num_received++;
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200809}
810
811/*
812 * this function is called when a whole packet has been received and processed,
813 * so that it can decide what to send to the input layer.
814 */
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200815static void mt_sync_frame(struct mt_device *td, struct mt_application *app,
816 struct input_dev *input)
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200817{
Benjamin Tissoiresd9c57a72018-03-20 12:04:45 +0100818 if (td->mtclass.quirks & MT_QUIRK_WIN8_PTP_BUTTONS)
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200819 input_event(input, EV_KEY, BTN_LEFT, app->left_button_state);
Hans de Goede127e71b2017-11-22 12:57:10 +0100820
Henrik Rydberg76f59022012-09-01 20:11:34 +0200821 input_mt_sync_frame(input);
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200822 input_event(input, EV_MSC, MSC_TIMESTAMP, app->timestamp);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100823 input_sync(input);
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200824 app->num_received = 0;
825 app->left_button_state = 0;
826
Benjamin Tissoires96098272017-06-15 15:32:05 +0200827 if (test_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags))
828 set_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags);
829 else
830 clear_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags);
831 clear_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100832}
833
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200834static int mt_compute_timestamp(struct mt_application *app,
835 struct hid_field *field, __s32 value)
Nicolas Boichat29cc3092017-08-22 09:10:11 +0800836{
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200837 long delta = value - app->prev_scantime;
838 unsigned long jdelta = jiffies_to_usecs(jiffies - app->jiffies);
Nicolas Boichat29cc3092017-08-22 09:10:11 +0800839
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200840 app->jiffies = jiffies;
Nicolas Boichat29cc3092017-08-22 09:10:11 +0800841
842 if (delta < 0)
843 delta += field->logical_maximum;
844
845 /* HID_DG_SCANTIME is expressed in 100us, we want it in us. */
846 delta *= 100;
847
848 if (jdelta > MAX_TIMESTAMP_INTERVAL)
849 /* No data received for a while, resync the timestamp. */
850 return 0;
851 else
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200852 return app->timestamp + delta;
Nicolas Boichat29cc3092017-08-22 09:10:11 +0800853}
854
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +0100855static int mt_touch_event(struct hid_device *hid, struct hid_field *field,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100856 struct hid_usage *usage, __s32 value)
857{
Benjamin Tissoires55978fa2013-01-31 17:22:24 +0100858 /* we will handle the hidinput part later, now remains hiddev */
859 if (hid->claimed & HID_CLAIMED_HIDDEV && hid->hiddev_hid_event)
860 hid->hiddev_hid_event(hid, field, usage, value);
861
862 return 1;
863}
864
865static void mt_process_mt_event(struct hid_device *hid, struct hid_field *field,
Hans de Goede55746d22017-11-22 12:57:09 +0100866 struct hid_usage *usage, __s32 value,
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200867 struct mt_application *app, bool first_packet)
Benjamin Tissoires55978fa2013-01-31 17:22:24 +0100868{
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100869 struct mt_device *td = hid_get_drvdata(hid);
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100870 __s32 quirks = td->mtclass.quirks;
Benjamin Tissoires4c437552013-03-22 18:53:57 +0100871 struct input_dev *input = field->hidinput->input;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100872
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200873 if (hid->claimed & HID_CLAIMED_INPUT) {
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100874 switch (usage->hid) {
875 case HID_DG_INRANGE:
Benjamin Tissoires20b60e62012-11-14 16:59:20 +0100876 if (quirks & MT_QUIRK_VALID_IS_INRANGE)
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200877 app->curvalid = value;
Benjamin Tissoires9b3bb9b82012-11-14 16:59:24 +0100878 if (quirks & MT_QUIRK_HOVERING)
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200879 app->curdata.inrange_state = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100880 break;
881 case HID_DG_TIPSWITCH:
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100882 if (quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200883 app->curvalid = value;
884 app->curdata.touch_state = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100885 break;
886 case HID_DG_CONFIDENCE:
Allen Hung6dd2e272016-06-23 16:31:30 +0800887 if (quirks & MT_QUIRK_CONFIDENCE)
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200888 app->curdata.confidence_state = value;
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100889 if (quirks & MT_QUIRK_VALID_IS_CONFIDENCE)
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200890 app->curvalid = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100891 break;
892 case HID_DG_CONTACTID:
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200893 app->curdata.contactid = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100894 break;
895 case HID_DG_TIPPRESSURE:
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200896 app->curdata.p = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100897 break;
898 case HID_GD_X:
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100899 if (usage->code == ABS_MT_TOOL_X)
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200900 app->curdata.cx = value;
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100901 else
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200902 app->curdata.x = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100903 break;
904 case HID_GD_Y:
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100905 if (usage->code == ABS_MT_TOOL_Y)
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200906 app->curdata.cy = value;
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100907 else
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200908 app->curdata.y = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100909 break;
910 case HID_DG_WIDTH:
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200911 app->curdata.w = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100912 break;
913 case HID_DG_HEIGHT:
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200914 app->curdata.h = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100915 break;
Nicolas Boichat29cc3092017-08-22 09:10:11 +0800916 case HID_DG_SCANTIME:
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200917 app->timestamp = mt_compute_timestamp(app, field,
918 value);
Nicolas Boichat29cc3092017-08-22 09:10:11 +0800919 break;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100920 case HID_DG_CONTACTCOUNT:
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100921 break;
Wei-Ning Huang00720272017-10-12 14:21:43 +0800922 case HID_DG_AZIMUTH:
923 /*
924 * Azimuth is counter-clockwise and ranges from [0, MAX)
925 * (a full revolution). Convert it to clockwise ranging
926 * [-MAX/2, MAX/2].
927 *
928 * Note that ABS_MT_ORIENTATION require us to report
929 * the limit of [-MAX/4, MAX/4], but the value can go
930 * out of range to [-MAX/2, MAX/2] to report an upside
931 * down ellipsis.
932 */
933 if (value > field->logical_maximum / 2)
934 value -= field->logical_maximum;
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200935 app->curdata.a = -value;
936 app->curdata.has_azimuth = true;
Wei-Ning Huang00720272017-10-12 14:21:43 +0800937 break;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100938 case HID_DG_TOUCH:
939 /* do nothing */
940 break;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100941
942 default:
Hans de Goede55746d22017-11-22 12:57:09 +0100943 /*
944 * For Win8 PTP touchpads we should only look at
945 * non finger/touch events in the first_packet of
946 * a (possible) multi-packet frame.
947 */
Benjamin Tissoiresd9c57a72018-03-20 12:04:45 +0100948 if ((quirks & MT_QUIRK_WIN8_PTP_BUTTONS) &&
Hans de Goede55746d22017-11-22 12:57:09 +0100949 !first_packet)
950 return;
951
Hans de Goede127e71b2017-11-22 12:57:10 +0100952 /*
953 * For Win8 PTP touchpads we map both the clickpad click
954 * and any "external" left buttons to BTN_LEFT if a
955 * device claims to have both we need to report 1 for
956 * BTN_LEFT if either is pressed, so we or all values
957 * together and report the result in mt_sync_frame().
958 */
Benjamin Tissoiresd9c57a72018-03-20 12:04:45 +0100959 if ((quirks & MT_QUIRK_WIN8_PTP_BUTTONS) &&
Hans de Goede127e71b2017-11-22 12:57:10 +0100960 usage->type == EV_KEY && usage->code == BTN_LEFT) {
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200961 app->left_button_state |= value;
Hans de Goede127e71b2017-11-22 12:57:10 +0100962 return;
963 }
964
Benjamin Tissoires4c437552013-03-22 18:53:57 +0100965 if (usage->type)
966 input_event(input, usage->type, usage->code,
967 value);
Benjamin Tissoires55978fa2013-01-31 17:22:24 +0100968 return;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100969 }
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100970
Benjamin Tissoires54f4c0c2012-11-14 16:59:17 +0100971 if (usage->usage_index + 1 == field->report_count) {
972 /* we only take into account the last report. */
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200973 if (usage->hid == app->last_slot_field)
974 mt_complete_slot(td, app,
975 field->hidinput->input);
Benjamin Tissoires54f4c0c2012-11-14 16:59:17 +0100976 }
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100977
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100978 }
Benjamin Tissoires55978fa2013-01-31 17:22:24 +0100979}
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100980
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +0100981static void mt_touch_report(struct hid_device *hid, struct hid_report *report)
Benjamin Tissoires55978fa2013-01-31 17:22:24 +0100982{
983 struct mt_device *td = hid_get_drvdata(hid);
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200984 struct mt_application *app;
Benjamin Tissoires55978fa2013-01-31 17:22:24 +0100985 struct hid_field *field;
Hans de Goede55746d22017-11-22 12:57:09 +0100986 bool first_packet;
Benjamin Tissoires55978fa2013-01-31 17:22:24 +0100987 unsigned count;
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200988 int r, n;
989 int scantime = 0;
990 int contact_count = -1;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100991
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +0200992 /* sticky fingers release in progress, abort */
993 if (test_and_set_bit(MT_IO_FLAGS_RUNNING, &td->mt_io_flags))
994 return;
995
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200996 app = mt_find_application(td, report->application);
997
998 if (!app)
999 return;
1000
Benjamin Tissoiresc2517f62013-01-31 17:22:25 +01001001 /*
1002 * Includes multi-packet support where subsequent
1003 * packets are sent with zero contactcount.
1004 */
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001005 if (app->scantime_index >= 0) {
1006 field = report->field[app->scantime_index];
1007 scantime = field->value[app->scantime_val_index];
Hans de Goedeaf8dc4d2017-11-22 12:57:08 +01001008 }
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001009 if (app->cc_index >= 0) {
1010 field = report->field[app->cc_index];
1011 contact_count = field->value[app->cc_value_index];
Hans de Goedeaf8dc4d2017-11-22 12:57:08 +01001012
1013 /*
1014 * For Win8 PTPs the first packet (td->num_received == 0) may
1015 * have a contactcount of 0 if there only is a button event.
1016 * We double check that this is not a continuation packet
1017 * of a possible multi-packet frame be checking that the
1018 * timestamp has changed.
1019 */
Benjamin Tissoiresd9c57a72018-03-20 12:04:45 +01001020 if ((td->mtclass.quirks & MT_QUIRK_WIN8_PTP_BUTTONS) &&
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001021 app->num_received == 0 &&
1022 app->prev_scantime != scantime)
1023 app->num_expected = contact_count;
Hans de Goedeaf8dc4d2017-11-22 12:57:08 +01001024 /* A non 0 contact count always indicates a first packet */
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001025 else if (contact_count)
1026 app->num_expected = contact_count;
Benjamin Tissoires7e3cc442013-02-06 12:10:47 +01001027 }
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001028 app->prev_scantime = scantime;
Benjamin Tissoiresc2517f62013-01-31 17:22:25 +01001029
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001030 first_packet = app->num_received == 0;
Benjamin Tissoires55978fa2013-01-31 17:22:24 +01001031 for (r = 0; r < report->maxfield; r++) {
1032 field = report->field[r];
1033 count = field->report_count;
1034
1035 if (!(HID_MAIN_ITEM_VARIABLE & field->flags))
1036 continue;
1037
1038 for (n = 0; n < count; n++)
1039 mt_process_mt_event(hid, field, &field->usage[n],
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001040 field->value[n], app, first_packet);
Benjamin Tissoires55978fa2013-01-31 17:22:24 +01001041 }
Benjamin Tissoires5b62efd2013-02-27 16:23:15 +01001042
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001043 if (app->num_received >= app->num_expected)
1044 mt_sync_frame(td, app, report->field[0]->hidinput->input);
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +02001045
1046 /*
1047 * Windows 8 specs says 2 things:
1048 * - once a contact has been reported, it has to be reported in each
1049 * subsequent report
1050 * - the report rate when fingers are present has to be at least
1051 * the refresh rate of the screen, 60 or 120 Hz
1052 *
1053 * I interprete this that the specification forces a report rate of
1054 * at least 60 Hz for a touchscreen to be certified.
1055 * Which means that if we do not get a report whithin 16 ms, either
1056 * something wrong happens, either the touchscreen forgets to send
1057 * a release. Taking a reasonable margin allows to remove issues
1058 * with USB communication or the load of the machine.
1059 *
1060 * Given that Win 8 devices are forced to send a release, this will
1061 * only affect laggish machines and the ones that have a firmware
1062 * defect.
1063 */
Benjamin Tissoires96098272017-06-15 15:32:05 +02001064 if (td->mtclass.quirks & MT_QUIRK_STICKY_FINGERS) {
1065 if (test_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags))
1066 mod_timer(&td->release_timer,
1067 jiffies + msecs_to_jiffies(100));
1068 else
1069 del_timer(&td->release_timer);
1070 }
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +02001071
1072 clear_bit(MT_IO_FLAGS_RUNNING, &td->mt_io_flags);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001073}
1074
Dmitry Torokhovb2c68a22015-09-29 15:52:59 -07001075static int mt_touch_input_configured(struct hid_device *hdev,
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001076 struct hid_input *hi,
1077 struct mt_application *app)
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001078{
1079 struct mt_device *td = hid_get_drvdata(hdev);
1080 struct mt_class *cls = &td->mtclass;
1081 struct input_dev *input = hi->input;
Dmitry Torokhovb2c68a22015-09-29 15:52:59 -07001082 int ret;
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001083
1084 if (!td->maxcontacts)
1085 td->maxcontacts = MT_DEFAULT_MAXCONTACT;
1086
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001087 mt_post_parse(td, app);
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001088 if (td->serial_maybe)
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001089 mt_post_parse_default_settings(td, app);
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001090
1091 if (cls->is_indirect)
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001092 app->mt_flags |= INPUT_MT_POINTER;
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001093
1094 if (cls->quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001095 app->mt_flags |= INPUT_MT_DROP_UNUSED;
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001096
Benjamin Tissoires015fdaa2015-03-06 11:14:42 -05001097 /* check for clickpads */
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001098 if ((app->mt_flags & INPUT_MT_POINTER) &&
1099 (app->buttons_count == 1))
Seth Forshee2c6e0272015-03-11 17:26:41 -05001100 td->is_buttonpad = true;
1101
1102 if (td->is_buttonpad)
Benjamin Tissoires015fdaa2015-03-06 11:14:42 -05001103 __set_bit(INPUT_PROP_BUTTONPAD, input->propbit);
1104
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001105 ret = input_mt_init_slots(input, td->maxcontacts, app->mt_flags);
Dmitry Torokhovb2c68a22015-09-29 15:52:59 -07001106 if (ret)
1107 return ret;
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001108
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001109 app->mt_flags = 0;
Dmitry Torokhovb2c68a22015-09-29 15:52:59 -07001110 return 0;
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001111}
1112
João Paulo Rechi Vita957b8df2017-07-24 14:22:25 -07001113#define mt_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, \
1114 max, EV_KEY, (c))
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001115static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
1116 struct hid_field *field, struct hid_usage *usage,
1117 unsigned long **bit, int *max)
1118{
Benjamin Tissoires6aef7042014-02-28 11:41:25 -05001119 struct mt_device *td = hid_get_drvdata(hdev);
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001120 struct mt_application *application;
Benjamin Tissoires6aef7042014-02-28 11:41:25 -05001121
1122 /*
1123 * If mtclass.export_all_inputs is not set, only map fields from
1124 * TouchScreen or TouchPad collections. We need to ignore fields
1125 * that belong to other collections such as Mouse that might have
1126 * the same GenericDesktop usages.
1127 */
1128 if (!td->mtclass.export_all_inputs &&
1129 field->application != HID_DG_TOUCHSCREEN &&
Benjamin Tissoiresfa11aa72013-03-22 18:38:32 +01001130 field->application != HID_DG_PEN &&
Benjamin Tissoires8fe89ef2016-11-25 14:27:23 +01001131 field->application != HID_DG_TOUCHPAD &&
1132 field->application != HID_GD_KEYBOARD &&
Hans de Goedee57f4e62017-08-22 08:37:52 +02001133 field->application != HID_GD_SYSTEM_CONTROL &&
João Paulo Rechi Vita1fbf74ef2017-07-24 14:22:24 -07001134 field->application != HID_CP_CONSUMER_CONTROL &&
João Paulo Rechi Vita957b8df2017-07-24 14:22:25 -07001135 field->application != HID_GD_WIRELESS_RADIO_CTLS &&
1136 !(field->application == HID_VD_ASUS_CUSTOM_MEDIA_KEYS &&
1137 td->mtclass.quirks & MT_QUIRK_ASUS_CUSTOM_UP))
Benjamin Tissoires6f492f22013-03-22 18:38:30 +01001138 return -1;
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001139
Benjamin Tissoires6aef7042014-02-28 11:41:25 -05001140 /*
João Paulo Rechi Vita957b8df2017-07-24 14:22:25 -07001141 * Some Asus keyboard+touchpad devices have the hotkeys defined in the
1142 * touchpad report descriptor. We need to treat these as an array to
1143 * map usages to input keys.
1144 */
Jiri Kosina39bbf402017-08-03 11:25:32 +02001145 if (field->application == HID_VD_ASUS_CUSTOM_MEDIA_KEYS &&
João Paulo Rechi Vita957b8df2017-07-24 14:22:25 -07001146 td->mtclass.quirks & MT_QUIRK_ASUS_CUSTOM_UP &&
1147 (usage->hid & HID_USAGE_PAGE) == HID_UP_CUSTOM) {
1148 set_bit(EV_REP, hi->input->evbit);
1149 if (field->flags & HID_MAIN_ITEM_VARIABLE)
1150 field->flags &= ~HID_MAIN_ITEM_VARIABLE;
1151 switch (usage->hid & HID_USAGE) {
1152 case 0x10: mt_map_key_clear(KEY_BRIGHTNESSDOWN); break;
1153 case 0x20: mt_map_key_clear(KEY_BRIGHTNESSUP); break;
1154 case 0x35: mt_map_key_clear(KEY_DISPLAY_OFF); break;
1155 case 0x6b: mt_map_key_clear(KEY_F21); break;
1156 case 0x6c: mt_map_key_clear(KEY_SLEEP); break;
1157 default:
1158 return -1;
1159 }
1160 return 1;
1161 }
1162
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001163 application = mt_find_application(td, field->application);
1164
João Paulo Rechi Vita957b8df2017-07-24 14:22:25 -07001165 /*
Benjamin Tissoires6aef7042014-02-28 11:41:25 -05001166 * some egalax touchscreens have "application == HID_DG_TOUCHSCREEN"
1167 * for the stylus.
Brent Adam1cc1cc92015-06-19 10:53:35 -06001168 * The check for mt_report_id ensures we don't process
1169 * HID_DG_CONTACTCOUNT from the pen report as it is outside the physical
1170 * collection, but within the report ID.
Benjamin Tissoires6aef7042014-02-28 11:41:25 -05001171 */
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001172 if (field->physical == HID_DG_STYLUS)
Benjamin Tissoirese55f6202014-02-28 11:41:24 -05001173 return 0;
Brent Adam1cc1cc92015-06-19 10:53:35 -06001174 else if ((field->physical == 0) &&
1175 (field->report->id != td->mt_report_id) &&
1176 (td->mt_report_id != -1))
1177 return 0;
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001178
Benjamin Tissoires6aef7042014-02-28 11:41:25 -05001179 if (field->application == HID_DG_TOUCHSCREEN ||
1180 field->application == HID_DG_TOUCHPAD)
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001181 return mt_touch_input_mapping(hdev, hi, field, usage, bit, max,
1182 application);
Benjamin Tissoires6aef7042014-02-28 11:41:25 -05001183
1184 /* let hid-core decide for the others */
1185 return 0;
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001186}
1187
1188static int mt_input_mapped(struct hid_device *hdev, struct hid_input *hi,
1189 struct hid_field *field, struct hid_usage *usage,
1190 unsigned long **bit, int *max)
1191{
Benjamin Tissoires6aef7042014-02-28 11:41:25 -05001192 /*
1193 * some egalax touchscreens have "application == HID_DG_TOUCHSCREEN"
1194 * for the stylus.
1195 */
Benjamin Tissoiresfa11aa72013-03-22 18:38:32 +01001196 if (field->physical == HID_DG_STYLUS)
Benjamin Tissoirese55f6202014-02-28 11:41:24 -05001197 return 0;
Benjamin Tissoiresfa11aa72013-03-22 18:38:32 +01001198
Benjamin Tissoires6aef7042014-02-28 11:41:25 -05001199 if (field->application == HID_DG_TOUCHSCREEN ||
Dmitry Torokhov4cf56a89c2017-07-11 10:02:18 -07001200 field->application == HID_DG_TOUCHPAD) {
1201 /* We own these mappings, tell hid-input to ignore them */
1202 return -1;
1203 }
Benjamin Tissoires6aef7042014-02-28 11:41:25 -05001204
1205 /* let hid-core decide for the others */
1206 return 0;
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001207}
1208
1209static int mt_event(struct hid_device *hid, struct hid_field *field,
1210 struct hid_usage *usage, __s32 value)
1211{
1212 struct mt_device *td = hid_get_drvdata(hid);
1213
1214 if (field->report->id == td->mt_report_id)
1215 return mt_touch_event(hid, field, usage, value);
1216
Benjamin Tissoirese55f6202014-02-28 11:41:24 -05001217 return 0;
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001218}
1219
1220static void mt_report(struct hid_device *hid, struct hid_report *report)
1221{
1222 struct mt_device *td = hid_get_drvdata(hid);
Benjamin Tissoirese55f6202014-02-28 11:41:24 -05001223 struct hid_field *field = report->field[0];
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001224
1225 if (!(hid->claimed & HID_CLAIMED_INPUT))
1226 return;
1227
1228 if (report->id == td->mt_report_id)
Benjamin Tissoirese55f6202014-02-28 11:41:24 -05001229 return mt_touch_report(hid, report);
Benjamin Tissoiresfa11aa72013-03-22 18:38:32 +01001230
Benjamin Tissoirese55f6202014-02-28 11:41:24 -05001231 if (field && field->hidinput && field->hidinput->input)
1232 input_sync(field->hidinput->input);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001233}
1234
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001235static bool mt_need_to_apply_feature(struct hid_device *hdev,
1236 struct hid_field *field,
Benjamin Tissoires02946f42018-04-24 10:04:37 +02001237 struct hid_usage *usage,
1238 enum latency_mode latency,
1239 bool surface_switch,
1240 bool button_switch)
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001241{
1242 struct mt_device *td = hid_get_drvdata(hdev);
Mathieu Magnaudetda10bc22014-11-22 12:02:07 +01001243 struct mt_class *cls = &td->mtclass;
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001244 struct hid_report *report = field->report;
1245 unsigned int index = usage->usage_index;
Mathieu Magnaudetda10bc22014-11-22 12:02:07 +01001246 char *buf;
Aaron Ma3064a032018-02-03 23:57:15 +08001247 u32 report_len;
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001248 int max;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001249
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001250 switch (usage->hid) {
1251 case HID_DG_INPUTMODE:
Mathieu Magnaudetda10bc22014-11-22 12:02:07 +01001252 if (cls->quirks & MT_QUIRK_FORCE_GET_FEATURE) {
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001253 report_len = hid_report_len(report);
1254 buf = hid_alloc_report_buf(report, GFP_KERNEL);
Mathieu Magnaudetda10bc22014-11-22 12:02:07 +01001255 if (!buf) {
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001256 hid_err(hdev,
1257 "failed to allocate buffer for report\n");
1258 return false;
Mathieu Magnaudetda10bc22014-11-22 12:02:07 +01001259 }
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001260 hid_hw_raw_request(hdev, report->id, buf, report_len,
Mathieu Magnaudetda10bc22014-11-22 12:02:07 +01001261 HID_FEATURE_REPORT,
1262 HID_REQ_GET_REPORT);
1263 kfree(buf);
1264 }
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001265
1266 field->value[index] = td->inputmode_value;
1267 return true;
1268
1269 case HID_DG_CONTACTMAX:
1270 if (td->mtclass.maxcontacts) {
1271 max = min_t(int, field->logical_maximum,
1272 td->mtclass.maxcontacts);
1273 if (field->value[index] != max) {
1274 field->value[index] = max;
1275 return true;
1276 }
1277 }
1278 break;
Benjamin Tissoires02946f42018-04-24 10:04:37 +02001279
1280 case HID_DG_LATENCYMODE:
1281 field->value[index] = latency;
Jiri Kosina99c703a2018-05-16 11:02:07 +02001282 return true;
Benjamin Tissoires02946f42018-04-24 10:04:37 +02001283
1284 case HID_DG_SURFACESWITCH:
1285 field->value[index] = surface_switch;
Jiri Kosina99c703a2018-05-16 11:02:07 +02001286 return true;
Benjamin Tissoires02946f42018-04-24 10:04:37 +02001287
1288 case HID_DG_BUTTONSWITCH:
1289 field->value[index] = button_switch;
Jiri Kosina99c703a2018-05-16 11:02:07 +02001290 return true;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001291 }
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001292
1293 return false; /* no need to update the report */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001294}
1295
Benjamin Tissoires02946f42018-04-24 10:04:37 +02001296static void mt_set_modes(struct hid_device *hdev, enum latency_mode latency,
1297 bool surface_switch, bool button_switch)
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +01001298{
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001299 struct hid_report_enum *rep_enum;
1300 struct hid_report *rep;
1301 struct hid_usage *usage;
1302 int i, j;
1303 bool update_report;
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +01001304
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001305 rep_enum = &hdev->report_enum[HID_FEATURE_REPORT];
1306 list_for_each_entry(rep, &rep_enum->report_list, list) {
1307 update_report = false;
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +01001308
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001309 for (i = 0; i < rep->maxfield; i++) {
1310 /* Ignore if report count is out of bounds. */
1311 if (rep->field[i]->report_count < 1)
1312 continue;
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +01001313
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001314 for (j = 0; j < rep->field[i]->maxusage; j++) {
1315 usage = &rep->field[i]->usage[j];
1316
1317 if (mt_need_to_apply_feature(hdev,
1318 rep->field[i],
Benjamin Tissoires02946f42018-04-24 10:04:37 +02001319 usage,
1320 latency,
1321 surface_switch,
1322 button_switch))
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001323 update_report = true;
1324 }
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +01001325 }
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001326
1327 if (update_report)
1328 hid_hw_request(hdev, rep, HID_REQ_SET_REPORT);
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +01001329 }
1330}
1331
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001332static void mt_post_parse_default_settings(struct mt_device *td,
1333 struct mt_application *app)
Henrik Rydberg4fa3a582012-05-01 08:40:01 +02001334{
1335 __s32 quirks = td->mtclass.quirks;
1336
1337 /* unknown serial device needs special quirks */
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001338 if (app->touches_by_report == 1) {
Henrik Rydberg4fa3a582012-05-01 08:40:01 +02001339 quirks |= MT_QUIRK_ALWAYS_VALID;
1340 quirks &= ~MT_QUIRK_NOT_SEEN_MEANS_UP;
1341 quirks &= ~MT_QUIRK_VALID_IS_INRANGE;
1342 quirks &= ~MT_QUIRK_VALID_IS_CONFIDENCE;
Benjamin Tissoirese0bb8f92013-01-31 17:22:27 +01001343 quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE;
Henrik Rydberg4fa3a582012-05-01 08:40:01 +02001344 }
1345
1346 td->mtclass.quirks = quirks;
1347}
1348
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001349static void mt_post_parse(struct mt_device *td, struct mt_application *app)
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +02001350{
1351 struct mt_fields *f = td->fields;
Benjamin Tissoiresc2517f62013-01-31 17:22:25 +01001352 struct mt_class *cls = &td->mtclass;
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +02001353
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001354 if (app->touches_by_report > 0) {
1355 int field_count_per_touch;
1356
1357 field_count_per_touch = f->length / app->touches_by_report;
1358 app->last_slot_field = f->usages[field_count_per_touch - 1];
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +02001359 }
Benjamin Tissoiresc2517f62013-01-31 17:22:25 +01001360
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001361 if (app->cc_index < 0)
Benjamin Tissoiresc2517f62013-01-31 17:22:25 +01001362 cls->quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE;
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +02001363}
1364
Dmitry Torokhovb2c68a22015-09-29 15:52:59 -07001365static int mt_input_configured(struct hid_device *hdev, struct hid_input *hi)
Henrik Rydberg76f59022012-09-01 20:11:34 +02001366{
1367 struct mt_device *td = hid_get_drvdata(hdev);
Benjamin Tissoiresc08d46a2013-07-24 19:38:05 +02001368 char *name;
1369 const char *suffix = NULL;
Benjamin Tissoires40ec2602018-04-24 10:04:35 +02001370 unsigned int application = 0;
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001371 struct mt_application *mt_application = NULL;
Benjamin Tissoires40ec2602018-04-24 10:04:35 +02001372 struct hid_report *report;
Dmitry Torokhovb2c68a22015-09-29 15:52:59 -07001373 int ret;
Henrik Rydberg76f59022012-09-01 20:11:34 +02001374
Benjamin Tissoires40ec2602018-04-24 10:04:35 +02001375 list_for_each_entry(report, &hi->reports, hidinput_list) {
1376 application = report->application;
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001377 mt_application = mt_find_application(td, application);
1378
Benjamin Tissoires40ec2602018-04-24 10:04:35 +02001379 if (report->id == td->mt_report_id) {
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001380 ret = mt_touch_input_configured(hdev, hi,
1381 mt_application);
Benjamin Tissoires40ec2602018-04-24 10:04:35 +02001382 if (ret)
1383 return ret;
1384 }
Henrik Rydberg76f59022012-09-01 20:11:34 +02001385
Benjamin Tissoires40ec2602018-04-24 10:04:35 +02001386 /*
1387 * some egalax touchscreens have "application == DG_TOUCHSCREEN"
1388 * for the stylus. Check this first, and then rely on
1389 * the application field.
1390 */
1391 if (report->field[0]->physical == HID_DG_STYLUS) {
Benjamin Tissoires6aef7042014-02-28 11:41:25 -05001392 suffix = "Pen";
1393 /* force BTN_STYLUS to allow tablet matching in udev */
1394 __set_bit(BTN_STYLUS, hi->input->keybit);
Benjamin Tissoires40ec2602018-04-24 10:04:35 +02001395 }
1396 }
1397
1398 if (!suffix) {
1399 switch (application) {
1400 case HID_GD_KEYBOARD:
1401 case HID_GD_KEYPAD:
1402 case HID_GD_MOUSE:
1403 case HID_DG_TOUCHPAD:
1404 case HID_GD_SYSTEM_CONTROL:
1405 case HID_CP_CONSUMER_CONTROL:
1406 case HID_GD_WIRELESS_RADIO_CTLS:
1407 /* already handled by hid core */
Benjamin Tissoires6aef7042014-02-28 11:41:25 -05001408 break;
1409 case HID_DG_TOUCHSCREEN:
1410 /* we do not set suffix = "Touchscreen" */
Benjamin Tissoires40ec2602018-04-24 10:04:35 +02001411 hi->input->name = hdev->name;
Benjamin Tissoires6aef7042014-02-28 11:41:25 -05001412 break;
Benjamin Tissoires40ec2602018-04-24 10:04:35 +02001413 case HID_DG_STYLUS:
1414 /* force BTN_STYLUS to allow tablet matching in udev */
1415 __set_bit(BTN_STYLUS, hi->input->keybit);
João Paulo Rechi Vita1fbf74ef2017-07-24 14:22:24 -07001416 break;
João Paulo Rechi Vita957b8df2017-07-24 14:22:25 -07001417 case HID_VD_ASUS_CUSTOM_MEDIA_KEYS:
1418 suffix = "Custom Media Keys";
1419 break;
Benjamin Tissoires6aef7042014-02-28 11:41:25 -05001420 default:
1421 suffix = "UNKNOWN";
1422 break;
1423 }
Benjamin Tissoiresc08d46a2013-07-24 19:38:05 +02001424 }
1425
1426 if (suffix) {
1427 name = devm_kzalloc(&hi->input->dev,
1428 strlen(hdev->name) + strlen(suffix) + 2,
1429 GFP_KERNEL);
1430 if (name) {
1431 sprintf(name, "%s %s", hdev->name, suffix);
1432 hi->input->name = name;
1433 }
1434 }
Dmitry Torokhovb2c68a22015-09-29 15:52:59 -07001435
1436 return 0;
Henrik Rydberg76f59022012-09-01 20:11:34 +02001437}
1438
Benjamin Tissoiresf3287a92017-01-30 10:48:06 +01001439static void mt_fix_const_field(struct hid_field *field, unsigned int usage)
1440{
1441 if (field->usage[0].hid != usage ||
1442 !(field->flags & HID_MAIN_ITEM_CONSTANT))
1443 return;
1444
1445 field->flags &= ~HID_MAIN_ITEM_CONSTANT;
1446 field->flags |= HID_MAIN_ITEM_VARIABLE;
1447}
1448
1449static void mt_fix_const_fields(struct hid_device *hdev, unsigned int usage)
1450{
1451 struct hid_report *report;
1452 int i;
1453
1454 list_for_each_entry(report,
1455 &hdev->report_enum[HID_INPUT_REPORT].report_list,
1456 list) {
1457
1458 if (!report->maxfield)
1459 continue;
1460
1461 for (i = 0; i < report->maxfield; i++)
1462 if (report->field[i]->maxusage >= 1)
1463 mt_fix_const_field(report->field[i], usage);
1464 }
1465}
1466
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +02001467static void mt_release_contacts(struct hid_device *hid)
1468{
1469 struct hid_input *hidinput;
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001470 struct mt_application *application;
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +02001471 struct mt_device *td = hid_get_drvdata(hid);
1472
1473 list_for_each_entry(hidinput, &hid->inputs, list) {
1474 struct input_dev *input_dev = hidinput->input;
1475 struct input_mt *mt = input_dev->mt;
1476 int i;
1477
1478 if (mt) {
1479 for (i = 0; i < mt->num_slots; i++) {
1480 input_mt_slot(input_dev, i);
1481 input_mt_report_slot_state(input_dev,
1482 MT_TOOL_FINGER,
1483 false);
1484 }
1485 input_mt_sync_frame(input_dev);
1486 input_sync(input_dev);
1487 }
1488 }
1489
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001490 list_for_each_entry(application, &td->applications, list) {
1491 application->num_received = 0;
1492 }
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +02001493}
1494
Kees Cook0ee32772017-10-04 17:53:24 -07001495static void mt_expired_timeout(struct timer_list *t)
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +02001496{
Kees Cook0ee32772017-10-04 17:53:24 -07001497 struct mt_device *td = from_timer(td, t, release_timer);
1498 struct hid_device *hdev = td->hdev;
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +02001499
1500 /*
1501 * An input report came in just before we release the sticky fingers,
1502 * it will take care of the sticky fingers.
1503 */
1504 if (test_and_set_bit(MT_IO_FLAGS_RUNNING, &td->mt_io_flags))
1505 return;
Benjamin Tissoires96098272017-06-15 15:32:05 +02001506 if (test_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags))
1507 mt_release_contacts(hdev);
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +02001508 clear_bit(MT_IO_FLAGS_RUNNING, &td->mt_io_flags);
1509}
1510
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001511static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
1512{
Benjamin Tissoires2d936662011-01-11 16:45:54 +01001513 int ret, i;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001514 struct mt_device *td;
Benjamin Tissoirescf6d15d2018-07-13 16:13:44 +02001515 const struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */
Benjamin Tissoires2d936662011-01-11 16:45:54 +01001516
Henrik Rydberg94b5485c2012-08-08 21:45:50 +02001517 for (i = 0; mt_classes[i].name ; i++) {
1518 if (id->driver_data == mt_classes[i].name) {
1519 mtclass = &(mt_classes[i]);
1520 break;
Benjamin Tissoires2d936662011-01-11 16:45:54 +01001521 }
1522 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001523
Benjamin Tissoiresc08d46a2013-07-24 19:38:05 +02001524 td = devm_kzalloc(&hdev->dev, sizeof(struct mt_device), GFP_KERNEL);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001525 if (!td) {
1526 dev_err(&hdev->dev, "cannot allocate multitouch data\n");
1527 return -ENOMEM;
1528 }
Kees Cook0ee32772017-10-04 17:53:24 -07001529 td->hdev = hdev;
Benjamin Tissoireseec29e32011-11-23 10:54:28 +01001530 td->mtclass = *mtclass;
Andrew Duggan9abebed2014-03-19 13:39:03 -07001531 td->inputmode_value = MT_INPUTMODE_TOUCHSCREEN;
Benjamin Tissoiresfa11aa72013-03-22 18:38:32 +01001532 td->mt_report_id = -1;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001533 hid_set_drvdata(hdev, td);
1534
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001535 INIT_LIST_HEAD(&td->applications);
1536
Benjamin Tissoiresc08d46a2013-07-24 19:38:05 +02001537 td->fields = devm_kzalloc(&hdev->dev, sizeof(struct mt_fields),
1538 GFP_KERNEL);
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +02001539 if (!td->fields) {
1540 dev_err(&hdev->dev, "cannot allocate multitouch fields data\n");
Benjamin Tissoiresc08d46a2013-07-24 19:38:05 +02001541 return -ENOMEM;
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +02001542 }
1543
Henrik Rydberg76f59022012-09-01 20:11:34 +02001544 if (id->vendor == HID_ANY_ID && id->product == HID_ANY_ID)
1545 td->serial_maybe = true;
1546
Benjamin Tissoiresb897f6d2016-11-25 14:27:22 +01001547 /* This allows the driver to correctly support devices
1548 * that emit events over several HID messages.
1549 */
1550 hdev->quirks |= HID_QUIRK_NO_INPUT_SYNC;
1551
1552 /*
1553 * This allows the driver to handle different input sensors
Benjamin Tissoires40ec2602018-04-24 10:04:35 +02001554 * that emits events through different applications on the same HID
Benjamin Tissoiresb897f6d2016-11-25 14:27:22 +01001555 * device.
1556 */
Benjamin Tissoires40ec2602018-04-24 10:04:35 +02001557 hdev->quirks |= HID_QUIRK_INPUT_PER_APP;
Benjamin Tissoiresb897f6d2016-11-25 14:27:22 +01001558
Kees Cook0ee32772017-10-04 17:53:24 -07001559 timer_setup(&td->release_timer, mt_expired_timeout, 0);
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +02001560
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001561 ret = hid_parse(hdev);
1562 if (ret != 0)
Benjamin Tissoiresc08d46a2013-07-24 19:38:05 +02001563 return ret;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001564
Benjamin Tissoiresf3287a92017-01-30 10:48:06 +01001565 if (mtclass->quirks & MT_QUIRK_FIX_CONST_CONTACT_ID)
1566 mt_fix_const_fields(hdev, HID_DG_CONTACTID);
1567
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001568 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
Benjamin Tissoires2d936662011-01-11 16:45:54 +01001569 if (ret)
Benjamin Tissoiresc08d46a2013-07-24 19:38:05 +02001570 return ret;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001571
Benjamin Tissoireseec29e32011-11-23 10:54:28 +01001572 ret = sysfs_create_group(&hdev->dev.kobj, &mt_attribute_group);
Nicholas Krause0c4b3c62016-02-04 10:52:40 -05001573 if (ret)
1574 dev_warn(&hdev->dev, "Cannot allocate sysfs group for %s\n",
1575 hdev->name);
Benjamin Tissoireseec29e32011-11-23 10:54:28 +01001576
Benjamin Tissoires02946f42018-04-24 10:04:37 +02001577 mt_set_modes(hdev, HID_LATENCY_NORMAL, true, true);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001578
Benjamin Tissoiresc08d46a2013-07-24 19:38:05 +02001579 /* release .fields memory as it is not used anymore */
1580 devm_kfree(&hdev->dev, td->fields);
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +02001581 td->fields = NULL;
1582
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001583 return 0;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001584}
1585
1586#ifdef CONFIG_PM
1587static int mt_reset_resume(struct hid_device *hdev)
1588{
Benson Leungd3e69b92016-03-11 14:19:49 -08001589 mt_release_contacts(hdev);
Benjamin Tissoires02946f42018-04-24 10:04:37 +02001590 mt_set_modes(hdev, HID_LATENCY_NORMAL, true, true);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001591 return 0;
1592}
Scott Liudfeefd12012-08-15 17:21:55 +08001593
1594static int mt_resume(struct hid_device *hdev)
1595{
Scott Liudfeefd12012-08-15 17:21:55 +08001596 /* Some Elan legacy devices require SET_IDLE to be set on resume.
1597 * It should be safe to send it to other devices too.
1598 * Tested on 3M, Stantum, Cypress, Zytronic, eGalax, and Elan panels. */
1599
Benjamin Tissoires4ba25d32013-02-27 16:38:18 +01001600 hid_hw_idle(hdev, 0, 0, HID_REQ_SET_IDLE);
Scott Liudfeefd12012-08-15 17:21:55 +08001601
1602 return 0;
1603}
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001604#endif
1605
1606static void mt_remove(struct hid_device *hdev)
1607{
Benjamin Tissoiresb897f6d2016-11-25 14:27:22 +01001608 struct mt_device *td = hid_get_drvdata(hdev);
1609
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +02001610 del_timer_sync(&td->release_timer);
1611
Benjamin Tissoireseec29e32011-11-23 10:54:28 +01001612 sysfs_remove_group(&hdev->dev.kobj, &mt_attribute_group);
Benjamin Tissoires59392122013-05-29 10:45:09 +02001613 hid_hw_stop(hdev);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001614}
1615
Benjamin Tissoires0fa9c612014-02-28 11:41:23 -05001616/*
1617 * This list contains only:
1618 * - VID/PID of products not working with the default multitouch handling
1619 * - 2 generic rules.
1620 * So there is no point in adding here any device with MT_CLS_DEFAULT.
1621 */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001622static const struct hid_device_id mt_devices[] = {
1623
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +01001624 /* 3M panels */
1625 { .driver_data = MT_CLS_3M,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001626 MT_USB_DEVICE(USB_VENDOR_ID_3M,
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +01001627 USB_DEVICE_ID_3M1968) },
1628 { .driver_data = MT_CLS_3M,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001629 MT_USB_DEVICE(USB_VENDOR_ID_3M,
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +01001630 USB_DEVICE_ID_3M2256) },
Benjamin Tissoiresc4fad872011-12-23 15:41:00 +01001631 { .driver_data = MT_CLS_3M,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001632 MT_USB_DEVICE(USB_VENDOR_ID_3M,
Benjamin Tissoiresc4fad872011-12-23 15:41:00 +01001633 USB_DEVICE_ID_3M3266) },
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +01001634
Masaki Ota504c9322017-06-16 09:29:39 +09001635 /* Alps devices */
1636 { .driver_data = MT_CLS_WIN_8_DUAL,
1637 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
1638 USB_VENDOR_ID_ALPS_JP,
1639 HID_DEVICE_ID_ALPS_U1_DUAL_PTP) },
1640 { .driver_data = MT_CLS_WIN_8_DUAL,
1641 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
1642 USB_VENDOR_ID_ALPS_JP,
1643 HID_DEVICE_ID_ALPS_U1_DUAL_3BTN_PTP) },
1644
Pavel Tatashin56d859e2017-08-25 18:06:04 -04001645 /* Lenovo X1 TAB Gen 2 */
1646 { .driver_data = MT_CLS_WIN_8_DUAL,
1647 HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8,
1648 USB_VENDOR_ID_LENOVO,
1649 USB_DEVICE_ID_LENOVO_X1_TAB) },
1650
Benjamin Tissoires6aef7042014-02-28 11:41:25 -05001651 /* Anton devices */
1652 { .driver_data = MT_CLS_EXPORT_ALL_INPUTS,
1653 MT_USB_DEVICE(USB_VENDOR_ID_ANTON,
1654 USB_DEVICE_ID_ANTON_TOUCH_PAD) },
Benjamin Tissoirese6aac342011-05-19 14:18:13 +02001655
João Paulo Rechi Vita957b8df2017-07-24 14:22:25 -07001656 /* Asus T304UA */
1657 { .driver_data = MT_CLS_ASUS,
1658 HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8,
1659 USB_VENDOR_ID_ASUSTEK,
1660 USB_DEVICE_ID_ASUSTEK_T304_KEYBOARD) },
1661
Benjamin Tissoiresb1057122011-12-23 15:40:59 +01001662 /* Atmel panels */
1663 { .driver_data = MT_CLS_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001664 MT_USB_DEVICE(USB_VENDOR_ID_ATMEL,
Benjamin Tissoires841cb152012-03-06 10:53:45 +01001665 USB_DEVICE_ID_ATMEL_MXT_DIGITIZER) },
Benjamin Tissoiresb1057122011-12-23 15:40:59 +01001666
Jiri Kosina9ed32692012-04-20 12:15:44 +02001667 /* Baanto multitouch devices */
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01001668 { .driver_data = MT_CLS_NSMU,
Jiri Kosina16b79bb2012-05-05 23:32:54 +02001669 MT_USB_DEVICE(USB_VENDOR_ID_BAANTO,
Jiri Kosina9ed32692012-04-20 12:15:44 +02001670 USB_DEVICE_ID_BAANTO_MT_190W2) },
Benjamin Tissoires0fa9c612014-02-28 11:41:23 -05001671
Benjamin Tissoiresa841b622011-03-18 14:27:54 +01001672 /* Cando panels */
1673 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001674 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
Benjamin Tissoiresa841b622011-03-18 14:27:54 +01001675 USB_DEVICE_ID_CANDO_MULTI_TOUCH) },
Benjamin Tissoiresa841b622011-03-18 14:27:54 +01001676 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001677 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
Benjamin Tissoiresa841b622011-03-18 14:27:54 +01001678 USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6) },
1679
Austin Zhang942fd422011-05-28 02:03:47 +08001680 /* Chunghwa Telecom touch panels */
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01001681 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001682 MT_USB_DEVICE(USB_VENDOR_ID_CHUNGHWAT,
Austin Zhang942fd422011-05-28 02:03:47 +08001683 USB_DEVICE_ID_CHUNGHWAT_MULTITOUCH) },
1684
Yang Bo070f63b2015-07-20 09:40:28 -07001685 /* CJTouch panels */
1686 { .driver_data = MT_CLS_NSMU,
1687 MT_USB_DEVICE(USB_VENDOR_ID_CJTOUCH,
1688 USB_DEVICE_ID_CJTOUCH_MULTI_TOUCH_0020) },
1689 { .driver_data = MT_CLS_NSMU,
1690 MT_USB_DEVICE(USB_VENDOR_ID_CJTOUCH,
1691 USB_DEVICE_ID_CJTOUCH_MULTI_TOUCH_0040) },
1692
Benjamin Tissoires79603dc2011-05-19 14:18:14 +02001693 /* CVTouch panels */
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01001694 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001695 MT_USB_DEVICE(USB_VENDOR_ID_CVTOUCH,
Benjamin Tissoires79603dc2011-05-19 14:18:14 +02001696 USB_DEVICE_ID_CVTOUCH_SCREEN) },
1697
Benjamin Tissoires22408282011-05-20 15:59:34 +02001698 /* eGalax devices (resistive) */
Benjamin Tissoirese36f6902011-11-23 10:54:31 +01001699 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001700 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +01001701 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480D) },
1702 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001703 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +01001704 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480E) },
Benjamin Tissoires22408282011-05-20 15:59:34 +02001705
1706 /* eGalax devices (capacitive) */
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +01001707 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001708 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +01001709 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7207) },
Benjamin Tissoirese36f6902011-11-23 10:54:31 +01001710 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001711 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +01001712 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_720C) },
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +01001713 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001714 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +01001715 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7224) },
Benjamin Tissoires2ce09df2012-03-06 17:57:02 +01001716 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001717 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoires2ce09df2012-03-06 17:57:02 +01001718 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_722A) },
Benjamin Tissoires22408282011-05-20 15:59:34 +02001719 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001720 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoires22408282011-05-20 15:59:34 +02001721 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_725E) },
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +01001722 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001723 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +01001724 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7262) },
Benjamin Tissoirese36f6902011-11-23 10:54:31 +01001725 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001726 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoires22408282011-05-20 15:59:34 +02001727 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_726B) },
Benjamin Tissoires22408282011-05-20 15:59:34 +02001728 { .driver_data = MT_CLS_EGALAX,
1729 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +01001730 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72A1) },
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +01001731 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001732 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +01001733 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72AA) },
Benjamin Tissoirese36f6902011-11-23 10:54:31 +01001734 { .driver_data = MT_CLS_EGALAX,
Andy Shevchenkoaa672da2013-05-17 14:34:48 +03001735 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
1736 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72C4) },
1737 { .driver_data = MT_CLS_EGALAX,
1738 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
1739 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72D0) },
1740 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001741 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoires66f06122011-11-23 10:54:33 +01001742 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72FA) },
1743 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001744 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Marek Vasutbb9ff212011-11-23 10:54:32 +01001745 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7302) },
Benjamin Tissoires1b723e82011-11-23 10:54:34 +01001746 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001747 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +01001748 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7349) },
1749 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001750 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Thierry Redingae01c9e2012-08-09 08:34:48 +02001751 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_73F7) },
1752 { .driver_data = MT_CLS_EGALAX_SERIAL,
1753 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +01001754 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_A001) },
Benjamin Tissoires22408282011-05-20 15:59:34 +02001755
Tomas Sokorai7c7606a2014-04-23 10:42:41 -04001756 /* Elitegroup panel */
1757 { .driver_data = MT_CLS_SERIAL,
1758 MT_USB_DEVICE(USB_VENDOR_ID_ELITEGROUP,
1759 USB_DEVICE_ID_ELITEGROUP_05D8) },
1760
Henrik Rydberg77723e32012-09-07 19:37:40 +02001761 /* Flatfrog Panels */
1762 { .driver_data = MT_CLS_FLATFROG,
1763 MT_USB_DEVICE(USB_VENDOR_ID_FLATFROG,
1764 USB_DEVICE_ID_MULTITOUCH_3200) },
1765
Benjamin Tissoires3db187e2014-01-23 16:33:14 -05001766 /* FocalTech Panels */
1767 { .driver_data = MT_CLS_SERIAL,
1768 MT_USB_DEVICE(USB_VENDOR_ID_CYGNAL,
1769 USB_DEVICE_ID_FOCALTECH_FTXXXX_MULTITOUCH) },
1770
Benjamin Tissoires5572da02011-01-07 23:47:27 +01001771 /* GeneralTouch panel */
Xianhan Yuf5ff4e12012-09-28 10:18:59 +08001772 { .driver_data = MT_CLS_GENERALTOUCH_TWOFINGERS,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001773 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
Benjamin Tissoires5572da02011-01-07 23:47:27 +01001774 USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS) },
Xianhan Yuf5ff4e12012-09-28 10:18:59 +08001775 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
1776 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1777 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PWT_TENFINGERS) },
Luosong7b226292013-10-02 11:20:00 +02001778 { .driver_data = MT_CLS_GENERALTOUCH_TWOFINGERS,
1779 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1780 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0101) },
1781 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
1782 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1783 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0102) },
1784 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
1785 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1786 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0106) },
1787 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
1788 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1789 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_010A) },
1790 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
1791 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1792 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_E100) },
Benjamin Tissoires5572da02011-01-07 23:47:27 +01001793
Andreas Nielsen4d5df5d2012-03-19 15:41:03 +01001794 /* Gametel game controller */
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01001795 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001796 MT_BT_DEVICE(USB_VENDOR_ID_FRUCTEL,
Andreas Nielsen4d5df5d2012-03-19 15:41:03 +01001797 USB_DEVICE_ID_GAMETEL_MT_MODE) },
1798
Benjamin Tissoiresee0fbd12011-05-19 14:18:15 +02001799 /* GoodTouch panels */
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01001800 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001801 MT_USB_DEVICE(USB_VENDOR_ID_GOODTOUCH,
Benjamin Tissoiresee0fbd12011-05-19 14:18:15 +02001802 USB_DEVICE_ID_GOODTOUCH_000f) },
1803
Benjamin Tissoires54580362011-11-29 13:13:12 +01001804 /* Hanvon panels */
1805 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001806 MT_USB_DEVICE(USB_VENDOR_ID_HANVON_ALT,
Benjamin Tissoires54580362011-11-29 13:13:12 +01001807 USB_DEVICE_ID_HANVON_ALT_MULTITOUCH) },
1808
Austin Zhang4e61f0d2011-05-09 23:54:14 +08001809 /* Ilitek dual touch panel */
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01001810 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001811 MT_USB_DEVICE(USB_VENDOR_ID_ILITEK,
Austin Zhang4e61f0d2011-05-09 23:54:14 +08001812 USB_DEVICE_ID_ILITEK_MULTITOUCH) },
1813
Benjamin Tissoiresf3287a92017-01-30 10:48:06 +01001814 /* LG Melfas panel */
1815 { .driver_data = MT_CLS_LG,
1816 HID_USB_DEVICE(USB_VENDOR_ID_LG,
1817 USB_DEVICE_ID_LG_MELFAS_MT) },
1818
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +02001819 /* MosArt panels */
1820 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001821 MT_USB_DEVICE(USB_VENDOR_ID_ASUS,
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +02001822 USB_DEVICE_ID_ASUS_T91MT)},
1823 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001824 MT_USB_DEVICE(USB_VENDOR_ID_ASUS,
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +02001825 USB_DEVICE_ID_ASUSTEK_MULTITOUCH_YFO) },
1826 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001827 MT_USB_DEVICE(USB_VENDOR_ID_TURBOX,
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +02001828 USB_DEVICE_ID_TURBOX_TOUCHSCREEN_MOSART) },
1829
Austin Hendrix4db703e2012-06-04 15:27:51 -07001830 /* Novatek Panel */
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01001831 { .driver_data = MT_CLS_NSMU,
Jiri Kosina4380d812012-06-06 16:28:33 +02001832 MT_USB_DEVICE(USB_VENDOR_ID_NOVATEK,
Austin Hendrix4db703e2012-06-04 15:27:51 -07001833 USB_DEVICE_ID_NOVATEK_PCT) },
1834
Benjamin Tissoiresa80e8032016-05-31 17:31:15 +02001835 /* Ntrig Panel */
1836 { .driver_data = MT_CLS_NSMU,
1837 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
1838 USB_VENDOR_ID_NTRIG, 0x1b05) },
1839
Hans de Goedefb55b402017-11-22 12:57:07 +01001840 /* Panasonic panels */
1841 { .driver_data = MT_CLS_PANASONIC,
1842 MT_USB_DEVICE(USB_VENDOR_ID_PANASONIC,
1843 USB_DEVICE_ID_PANABOARD_UBT780) },
1844 { .driver_data = MT_CLS_PANASONIC,
1845 MT_USB_DEVICE(USB_VENDOR_ID_PANASONIC,
1846 USB_DEVICE_ID_PANABOARD_UBT880) },
1847
Aaron Tianb7ea95f2011-12-15 11:09:06 +08001848 /* PixArt optical touch screen */
1849 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001850 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
Aaron Tianb7ea95f2011-12-15 11:09:06 +08001851 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN) },
1852 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001853 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
Aaron Tianb7ea95f2011-12-15 11:09:06 +08001854 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN1) },
1855 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001856 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
Aaron Tianb7ea95f2011-12-15 11:09:06 +08001857 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN2) },
1858
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001859 /* PixCir-based panels */
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +01001860 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001861 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001862 USB_DEVICE_ID_CANDO_PIXCIR_MULTI_TOUCH) },
1863
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +01001864 /* Quanta-based panels */
1865 { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001866 MT_USB_DEVICE(USB_VENDOR_ID_QUANTA,
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +01001867 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3001) },
Forest Bonda6802e02013-10-21 12:38:49 -04001868
Benjamin Tissoires843e4752018-03-20 12:04:46 +01001869 /* Razer touchpads */
1870 { .driver_data = MT_CLS_RAZER_BLADE_STEALTH,
1871 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
1872 USB_VENDOR_ID_SYNAPTICS, 0x8323) },
1873
Benjamin Tissoires043b4032011-03-18 14:27:53 +01001874 /* Stantum panels */
Benjamin Tissoiresbf5af9b2011-05-19 14:18:18 +02001875 { .driver_data = MT_CLS_CONFIDENCE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001876 MT_USB_DEVICE(USB_VENDOR_ID_STANTUM_STM,
Benjamin Tissoires043b4032011-03-18 14:27:53 +01001877 USB_DEVICE_ID_MTP_STM)},
Benjamin Tissoires043b4032011-03-18 14:27:53 +01001878
Benjamin Tissoires847672c2012-02-04 17:08:50 +01001879 /* TopSeed panels */
1880 { .driver_data = MT_CLS_TOPSEED,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001881 MT_USB_DEVICE(USB_VENDOR_ID_TOPSEED2,
Benjamin Tissoires847672c2012-02-04 17:08:50 +01001882 USB_DEVICE_ID_TOPSEED2_PERIPAD_701) },
1883
Benjamin Tissoires5e74e562011-05-19 14:18:16 +02001884 /* Touch International panels */
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01001885 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001886 MT_USB_DEVICE(USB_VENDOR_ID_TOUCH_INTL,
Benjamin Tissoires5e74e562011-05-19 14:18:16 +02001887 USB_DEVICE_ID_TOUCH_INTL_MULTI_TOUCH) },
1888
Benjamin Tissoires617b64f2011-05-19 14:18:17 +02001889 /* Unitec panels */
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01001890 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001891 MT_USB_DEVICE(USB_VENDOR_ID_UNITEC,
Benjamin Tissoires617b64f2011-05-19 14:18:17 +02001892 USB_DEVICE_ID_UNITEC_USB_TOUCH_0709) },
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01001893 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001894 MT_USB_DEVICE(USB_VENDOR_ID_UNITEC,
Benjamin Tissoires617b64f2011-05-19 14:18:17 +02001895 USB_DEVICE_ID_UNITEC_USB_TOUCH_0A19) },
KaiChung Chengbf9d1212013-11-21 10:04:30 +01001896
Mathieu Magnaudetda10bc22014-11-22 12:02:07 +01001897 /* VTL panels */
1898 { .driver_data = MT_CLS_VTL,
1899 MT_USB_DEVICE(USB_VENDOR_ID_VTL,
1900 USB_DEVICE_ID_VTL_MULTITOUCH_FF3F) },
1901
KaiChung Chengbf9d1212013-11-21 10:04:30 +01001902 /* Wistron panels */
1903 { .driver_data = MT_CLS_NSMU,
1904 MT_USB_DEVICE(USB_VENDOR_ID_WISTRON,
1905 USB_DEVICE_ID_WISTRON_OPTICAL_TOUCH) },
1906
ice chienbc8a2a92011-07-15 16:58:06 +08001907 /* XAT */
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01001908 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001909 MT_USB_DEVICE(USB_VENDOR_ID_XAT,
ice chienbc8a2a92011-07-15 16:58:06 +08001910 USB_DEVICE_ID_XAT_CSR) },
Benjamin Tissoires617b64f2011-05-19 14:18:17 +02001911
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001912 /* Xiroku */
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01001913 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001914 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001915 USB_DEVICE_ID_XIROKU_SPX) },
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01001916 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001917 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001918 USB_DEVICE_ID_XIROKU_MPX) },
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01001919 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001920 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001921 USB_DEVICE_ID_XIROKU_CSR) },
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01001922 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001923 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001924 USB_DEVICE_ID_XIROKU_SPX1) },
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01001925 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001926 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001927 USB_DEVICE_ID_XIROKU_MPX1) },
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01001928 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001929 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001930 USB_DEVICE_ID_XIROKU_CSR1) },
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01001931 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001932 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001933 USB_DEVICE_ID_XIROKU_SPX2) },
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01001934 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001935 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001936 USB_DEVICE_ID_XIROKU_MPX2) },
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01001937 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001938 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001939 USB_DEVICE_ID_XIROKU_CSR2) },
1940
Wei-Ning Huang0e822322017-06-21 10:43:25 +08001941 /* Google MT devices */
1942 { .driver_data = MT_CLS_GOOGLE,
1943 HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY, USB_VENDOR_ID_GOOGLE,
1944 USB_DEVICE_ID_GOOGLE_TOUCH_ROSE) },
1945
Henrik Rydberg4fa3a582012-05-01 08:40:01 +02001946 /* Generic MT device */
1947 { HID_DEVICE(HID_BUS_ANY, HID_GROUP_MULTITOUCH, HID_ANY_ID, HID_ANY_ID) },
Benjamin Tissoiresf961bd32013-08-22 14:51:08 +02001948
1949 /* Generic Win 8 certified MT device */
1950 { .driver_data = MT_CLS_WIN_8,
1951 HID_DEVICE(HID_BUS_ANY, HID_GROUP_MULTITOUCH_WIN_8,
1952 HID_ANY_ID, HID_ANY_ID) },
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001953 { }
1954};
1955MODULE_DEVICE_TABLE(hid, mt_devices);
1956
1957static const struct hid_usage_id mt_grabbed_usages[] = {
1958 { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID },
1959 { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
1960};
1961
1962static struct hid_driver mt_driver = {
1963 .name = "hid-multitouch",
1964 .id_table = mt_devices,
1965 .probe = mt_probe,
1966 .remove = mt_remove,
1967 .input_mapping = mt_input_mapping,
1968 .input_mapped = mt_input_mapped,
Henrik Rydberg76f59022012-09-01 20:11:34 +02001969 .input_configured = mt_input_configured,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001970 .feature_mapping = mt_feature_mapping,
1971 .usage_table = mt_grabbed_usages,
1972 .event = mt_event,
Benjamin Tissoires55978fa2013-01-31 17:22:24 +01001973 .report = mt_report,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001974#ifdef CONFIG_PM
1975 .reset_resume = mt_reset_resume,
Scott Liudfeefd12012-08-15 17:21:55 +08001976 .resume = mt_resume,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001977#endif
1978};
H Hartley Sweetenf4254582012-12-17 15:28:26 -07001979module_hid_driver(mt_driver);