blob: 0d190d93ca7c99ba0d98cff273e965096b194498 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01002/*
3 * HID driver for multitouch panels
4 *
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +01005 * Copyright (c) 2010-2012 Stephane Chatty <chatty@enac.fr>
Benjamin Tissoiresb0a78682013-02-25 11:31:49 +01006 * Copyright (c) 2010-2013 Benjamin Tissoires <benjamin.tissoires@gmail.com>
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +01007 * Copyright (c) 2010-2012 Ecole Nationale de l'Aviation Civile, France
Benjamin Tissoiresb0a78682013-02-25 11:31:49 +01008 * Copyright (c) 2012-2013 Red Hat, Inc
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01009 *
Richard Nauber4875ac12011-03-09 06:20:57 +010010 * This code is partly based on hid-egalax.c:
11 *
12 * Copyright (c) 2010 Stephane Chatty <chatty@enac.fr>
13 * Copyright (c) 2010 Henrik Rydberg <rydberg@euromail.se>
14 * Copyright (c) 2010 Canonical, Ltd.
15 *
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +010016 * This code is partly based on hid-3m-pct.c:
17 *
18 * Copyright (c) 2009-2010 Stephane Chatty <chatty@enac.fr>
19 * Copyright (c) 2010 Henrik Rydberg <rydberg@euromail.se>
20 * Copyright (c) 2010 Canonical, Ltd.
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010021 */
22
23/*
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010024 */
25
Benjamin Tissoiresb0a78682013-02-25 11:31:49 +010026/*
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +020027 * This driver is regularly tested thanks to the test suite in hid-tools[1].
Benjamin Tissoiresb0a78682013-02-25 11:31:49 +010028 * Please run these regression tests before patching this module so that
29 * your patch won't break existing known devices.
30 *
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +020031 * [1] https://gitlab.freedesktop.org/libevdev/hid-tools
Benjamin Tissoiresb0a78682013-02-25 11:31:49 +010032 */
33
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010034#include <linux/device.h>
35#include <linux/hid.h>
36#include <linux/module.h>
37#include <linux/slab.h>
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010038#include <linux/input/mt.h>
Nicolas Boichat29cc3092017-08-22 09:10:11 +080039#include <linux/jiffies.h>
Benjamin Tissoires49a5a822013-03-22 18:38:33 +010040#include <linux/string.h>
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +020041#include <linux/timer.h>
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010042
43
44MODULE_AUTHOR("Stephane Chatty <chatty@enac.fr>");
Benjamin Tissoiresef2fafb2011-01-31 11:28:21 +010045MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>");
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010046MODULE_DESCRIPTION("HID multitouch panels");
47MODULE_LICENSE("GPL");
48
49#include "hid-ids.h"
50
51/* quirks to control the device */
Benjamin Tissoiresfd911892017-06-15 15:32:03 +020052#define MT_QUIRK_NOT_SEEN_MEANS_UP BIT(0)
53#define MT_QUIRK_SLOT_IS_CONTACTID BIT(1)
54#define MT_QUIRK_CYPRESS BIT(2)
55#define MT_QUIRK_SLOT_IS_CONTACTNUMBER BIT(3)
56#define MT_QUIRK_ALWAYS_VALID BIT(4)
57#define MT_QUIRK_VALID_IS_INRANGE BIT(5)
58#define MT_QUIRK_VALID_IS_CONFIDENCE BIT(6)
59#define MT_QUIRK_CONFIDENCE BIT(7)
60#define MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE BIT(8)
61#define MT_QUIRK_NO_AREA BIT(9)
62#define MT_QUIRK_IGNORE_DUPLICATES BIT(10)
63#define MT_QUIRK_HOVERING BIT(11)
64#define MT_QUIRK_CONTACT_CNT_ACCURATE BIT(12)
65#define MT_QUIRK_FORCE_GET_FEATURE BIT(13)
66#define MT_QUIRK_FIX_CONST_CONTACT_ID BIT(14)
67#define MT_QUIRK_TOUCH_SIZE_SCALING BIT(15)
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +020068#define MT_QUIRK_STICKY_FINGERS BIT(16)
João Paulo Rechi Vita957b8df2017-07-24 14:22:25 -070069#define MT_QUIRK_ASUS_CUSTOM_UP BIT(17)
Benjamin Tissoiresd9c57a72018-03-20 12:04:45 +010070#define MT_QUIRK_WIN8_PTP_BUTTONS BIT(18)
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010071
Andrew Duggan9abebed2014-03-19 13:39:03 -070072#define MT_INPUTMODE_TOUCHSCREEN 0x02
73#define MT_INPUTMODE_TOUCHPAD 0x03
74
Seth Forshee2c6e0272015-03-11 17:26:41 -050075#define MT_BUTTONTYPE_CLICKPAD 0
76
Benjamin Tissoires02946f42018-04-24 10:04:37 +020077enum latency_mode {
78 HID_LATENCY_NORMAL = 0,
79 HID_LATENCY_HIGH = 1,
80};
81
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +020082#define MT_IO_FLAGS_RUNNING 0
Benjamin Tissoires96098272017-06-15 15:32:05 +020083#define MT_IO_FLAGS_ACTIVE_SLOTS 1
84#define MT_IO_FLAGS_PENDING_SLOTS 2
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +020085
Benjamin Tissoires01eaac72018-07-13 16:13:48 +020086static const bool mtrue = true; /* default for true */
87static const bool mfalse; /* default for false */
88static const __s32 mzero; /* default for 0 */
89
90#define DEFAULT_TRUE ((void *)&mtrue)
91#define DEFAULT_FALSE ((void *)&mfalse)
92#define DEFAULT_ZERO ((void *)&mzero)
93
94struct mt_usages {
95 struct list_head list;
96 __s32 *x, *y, *cx, *cy, *p, *w, *h, *a;
97 __s32 *contactid; /* the device ContactID assigned to this slot */
98 bool *tip_state; /* is the touch valid? */
99 bool *inrange_state; /* is the finger in proximity of the sensor? */
100 bool *confidence_state; /* is the touch made by a finger? */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100101};
102
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200103struct mt_application {
104 struct list_head list;
105 unsigned int application;
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200106 struct list_head mt_usages; /* mt usages list */
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +0200107
108 __s32 quirks;
109
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200110 __s32 *scantime; /* scantime reported */
111 __s32 scantime_logical_max; /* max value for raw scantime */
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200112
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200113 __s32 *raw_cc; /* contact count in the report */
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200114 int left_button_state; /* left button state */
115 unsigned int mt_flags; /* flags to pass to input-mt */
116
Dmitry Torokhov28a042a2018-07-13 16:13:54 +0200117 unsigned long *pending_palm_slots; /* slots where we reported palm
118 * and need to release */
119
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200120 __u8 num_received; /* how many contacts we received */
121 __u8 num_expected; /* expected last contact index */
122 __u8 buttons_count; /* number of physical buttons per touchpad */
123 __u8 touches_by_report; /* how many touches are present in one report:
124 * 1 means we should use a serial protocol
125 * > 1 means hybrid (multitouch) protocol
126 */
127
128 __s32 dev_time; /* the scan time provided by the device */
129 unsigned long jiffies; /* the frame's jiffies */
130 int timestamp; /* the timestamp to be sent */
131 int prev_scantime; /* scantime reported previously */
132
133 bool have_contact_count;
134};
135
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100136struct mt_class {
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100137 __s32 name; /* MT_CLS */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100138 __s32 quirks;
139 __s32 sn_move; /* Signal/noise ratio for move events */
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100140 __s32 sn_width; /* Signal/noise ratio for width events */
141 __s32 sn_height; /* Signal/noise ratio for height events */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100142 __s32 sn_pressure; /* Signal/noise ratio for pressure events */
143 __u8 maxcontacts;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100144 bool is_indirect; /* true for touchpads */
Benjamin Tissoires6aef7042014-02-28 11:41:25 -0500145 bool export_all_inputs; /* do not ignore mouse, keyboards, etc... */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100146};
147
Benjamin Tissoires8dfe14b2018-07-13 16:13:47 +0200148struct mt_report_data {
149 struct list_head list;
150 struct hid_report *report;
151 struct mt_application *application;
152 bool is_mt_collection;
153};
154
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100155struct mt_device {
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100156 struct mt_class mtclass; /* our mt device class */
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +0200157 struct timer_list release_timer; /* to release sticky fingers */
Kees Cook0ee32772017-10-04 17:53:24 -0700158 struct hid_device *hdev; /* hid_device we're attached to */
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +0200159 unsigned long mt_io_flags; /* mt flags (MT_IO_FLAGS_*) */
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +0200160 __u8 inputmode_value; /* InputMode HID feature value */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100161 __u8 maxcontacts;
Seth Forshee2c6e0272015-03-11 17:26:41 -0500162 bool is_buttonpad; /* is this device a button pad? */
Henrik Rydberg76f59022012-09-01 20:11:34 +0200163 bool serial_maybe; /* need to check for serial protocol */
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200164
165 struct list_head applications;
Benjamin Tissoires8dfe14b2018-07-13 16:13:47 +0200166 struct list_head reports;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100167};
168
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200169static void mt_post_parse_default_settings(struct mt_device *td,
170 struct mt_application *app);
171static void mt_post_parse(struct mt_device *td, struct mt_application *app);
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +0100172
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100173/* classes of device behavior */
Benjamin Tissoires22408282011-05-20 15:59:34 +0200174#define MT_CLS_DEFAULT 0x0001
175
Stephane Chattya062cc52011-09-17 22:27:30 +0200176#define MT_CLS_SERIAL 0x0002
177#define MT_CLS_CONFIDENCE 0x0003
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +0100178#define MT_CLS_CONFIDENCE_CONTACT_ID 0x0004
179#define MT_CLS_CONFIDENCE_MINUS_ONE 0x0005
180#define MT_CLS_DUAL_INRANGE_CONTACTID 0x0006
181#define MT_CLS_DUAL_INRANGE_CONTACTNUMBER 0x0007
Benjamin Tissoires0fa9c612014-02-28 11:41:23 -0500182/* reserved 0x0008 */
Aaron Tianb7ea95f2011-12-15 11:09:06 +0800183#define MT_CLS_INRANGE_CONTACTNUMBER 0x0009
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +0100184#define MT_CLS_NSMU 0x000a
Benjamin Tissoires0fa9c612014-02-28 11:41:23 -0500185/* reserved 0x0010 */
186/* reserved 0x0011 */
Benjamin Tissoiresf961bd32013-08-22 14:51:08 +0200187#define MT_CLS_WIN_8 0x0012
Benjamin Tissoires6aef7042014-02-28 11:41:25 -0500188#define MT_CLS_EXPORT_ALL_INPUTS 0x0013
Masaki Ota504c9322017-06-16 09:29:39 +0900189#define MT_CLS_WIN_8_DUAL 0x0014
Benjamin Tissoires22408282011-05-20 15:59:34 +0200190
191/* vendor specific classes */
192#define MT_CLS_3M 0x0101
Benjamin Tissoires0fa9c612014-02-28 11:41:23 -0500193/* reserved 0x0102 */
Benjamin Tissoires22408282011-05-20 15:59:34 +0200194#define MT_CLS_EGALAX 0x0103
Benjamin Tissoires1b723e82011-11-23 10:54:34 +0100195#define MT_CLS_EGALAX_SERIAL 0x0104
Benjamin Tissoires847672c2012-02-04 17:08:50 +0100196#define MT_CLS_TOPSEED 0x0105
Denis Kovalev2258e862012-02-14 00:50:33 -0800197#define MT_CLS_PANASONIC 0x0106
Henrik Rydberg77723e32012-09-07 19:37:40 +0200198#define MT_CLS_FLATFROG 0x0107
Jiri Kosinacdcd3ac2012-10-01 14:38:54 +0200199#define MT_CLS_GENERALTOUCH_TWOFINGERS 0x0108
200#define MT_CLS_GENERALTOUCH_PWT_TENFINGERS 0x0109
Benjamin Tissoiresf3287a92017-01-30 10:48:06 +0100201#define MT_CLS_LG 0x010a
João Paulo Rechi Vita957b8df2017-07-24 14:22:25 -0700202#define MT_CLS_ASUS 0x010b
Mathieu Magnaudetda10bc22014-11-22 12:02:07 +0100203#define MT_CLS_VTL 0x0110
Wei-Ning Huang0e822322017-06-21 10:43:25 +0800204#define MT_CLS_GOOGLE 0x0111
Benjamin Tissoires843e4752018-03-20 12:04:46 +0100205#define MT_CLS_RAZER_BLADE_STEALTH 0x0112
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100206
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100207#define MT_DEFAULT_MAXCONTACT 10
Benjamin Tissoiresafbcb042012-11-14 16:59:18 +0100208#define MT_MAX_MAXCONTACT 250
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100209
Nicolas Boichat29cc3092017-08-22 09:10:11 +0800210/*
211 * Resync device and local timestamps after that many microseconds without
212 * receiving data.
213 */
214#define MAX_TIMESTAMP_INTERVAL 1000000
215
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200216#define MT_USB_DEVICE(v, p) HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH, v, p)
217#define MT_BT_DEVICE(v, p) HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_MULTITOUCH, v, p)
218
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100219/*
220 * these device-dependent functions determine what slot corresponds
221 * to a valid contact that was just read.
222 */
223
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200224static int cypress_compute_slot(struct mt_application *application,
225 struct mt_usages *slot)
Benjamin Tissoiresa3b5e572011-01-07 23:46:30 +0100226{
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200227 if (*slot->contactid != 0 || application->num_received == 0)
228 return *slot->contactid;
Benjamin Tissoiresa3b5e572011-01-07 23:46:30 +0100229 else
230 return -1;
231}
232
Benjamin Tissoirescf6d15d2018-07-13 16:13:44 +0200233static const struct mt_class mt_classes[] = {
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100234 { .name = MT_CLS_DEFAULT,
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +0100235 .quirks = MT_QUIRK_ALWAYS_VALID |
236 MT_QUIRK_CONTACT_CNT_ACCURATE },
237 { .name = MT_CLS_NSMU,
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100238 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP },
Stephane Chattya062cc52011-09-17 22:27:30 +0200239 { .name = MT_CLS_SERIAL,
240 .quirks = MT_QUIRK_ALWAYS_VALID},
Benjamin Tissoires22408282011-05-20 15:59:34 +0200241 { .name = MT_CLS_CONFIDENCE,
242 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE },
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +0100243 { .name = MT_CLS_CONFIDENCE_CONTACT_ID,
244 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
245 MT_QUIRK_SLOT_IS_CONTACTID },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200246 { .name = MT_CLS_CONFIDENCE_MINUS_ONE,
247 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
248 MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE },
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +0100249 { .name = MT_CLS_DUAL_INRANGE_CONTACTID,
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100250 .quirks = MT_QUIRK_VALID_IS_INRANGE |
251 MT_QUIRK_SLOT_IS_CONTACTID,
252 .maxcontacts = 2 },
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +0100253 { .name = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100254 .quirks = MT_QUIRK_VALID_IS_INRANGE |
255 MT_QUIRK_SLOT_IS_CONTACTNUMBER,
256 .maxcontacts = 2 },
Aaron Tianb7ea95f2011-12-15 11:09:06 +0800257 { .name = MT_CLS_INRANGE_CONTACTNUMBER,
258 .quirks = MT_QUIRK_VALID_IS_INRANGE |
259 MT_QUIRK_SLOT_IS_CONTACTNUMBER },
Benjamin Tissoiresf961bd32013-08-22 14:51:08 +0200260 { .name = MT_CLS_WIN_8,
261 .quirks = MT_QUIRK_ALWAYS_VALID |
262 MT_QUIRK_IGNORE_DUPLICATES |
263 MT_QUIRK_HOVERING |
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +0200264 MT_QUIRK_CONTACT_CNT_ACCURATE |
Benjamin Tissoiresd9c57a72018-03-20 12:04:45 +0100265 MT_QUIRK_STICKY_FINGERS |
Benjamin Tissoiresc23e2042019-08-12 18:23:25 +0200266 MT_QUIRK_WIN8_PTP_BUTTONS,
267 .export_all_inputs = true },
Benjamin Tissoires6aef7042014-02-28 11:41:25 -0500268 { .name = MT_CLS_EXPORT_ALL_INPUTS,
269 .quirks = MT_QUIRK_ALWAYS_VALID |
270 MT_QUIRK_CONTACT_CNT_ACCURATE,
271 .export_all_inputs = true },
Masaki Ota504c9322017-06-16 09:29:39 +0900272 { .name = MT_CLS_WIN_8_DUAL,
273 .quirks = MT_QUIRK_ALWAYS_VALID |
274 MT_QUIRK_IGNORE_DUPLICATES |
275 MT_QUIRK_HOVERING |
Benjamin Tissoiresd9c57a72018-03-20 12:04:45 +0100276 MT_QUIRK_CONTACT_CNT_ACCURATE |
277 MT_QUIRK_WIN8_PTP_BUTTONS,
Masaki Ota504c9322017-06-16 09:29:39 +0900278 .export_all_inputs = true },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200279
280 /*
281 * vendor specific classes
282 */
283 { .name = MT_CLS_3M,
284 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
HungNien Chene9d0a262017-03-06 11:30:14 +0800285 MT_QUIRK_SLOT_IS_CONTACTID |
286 MT_QUIRK_TOUCH_SIZE_SCALING,
Benjamin Tissoires22408282011-05-20 15:59:34 +0200287 .sn_move = 2048,
288 .sn_width = 128,
Henrik Rydbergc5d40be2012-09-05 16:58:12 +0200289 .sn_height = 128,
290 .maxcontacts = 60,
291 },
Richard Nauber4875ac12011-03-09 06:20:57 +0100292 { .name = MT_CLS_EGALAX,
293 .quirks = MT_QUIRK_SLOT_IS_CONTACTID |
Benjamin Tissoires2261bb92011-11-23 10:54:29 +0100294 MT_QUIRK_VALID_IS_INRANGE,
Richard Nauber4875ac12011-03-09 06:20:57 +0100295 .sn_move = 4096,
296 .sn_pressure = 32,
297 },
Benjamin Tissoires1b723e82011-11-23 10:54:34 +0100298 { .name = MT_CLS_EGALAX_SERIAL,
299 .quirks = MT_QUIRK_SLOT_IS_CONTACTID |
300 MT_QUIRK_ALWAYS_VALID,
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100301 .sn_move = 4096,
302 .sn_pressure = 32,
303 },
Benjamin Tissoires847672c2012-02-04 17:08:50 +0100304 { .name = MT_CLS_TOPSEED,
305 .quirks = MT_QUIRK_ALWAYS_VALID,
306 .is_indirect = true,
307 .maxcontacts = 2,
308 },
Denis Kovalev2258e862012-02-14 00:50:33 -0800309 { .name = MT_CLS_PANASONIC,
310 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP,
311 .maxcontacts = 4 },
Xianhan Yuf5ff4e12012-09-28 10:18:59 +0800312 { .name = MT_CLS_GENERALTOUCH_TWOFINGERS,
313 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
314 MT_QUIRK_VALID_IS_INRANGE |
Luosong7b226292013-10-02 11:20:00 +0200315 MT_QUIRK_SLOT_IS_CONTACTID,
Xianhan Yuf5ff4e12012-09-28 10:18:59 +0800316 .maxcontacts = 2
317 },
318 { .name = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
319 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
Luosong7b226292013-10-02 11:20:00 +0200320 MT_QUIRK_SLOT_IS_CONTACTID
Xianhan Yuf5ff4e12012-09-28 10:18:59 +0800321 },
Benjamin Tissoires043b4032011-03-18 14:27:53 +0100322
Henrik Rydberg77723e32012-09-07 19:37:40 +0200323 { .name = MT_CLS_FLATFROG,
324 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
325 MT_QUIRK_NO_AREA,
326 .sn_move = 2048,
327 .maxcontacts = 40,
328 },
Benjamin Tissoiresf3287a92017-01-30 10:48:06 +0100329 { .name = MT_CLS_LG,
330 .quirks = MT_QUIRK_ALWAYS_VALID |
331 MT_QUIRK_FIX_CONST_CONTACT_ID |
332 MT_QUIRK_IGNORE_DUPLICATES |
333 MT_QUIRK_HOVERING |
334 MT_QUIRK_CONTACT_CNT_ACCURATE },
João Paulo Rechi Vita957b8df2017-07-24 14:22:25 -0700335 { .name = MT_CLS_ASUS,
336 .quirks = MT_QUIRK_ALWAYS_VALID |
337 MT_QUIRK_CONTACT_CNT_ACCURATE |
338 MT_QUIRK_ASUS_CUSTOM_UP },
Mathieu Magnaudetda10bc22014-11-22 12:02:07 +0100339 { .name = MT_CLS_VTL,
340 .quirks = MT_QUIRK_ALWAYS_VALID |
341 MT_QUIRK_CONTACT_CNT_ACCURATE |
342 MT_QUIRK_FORCE_GET_FEATURE,
343 },
Wei-Ning Huang0e822322017-06-21 10:43:25 +0800344 { .name = MT_CLS_GOOGLE,
345 .quirks = MT_QUIRK_ALWAYS_VALID |
346 MT_QUIRK_CONTACT_CNT_ACCURATE |
347 MT_QUIRK_SLOT_IS_CONTACTID |
348 MT_QUIRK_HOVERING
349 },
Benjamin Tissoires843e4752018-03-20 12:04:46 +0100350 { .name = MT_CLS_RAZER_BLADE_STEALTH,
351 .quirks = MT_QUIRK_ALWAYS_VALID |
352 MT_QUIRK_IGNORE_DUPLICATES |
353 MT_QUIRK_HOVERING |
354 MT_QUIRK_CONTACT_CNT_ACCURATE |
355 MT_QUIRK_WIN8_PTP_BUTTONS,
356 },
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100357 { }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100358};
359
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100360static ssize_t mt_show_quirks(struct device *dev,
361 struct device_attribute *attr,
362 char *buf)
363{
Geliang Tangee79a8f2015-12-27 17:25:21 +0800364 struct hid_device *hdev = to_hid_device(dev);
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100365 struct mt_device *td = hid_get_drvdata(hdev);
366
367 return sprintf(buf, "%u\n", td->mtclass.quirks);
368}
369
370static ssize_t mt_set_quirks(struct device *dev,
371 struct device_attribute *attr,
372 const char *buf, size_t count)
373{
Geliang Tangee79a8f2015-12-27 17:25:21 +0800374 struct hid_device *hdev = to_hid_device(dev);
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100375 struct mt_device *td = hid_get_drvdata(hdev);
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200376 struct mt_application *application;
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100377
378 unsigned long val;
379
380 if (kstrtoul(buf, 0, &val))
381 return -EINVAL;
382
383 td->mtclass.quirks = val;
384
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200385 list_for_each_entry(application, &td->applications, list) {
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +0200386 application->quirks = val;
387 if (!application->have_contact_count)
388 application->quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE;
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200389 }
390
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100391 return count;
392}
393
394static DEVICE_ATTR(quirks, S_IWUSR | S_IRUGO, mt_show_quirks, mt_set_quirks);
395
396static struct attribute *sysfs_attrs[] = {
397 &dev_attr_quirks.attr,
398 NULL
399};
400
Arvind Yadav9182fb92017-08-03 16:56:43 +0530401static const struct attribute_group mt_attribute_group = {
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100402 .attrs = sysfs_attrs
403};
404
Mika Westerberg6d4f5442015-10-07 15:33:43 +0300405static void mt_get_feature(struct hid_device *hdev, struct hid_report *report)
406{
Aaron Ma3064a032018-02-03 23:57:15 +0800407 int ret;
408 u32 size = hid_report_len(report);
Mika Westerberg6d4f5442015-10-07 15:33:43 +0300409 u8 *buf;
410
411 /*
Benjamin Tissoiresb897f6d2016-11-25 14:27:22 +0100412 * Do not fetch the feature report if the device has been explicitly
413 * marked as non-capable.
Mika Westerberg6d4f5442015-10-07 15:33:43 +0300414 */
Benjamin Tissoiresadaabbf2018-03-20 12:04:50 +0100415 if (hdev->quirks & HID_QUIRK_NO_INIT_REPORTS)
Mika Westerberg6d4f5442015-10-07 15:33:43 +0300416 return;
417
418 buf = hid_alloc_report_buf(report, GFP_KERNEL);
419 if (!buf)
420 return;
421
422 ret = hid_hw_raw_request(hdev, report->id, buf, size,
423 HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
424 if (ret < 0) {
425 dev_warn(&hdev->dev, "failed to fetch feature %d\n",
426 report->id);
427 } else {
428 ret = hid_report_raw_event(hdev, HID_FEATURE_REPORT, buf,
429 size, 0);
430 if (ret)
431 dev_warn(&hdev->dev, "failed to report feature\n");
432 }
433
434 kfree(buf);
435}
436
Henrik Rydbergf635bd12011-02-24 19:30:59 +0100437static void mt_feature_mapping(struct hid_device *hdev,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100438 struct hid_field *field, struct hid_usage *usage)
439{
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100440 struct mt_device *td = hid_get_drvdata(hdev);
441
442 switch (usage->hid) {
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100443 case HID_DG_CONTACTMAX:
Mika Westerberg6d4f5442015-10-07 15:33:43 +0300444 mt_get_feature(hdev, field->report);
445
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100446 td->maxcontacts = field->value[0];
Benjamin Tissoiresafbcb042012-11-14 16:59:18 +0100447 if (!td->maxcontacts &&
448 field->logical_maximum <= MT_MAX_MAXCONTACT)
449 td->maxcontacts = field->logical_maximum;
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100450 if (td->mtclass.maxcontacts)
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100451 /* check if the maxcontacts is given by the class */
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100452 td->maxcontacts = td->mtclass.maxcontacts;
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100453
454 break;
Seth Forshee2c6e0272015-03-11 17:26:41 -0500455 case HID_DG_BUTTONTYPE:
456 if (usage->usage_index >= field->report_count) {
457 dev_err(&hdev->dev, "HID_DG_BUTTONTYPE out of range\n");
458 break;
459 }
460
Mika Westerberg6d4f5442015-10-07 15:33:43 +0300461 mt_get_feature(hdev, field->report);
Seth Forshee2c6e0272015-03-11 17:26:41 -0500462 if (field->value[usage->usage_index] == MT_BUTTONTYPE_CLICKPAD)
463 td->is_buttonpad = true;
464
465 break;
Benjamin Tissoires45c5c682016-03-07 11:02:38 +0100466 case 0xff0000c5:
467 /* Retrieve the Win8 blob once to enable some devices */
468 if (usage->usage_index == 0)
469 mt_get_feature(hdev, field->report);
470 break;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100471 }
472}
473
474static void set_abs(struct input_dev *input, unsigned int code,
475 struct hid_field *field, int snratio)
476{
477 int fmin = field->logical_minimum;
478 int fmax = field->logical_maximum;
479 int fuzz = snratio ? (fmax - fmin) / snratio : 0;
480 input_set_abs_params(input, code, fmin, fmax, fuzz, 0);
Benjamin Tissoires37cf6e62012-11-14 16:59:13 +0100481 input_abs_set_res(input, code, hidinput_calc_abs_res(field, code));
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100482}
483
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200484static struct mt_usages *mt_allocate_usage(struct hid_device *hdev,
485 struct mt_application *application)
486{
487 struct mt_usages *usage;
488
489 usage = devm_kzalloc(&hdev->dev, sizeof(*usage), GFP_KERNEL);
490 if (!usage)
491 return NULL;
492
493 /* set some defaults so we do not need to check for null pointers */
494 usage->x = DEFAULT_ZERO;
495 usage->y = DEFAULT_ZERO;
496 usage->cx = DEFAULT_ZERO;
497 usage->cy = DEFAULT_ZERO;
498 usage->p = DEFAULT_ZERO;
499 usage->w = DEFAULT_ZERO;
500 usage->h = DEFAULT_ZERO;
501 usage->a = DEFAULT_ZERO;
502 usage->contactid = DEFAULT_ZERO;
503 usage->tip_state = DEFAULT_FALSE;
504 usage->inrange_state = DEFAULT_FALSE;
505 usage->confidence_state = DEFAULT_TRUE;
506
507 list_add_tail(&usage->list, &application->mt_usages);
508
509 return usage;
510}
511
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200512static struct mt_application *mt_allocate_application(struct mt_device *td,
513 unsigned int application)
514{
515 struct mt_application *mt_application;
516
517 mt_application = devm_kzalloc(&td->hdev->dev, sizeof(*mt_application),
518 GFP_KERNEL);
519 if (!mt_application)
520 return NULL;
521
522 mt_application->application = application;
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200523 INIT_LIST_HEAD(&mt_application->mt_usages);
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200524
525 if (application == HID_DG_TOUCHSCREEN)
526 mt_application->mt_flags |= INPUT_MT_DIRECT;
527
528 /*
529 * Model touchscreens providing buttons as touchpads.
530 */
531 if (application == HID_DG_TOUCHPAD) {
532 mt_application->mt_flags |= INPUT_MT_POINTER;
533 td->inputmode_value = MT_INPUTMODE_TOUCHPAD;
534 }
535
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200536 mt_application->scantime = DEFAULT_ZERO;
537 mt_application->raw_cc = DEFAULT_ZERO;
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +0200538 mt_application->quirks = td->mtclass.quirks;
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200539
540 list_add_tail(&mt_application->list, &td->applications);
541
542 return mt_application;
543}
544
545static struct mt_application *mt_find_application(struct mt_device *td,
546 unsigned int application)
547{
548 struct mt_application *tmp, *mt_application = NULL;
549
550 list_for_each_entry(tmp, &td->applications, list) {
551 if (application == tmp->application) {
552 mt_application = tmp;
553 break;
554 }
555 }
556
557 if (!mt_application)
558 mt_application = mt_allocate_application(td, application);
559
560 return mt_application;
561}
562
Benjamin Tissoires8dfe14b2018-07-13 16:13:47 +0200563static struct mt_report_data *mt_allocate_report_data(struct mt_device *td,
564 struct hid_report *report)
565{
566 struct mt_report_data *rdata;
567 struct hid_field *field;
568 int r, n;
569
570 rdata = devm_kzalloc(&td->hdev->dev, sizeof(*rdata), GFP_KERNEL);
571 if (!rdata)
572 return NULL;
573
574 rdata->report = report;
575 rdata->application = mt_find_application(td, report->application);
576
577 if (!rdata->application) {
578 devm_kfree(&td->hdev->dev, rdata);
579 return NULL;
580 }
581
582 for (r = 0; r < report->maxfield; r++) {
583 field = report->field[r];
584
585 if (!(HID_MAIN_ITEM_VARIABLE & field->flags))
586 continue;
587
588 for (n = 0; n < field->report_count; n++) {
589 if (field->usage[n].hid == HID_DG_CONTACTID)
590 rdata->is_mt_collection = true;
591 }
592 }
593
594 list_add_tail(&rdata->list, &td->reports);
595
596 return rdata;
597}
598
599static struct mt_report_data *mt_find_report_data(struct mt_device *td,
600 struct hid_report *report)
601{
602 struct mt_report_data *tmp, *rdata = NULL;
603
604 list_for_each_entry(tmp, &td->reports, list) {
605 if (report == tmp->report) {
606 rdata = tmp;
607 break;
608 }
609 }
610
611 if (!rdata)
612 rdata = mt_allocate_report_data(td, report);
613
614 return rdata;
615}
616
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200617static void mt_store_field(struct hid_device *hdev,
618 struct mt_application *application,
619 __s32 *value,
620 size_t offset)
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100621{
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200622 struct mt_usages *usage;
623 __s32 **target;
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200624
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200625 if (list_empty(&application->mt_usages))
626 usage = mt_allocate_usage(hdev, application);
627 else
628 usage = list_last_entry(&application->mt_usages,
629 struct mt_usages,
630 list);
631
632 if (!usage)
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200633 return;
634
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200635 target = (__s32 **)((char *)usage + offset);
636
637 /* the value has already been filled, create a new slot */
638 if (*target != DEFAULT_TRUE &&
639 *target != DEFAULT_FALSE &&
640 *target != DEFAULT_ZERO) {
Benjamin Tissoires81bcbad2019-05-21 15:38:31 +0200641 if (usage->contactid == DEFAULT_ZERO ||
642 usage->x == DEFAULT_ZERO ||
643 usage->y == DEFAULT_ZERO) {
644 hid_dbg(hdev,
645 "ignoring duplicate usage on incomplete");
646 return;
647 }
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200648 usage = mt_allocate_usage(hdev, application);
649 if (!usage)
650 return;
651
652 target = (__s32 **)((char *)usage + offset);
653 }
654
655 *target = value;
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100656}
657
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200658#define MT_STORE_FIELD(__name) \
659 mt_store_field(hdev, app, \
660 &field->value[usage->usage_index], \
661 offsetof(struct mt_usages, __name))
662
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +0100663static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100664 struct hid_field *field, struct hid_usage *usage,
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200665 unsigned long **bit, int *max, struct mt_application *app)
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100666{
667 struct mt_device *td = hid_get_drvdata(hdev);
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100668 struct mt_class *cls = &td->mtclass;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100669 int code;
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100670 struct hid_usage *prev_usage = NULL;
Richard Nauber4875ac12011-03-09 06:20:57 +0100671
Henrik Rydberg76f59022012-09-01 20:11:34 +0200672 /*
673 * Model touchscreens providing buttons as touchpads.
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100674 */
Benjamin Tissoiresba6b0552018-07-13 16:13:49 +0200675 if (field->application == HID_DG_TOUCHSCREEN &&
676 (usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON) {
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200677 app->mt_flags |= INPUT_MT_POINTER;
Andrew Duggan9abebed2014-03-19 13:39:03 -0700678 td->inputmode_value = MT_INPUTMODE_TOUCHPAD;
679 }
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100680
Benjamin Tissoires015fdaa2015-03-06 11:14:42 -0500681 /* count the buttons on touchpads */
682 if ((usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON)
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200683 app->buttons_count++;
Benjamin Tissoires015fdaa2015-03-06 11:14:42 -0500684
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100685 if (usage->usage_index)
686 prev_usage = &field->usage[usage->usage_index - 1];
687
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100688 switch (usage->hid & HID_USAGE_PAGE) {
689
690 case HID_UP_GENDESK:
691 switch (usage->hid) {
692 case HID_GD_X:
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200693 if (prev_usage && (prev_usage->hid == usage->hid)) {
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200694 code = ABS_MT_TOOL_X;
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200695 MT_STORE_FIELD(cx);
696 } else {
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200697 code = ABS_MT_POSITION_X;
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200698 MT_STORE_FIELD(x);
699 }
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100700
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200701 set_abs(hi->input, code, field, cls->sn_move);
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200702
Benjamin Tissoiresba6b0552018-07-13 16:13:49 +0200703 /*
704 * A system multi-axis that exports X and Y has a high
705 * chance of being used directly on a surface
706 */
707 if (field->application == HID_GD_SYSTEM_MULTIAXIS) {
708 __set_bit(INPUT_PROP_DIRECT,
709 hi->input->propbit);
710 input_set_abs_params(hi->input,
711 ABS_MT_TOOL_TYPE,
712 MT_TOOL_DIAL,
713 MT_TOOL_DIAL, 0, 0);
714 }
715
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100716 return 1;
717 case HID_GD_Y:
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200718 if (prev_usage && (prev_usage->hid == usage->hid)) {
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200719 code = ABS_MT_TOOL_Y;
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200720 MT_STORE_FIELD(cy);
721 } else {
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200722 code = ABS_MT_POSITION_Y;
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200723 MT_STORE_FIELD(y);
724 }
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100725
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200726 set_abs(hi->input, code, field, cls->sn_move);
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200727
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100728 return 1;
729 }
730 return 0;
731
732 case HID_UP_DIGITIZER:
733 switch (usage->hid) {
734 case HID_DG_INRANGE:
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +0200735 if (app->quirks & MT_QUIRK_HOVERING) {
Benjamin Tissoires9b3bb9b82012-11-14 16:59:24 +0100736 input_set_abs_params(hi->input,
737 ABS_MT_DISTANCE, 0, 1, 0, 0);
738 }
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200739 MT_STORE_FIELD(inrange_state);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100740 return 1;
741 case HID_DG_CONFIDENCE:
Masaki Ota504c9322017-06-16 09:29:39 +0900742 if ((cls->name == MT_CLS_WIN_8 ||
743 cls->name == MT_CLS_WIN_8_DUAL) &&
Dmitry Torokhovf9024372018-07-13 16:13:53 +0200744 (field->application == HID_DG_TOUCHPAD ||
745 field->application == HID_DG_TOUCHSCREEN))
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +0200746 app->quirks |= MT_QUIRK_CONFIDENCE;
Dmitry Torokhov9152c7d2018-07-13 16:13:52 +0200747
748 if (app->quirks & MT_QUIRK_CONFIDENCE)
749 input_set_abs_params(hi->input,
750 ABS_MT_TOOL_TYPE,
751 MT_TOOL_FINGER,
752 MT_TOOL_PALM, 0, 0);
753
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200754 MT_STORE_FIELD(confidence_state);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100755 return 1;
756 case HID_DG_TIPSWITCH:
Benjamin Tissoiresba6b0552018-07-13 16:13:49 +0200757 if (field->application != HID_GD_SYSTEM_MULTIAXIS)
758 input_set_capability(hi->input,
759 EV_KEY, BTN_TOUCH);
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200760 MT_STORE_FIELD(tip_state);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100761 return 1;
762 case HID_DG_CONTACTID:
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200763 MT_STORE_FIELD(contactid);
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200764 app->touches_by_report++;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100765 return 1;
766 case HID_DG_WIDTH:
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +0200767 if (!(app->quirks & MT_QUIRK_NO_AREA))
Henrik Rydberg77723e32012-09-07 19:37:40 +0200768 set_abs(hi->input, ABS_MT_TOUCH_MAJOR, field,
769 cls->sn_width);
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200770 MT_STORE_FIELD(w);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100771 return 1;
772 case HID_DG_HEIGHT:
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +0200773 if (!(app->quirks & MT_QUIRK_NO_AREA)) {
Henrik Rydberg77723e32012-09-07 19:37:40 +0200774 set_abs(hi->input, ABS_MT_TOUCH_MINOR, field,
775 cls->sn_height);
Wei-Ning Huang00720272017-10-12 14:21:43 +0800776
777 /*
778 * Only set ABS_MT_ORIENTATION if it is not
779 * already set by the HID_DG_AZIMUTH usage.
780 */
781 if (!test_bit(ABS_MT_ORIENTATION,
782 hi->input->absbit))
783 input_set_abs_params(hi->input,
784 ABS_MT_ORIENTATION, 0, 1, 0, 0);
Henrik Rydberg77723e32012-09-07 19:37:40 +0200785 }
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200786 MT_STORE_FIELD(h);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100787 return 1;
788 case HID_DG_TIPPRESSURE:
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100789 set_abs(hi->input, ABS_MT_PRESSURE, field,
790 cls->sn_pressure);
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200791 MT_STORE_FIELD(p);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100792 return 1;
Nicolas Boichat29cc3092017-08-22 09:10:11 +0800793 case HID_DG_SCANTIME:
Nicolas Boichat29cc3092017-08-22 09:10:11 +0800794 input_set_capability(hi->input, EV_MSC, MSC_TIMESTAMP);
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200795 app->scantime = &field->value[usage->usage_index];
796 app->scantime_logical_max = field->logical_maximum;
Nicolas Boichat29cc3092017-08-22 09:10:11 +0800797 return 1;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100798 case HID_DG_CONTACTCOUNT:
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200799 app->have_contact_count = true;
800 app->raw_cc = &field->value[usage->usage_index];
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100801 return 1;
Wei-Ning Huang00720272017-10-12 14:21:43 +0800802 case HID_DG_AZIMUTH:
Wei-Ning Huang00720272017-10-12 14:21:43 +0800803 /*
804 * Azimuth has the range of [0, MAX) representing a full
805 * revolution. Set ABS_MT_ORIENTATION to a quarter of
806 * MAX according the definition of ABS_MT_ORIENTATION
807 */
808 input_set_abs_params(hi->input, ABS_MT_ORIENTATION,
809 -field->logical_maximum / 4,
810 field->logical_maximum / 4,
811 cls->sn_move ?
812 field->logical_maximum / cls->sn_move : 0, 0);
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200813 MT_STORE_FIELD(a);
Wei-Ning Huang00720272017-10-12 14:21:43 +0800814 return 1;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100815 case HID_DG_CONTACTMAX:
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200816 /* contact max are global to the report */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100817 return -1;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100818 case HID_DG_TOUCH:
819 /* Legacy devices use TIPSWITCH and not TOUCH.
820 * Let's just ignore this field. */
821 return -1;
Alan Cox65b258e2012-10-25 15:35:25 +0100822 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100823 /* let hid-input decide for the others */
824 return 0;
825
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100826 case HID_UP_BUTTON:
827 code = BTN_MOUSE + ((usage->hid - 1) & HID_USAGE);
Benjamin Tissoires594312b2016-11-25 11:08:10 +0100828 /*
829 * MS PTP spec says that external buttons left and right have
830 * usages 2 and 3.
831 */
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +0200832 if ((app->quirks & MT_QUIRK_WIN8_PTP_BUTTONS) &&
Benjamin Tissoires594312b2016-11-25 11:08:10 +0100833 field->application == HID_DG_TOUCHPAD &&
834 (usage->hid & HID_USAGE) > 1)
835 code--;
Benjamin Tissoiresba6b0552018-07-13 16:13:49 +0200836
837 if (field->application == HID_GD_SYSTEM_MULTIAXIS)
838 code = BTN_0 + ((usage->hid - 1) & HID_USAGE);
839
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100840 hid_map_usage(hi, usage, bit, max, EV_KEY, code);
841 input_set_capability(hi->input, EV_KEY, code);
842 return 1;
843
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100844 case 0xff000000:
845 /* we do not want to map these: no input-oriented meaning */
846 return -1;
847 }
848
849 return 0;
850}
851
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200852static int mt_compute_slot(struct mt_device *td, struct mt_application *app,
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200853 struct mt_usages *slot,
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200854 struct input_dev *input)
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100855{
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +0200856 __s32 quirks = app->quirks;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100857
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100858 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID)
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200859 return *slot->contactid;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100860
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100861 if (quirks & MT_QUIRK_CYPRESS)
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200862 return cypress_compute_slot(app, slot);
Benjamin Tissoiresa3b5e572011-01-07 23:46:30 +0100863
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100864 if (quirks & MT_QUIRK_SLOT_IS_CONTACTNUMBER)
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200865 return app->num_received;
Benjamin Tissoires5572da02011-01-07 23:47:27 +0100866
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +0200867 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE)
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200868 return *slot->contactid - 1;
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +0200869
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200870 return input_mt_get_slot_by_key(input, *slot->contactid);
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200871}
872
Dmitry Torokhov28a042a2018-07-13 16:13:54 +0200873static void mt_release_pending_palms(struct mt_device *td,
874 struct mt_application *app,
875 struct input_dev *input)
876{
877 int slotnum;
878 bool need_sync = false;
879
880 for_each_set_bit(slotnum, app->pending_palm_slots, td->maxcontacts) {
881 clear_bit(slotnum, app->pending_palm_slots);
882
883 input_mt_slot(input, slotnum);
884 input_mt_report_slot_state(input, MT_TOOL_PALM, false);
885
886 need_sync = true;
887 }
888
889 if (need_sync) {
890 input_mt_sync_frame(input);
891 input_sync(input);
892 }
893}
894
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200895/*
896 * this function is called when a whole packet has been received and processed,
897 * so that it can decide what to send to the input layer.
898 */
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200899static void mt_sync_frame(struct mt_device *td, struct mt_application *app,
900 struct input_dev *input)
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200901{
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +0200902 if (app->quirks & MT_QUIRK_WIN8_PTP_BUTTONS)
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200903 input_event(input, EV_KEY, BTN_LEFT, app->left_button_state);
Hans de Goede127e71b2017-11-22 12:57:10 +0100904
Henrik Rydberg76f59022012-09-01 20:11:34 +0200905 input_mt_sync_frame(input);
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200906 input_event(input, EV_MSC, MSC_TIMESTAMP, app->timestamp);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100907 input_sync(input);
Dmitry Torokhov28a042a2018-07-13 16:13:54 +0200908
909 mt_release_pending_palms(td, app, input);
910
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200911 app->num_received = 0;
912 app->left_button_state = 0;
913
Benjamin Tissoires96098272017-06-15 15:32:05 +0200914 if (test_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags))
915 set_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags);
916 else
917 clear_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags);
918 clear_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100919}
920
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200921static int mt_compute_timestamp(struct mt_application *app, __s32 value)
Nicolas Boichat29cc3092017-08-22 09:10:11 +0800922{
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200923 long delta = value - app->prev_scantime;
924 unsigned long jdelta = jiffies_to_usecs(jiffies - app->jiffies);
Nicolas Boichat29cc3092017-08-22 09:10:11 +0800925
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200926 app->jiffies = jiffies;
Nicolas Boichat29cc3092017-08-22 09:10:11 +0800927
928 if (delta < 0)
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200929 delta += app->scantime_logical_max;
Nicolas Boichat29cc3092017-08-22 09:10:11 +0800930
931 /* HID_DG_SCANTIME is expressed in 100us, we want it in us. */
932 delta *= 100;
933
934 if (jdelta > MAX_TIMESTAMP_INTERVAL)
935 /* No data received for a while, resync the timestamp. */
936 return 0;
937 else
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200938 return app->timestamp + delta;
Nicolas Boichat29cc3092017-08-22 09:10:11 +0800939}
940
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +0100941static int mt_touch_event(struct hid_device *hid, struct hid_field *field,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100942 struct hid_usage *usage, __s32 value)
943{
Benjamin Tissoires55978fa2013-01-31 17:22:24 +0100944 /* we will handle the hidinput part later, now remains hiddev */
945 if (hid->claimed & HID_CLAIMED_HIDDEV && hid->hiddev_hid_event)
946 hid->hiddev_hid_event(hid, field, usage, value);
947
948 return 1;
949}
950
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200951static int mt_process_slot(struct mt_device *td, struct input_dev *input,
952 struct mt_application *app,
953 struct mt_usages *slot)
Benjamin Tissoires55978fa2013-01-31 17:22:24 +0100954{
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200955 struct input_mt *mt = input->mt;
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +0200956 __s32 quirks = app->quirks;
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200957 bool valid = true;
958 bool confidence_state = true;
959 bool inrange_state = false;
960 int active;
961 int slotnum;
Benjamin Tissoiresba6b0552018-07-13 16:13:49 +0200962 int tool = MT_TOOL_FINGER;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100963
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200964 if (!slot)
965 return -EINVAL;
966
967 if ((quirks & MT_QUIRK_CONTACT_CNT_ACCURATE) &&
968 app->num_received >= app->num_expected)
969 return -EAGAIN;
970
971 if (!(quirks & MT_QUIRK_ALWAYS_VALID)) {
972 if (quirks & MT_QUIRK_VALID_IS_INRANGE)
973 valid = *slot->inrange_state;
974 if (quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
975 valid = *slot->tip_state;
976 if (quirks & MT_QUIRK_VALID_IS_CONFIDENCE)
977 valid = *slot->confidence_state;
978
979 if (!valid)
980 return 0;
981 }
982
983 slotnum = mt_compute_slot(td, app, slot, input);
984 if (slotnum < 0 || slotnum >= td->maxcontacts)
985 return 0;
986
987 if ((quirks & MT_QUIRK_IGNORE_DUPLICATES) && mt) {
988 struct input_mt_slot *i_slot = &mt->slots[slotnum];
989
990 if (input_mt_is_active(i_slot) &&
991 input_mt_is_used(mt, i_slot))
992 return -EAGAIN;
993 }
994
995 if (quirks & MT_QUIRK_CONFIDENCE)
996 confidence_state = *slot->confidence_state;
997
998 if (quirks & MT_QUIRK_HOVERING)
999 inrange_state = *slot->inrange_state;
1000
Dmitry Torokhov9152c7d2018-07-13 16:13:52 +02001001 active = *slot->tip_state || inrange_state;
Benjamin Tissoires01eaac72018-07-13 16:13:48 +02001002
Benjamin Tissoiresba6b0552018-07-13 16:13:49 +02001003 if (app->application == HID_GD_SYSTEM_MULTIAXIS)
1004 tool = MT_TOOL_DIAL;
Dmitry Torokhov28a042a2018-07-13 16:13:54 +02001005 else if (unlikely(!confidence_state)) {
Dmitry Torokhov9152c7d2018-07-13 16:13:52 +02001006 tool = MT_TOOL_PALM;
Dmitry Torokhov28a042a2018-07-13 16:13:54 +02001007 if (!active &&
1008 input_mt_is_active(&mt->slots[slotnum])) {
1009 /*
1010 * The non-confidence was reported for
1011 * previously valid contact that is also no
1012 * longer valid. We can't simply report
1013 * lift-off as userspace will not be aware
1014 * of non-confidence, so we need to split
1015 * it into 2 events: active MT_TOOL_PALM
1016 * and a separate liftoff.
1017 */
1018 active = true;
1019 set_bit(slotnum, app->pending_palm_slots);
1020 }
1021 }
Benjamin Tissoiresba6b0552018-07-13 16:13:49 +02001022
Benjamin Tissoires01eaac72018-07-13 16:13:48 +02001023 input_mt_slot(input, slotnum);
Benjamin Tissoiresba6b0552018-07-13 16:13:49 +02001024 input_mt_report_slot_state(input, tool, active);
Benjamin Tissoires01eaac72018-07-13 16:13:48 +02001025 if (active) {
1026 /* this finger is in proximity of the sensor */
1027 int wide = (*slot->w > *slot->h);
1028 int major = max(*slot->w, *slot->h);
1029 int minor = min(*slot->w, *slot->h);
1030 int orientation = wide;
1031 int max_azimuth;
1032 int azimuth;
1033
1034 if (slot->a != DEFAULT_ZERO) {
Wei-Ning Huang00720272017-10-12 14:21:43 +08001035 /*
1036 * Azimuth is counter-clockwise and ranges from [0, MAX)
1037 * (a full revolution). Convert it to clockwise ranging
1038 * [-MAX/2, MAX/2].
1039 *
1040 * Note that ABS_MT_ORIENTATION require us to report
1041 * the limit of [-MAX/4, MAX/4], but the value can go
1042 * out of range to [-MAX/2, MAX/2] to report an upside
1043 * down ellipsis.
1044 */
Benjamin Tissoires01eaac72018-07-13 16:13:48 +02001045 azimuth = *slot->a;
1046 max_azimuth = input_abs_get_max(input,
1047 ABS_MT_ORIENTATION);
1048 if (azimuth > max_azimuth * 2)
1049 azimuth -= max_azimuth * 4;
1050 orientation = -azimuth;
1051 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001052
Benjamin Tissoires01eaac72018-07-13 16:13:48 +02001053 if (quirks & MT_QUIRK_TOUCH_SIZE_SCALING) {
Dmitry Torokhov9152c7d2018-07-13 16:13:52 +02001054 /*
1055 * divided by two to match visual scale of touch
1056 * for devices with this quirk
1057 */
Benjamin Tissoires01eaac72018-07-13 16:13:48 +02001058 major = major >> 1;
1059 minor = minor >> 1;
1060 }
Hans de Goede55746d22017-11-22 12:57:09 +01001061
Benjamin Tissoires01eaac72018-07-13 16:13:48 +02001062 input_event(input, EV_ABS, ABS_MT_POSITION_X, *slot->x);
1063 input_event(input, EV_ABS, ABS_MT_POSITION_Y, *slot->y);
1064 input_event(input, EV_ABS, ABS_MT_TOOL_X, *slot->cx);
1065 input_event(input, EV_ABS, ABS_MT_TOOL_Y, *slot->cy);
1066 input_event(input, EV_ABS, ABS_MT_DISTANCE, !*slot->tip_state);
1067 input_event(input, EV_ABS, ABS_MT_ORIENTATION, orientation);
1068 input_event(input, EV_ABS, ABS_MT_PRESSURE, *slot->p);
1069 input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, major);
1070 input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, minor);
Hans de Goede127e71b2017-11-22 12:57:10 +01001071
Benjamin Tissoires01eaac72018-07-13 16:13:48 +02001072 set_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags);
1073 }
1074
1075 return 0;
1076}
1077
1078static void mt_process_mt_event(struct hid_device *hid,
1079 struct mt_application *app,
1080 struct hid_field *field,
1081 struct hid_usage *usage,
1082 __s32 value,
1083 bool first_packet)
1084{
1085 __s32 quirks = app->quirks;
1086 struct input_dev *input = field->hidinput->input;
1087
1088 if (!usage->type || !(hid->claimed & HID_CLAIMED_INPUT))
1089 return;
1090
1091 if (quirks & MT_QUIRK_WIN8_PTP_BUTTONS) {
1092
1093 /*
1094 * For Win8 PTP touchpads we should only look at
1095 * non finger/touch events in the first_packet of a
1096 * (possible) multi-packet frame.
1097 */
1098 if (!first_packet)
1099 return;
1100
1101 /*
1102 * For Win8 PTP touchpads we map both the clickpad click
1103 * and any "external" left buttons to BTN_LEFT if a
1104 * device claims to have both we need to report 1 for
1105 * BTN_LEFT if either is pressed, so we or all values
1106 * together and report the result in mt_sync_frame().
1107 */
1108 if (usage->type == EV_KEY && usage->code == BTN_LEFT) {
1109 app->left_button_state |= value;
Benjamin Tissoires55978fa2013-01-31 17:22:24 +01001110 return;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001111 }
1112 }
Benjamin Tissoires01eaac72018-07-13 16:13:48 +02001113
1114 input_event(input, usage->type, usage->code, value);
Benjamin Tissoires55978fa2013-01-31 17:22:24 +01001115}
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001116
Benjamin Tissoires8dfe14b2018-07-13 16:13:47 +02001117static void mt_touch_report(struct hid_device *hid,
1118 struct mt_report_data *rdata)
Benjamin Tissoires55978fa2013-01-31 17:22:24 +01001119{
1120 struct mt_device *td = hid_get_drvdata(hid);
Benjamin Tissoires8dfe14b2018-07-13 16:13:47 +02001121 struct hid_report *report = rdata->report;
1122 struct mt_application *app = rdata->application;
Benjamin Tissoires55978fa2013-01-31 17:22:24 +01001123 struct hid_field *field;
Benjamin Tissoires01eaac72018-07-13 16:13:48 +02001124 struct input_dev *input;
1125 struct mt_usages *slot;
Hans de Goede55746d22017-11-22 12:57:09 +01001126 bool first_packet;
Benjamin Tissoires55978fa2013-01-31 17:22:24 +01001127 unsigned count;
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001128 int r, n;
1129 int scantime = 0;
1130 int contact_count = -1;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001131
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +02001132 /* sticky fingers release in progress, abort */
1133 if (test_and_set_bit(MT_IO_FLAGS_RUNNING, &td->mt_io_flags))
1134 return;
1135
Benjamin Tissoires01eaac72018-07-13 16:13:48 +02001136 scantime = *app->scantime;
1137 app->timestamp = mt_compute_timestamp(app, scantime);
1138 if (app->raw_cc != DEFAULT_ZERO)
1139 contact_count = *app->raw_cc;
1140
Benjamin Tissoiresc2517f62013-01-31 17:22:25 +01001141 /*
1142 * Includes multi-packet support where subsequent
1143 * packets are sent with zero contactcount.
1144 */
Benjamin Tissoires01eaac72018-07-13 16:13:48 +02001145 if (contact_count >= 0) {
Hans de Goedeaf8dc4d2017-11-22 12:57:08 +01001146 /*
1147 * For Win8 PTPs the first packet (td->num_received == 0) may
1148 * have a contactcount of 0 if there only is a button event.
1149 * We double check that this is not a continuation packet
1150 * of a possible multi-packet frame be checking that the
1151 * timestamp has changed.
1152 */
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +02001153 if ((app->quirks & MT_QUIRK_WIN8_PTP_BUTTONS) &&
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001154 app->num_received == 0 &&
1155 app->prev_scantime != scantime)
1156 app->num_expected = contact_count;
Hans de Goedeaf8dc4d2017-11-22 12:57:08 +01001157 /* A non 0 contact count always indicates a first packet */
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001158 else if (contact_count)
1159 app->num_expected = contact_count;
Benjamin Tissoires7e3cc442013-02-06 12:10:47 +01001160 }
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001161 app->prev_scantime = scantime;
Benjamin Tissoiresc2517f62013-01-31 17:22:25 +01001162
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001163 first_packet = app->num_received == 0;
Benjamin Tissoires01eaac72018-07-13 16:13:48 +02001164
1165 input = report->field[0]->hidinput->input;
1166
1167 list_for_each_entry(slot, &app->mt_usages, list) {
1168 if (!mt_process_slot(td, input, app, slot))
1169 app->num_received++;
1170 }
1171
Benjamin Tissoires55978fa2013-01-31 17:22:24 +01001172 for (r = 0; r < report->maxfield; r++) {
1173 field = report->field[r];
1174 count = field->report_count;
1175
1176 if (!(HID_MAIN_ITEM_VARIABLE & field->flags))
1177 continue;
1178
1179 for (n = 0; n < count; n++)
Benjamin Tissoires01eaac72018-07-13 16:13:48 +02001180 mt_process_mt_event(hid, app, field,
1181 &field->usage[n], field->value[n],
1182 first_packet);
Benjamin Tissoires55978fa2013-01-31 17:22:24 +01001183 }
Benjamin Tissoires5b62efd2013-02-27 16:23:15 +01001184
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001185 if (app->num_received >= app->num_expected)
Benjamin Tissoires01eaac72018-07-13 16:13:48 +02001186 mt_sync_frame(td, app, input);
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +02001187
1188 /*
1189 * Windows 8 specs says 2 things:
1190 * - once a contact has been reported, it has to be reported in each
1191 * subsequent report
1192 * - the report rate when fingers are present has to be at least
1193 * the refresh rate of the screen, 60 or 120 Hz
1194 *
1195 * I interprete this that the specification forces a report rate of
1196 * at least 60 Hz for a touchscreen to be certified.
1197 * Which means that if we do not get a report whithin 16 ms, either
1198 * something wrong happens, either the touchscreen forgets to send
1199 * a release. Taking a reasonable margin allows to remove issues
1200 * with USB communication or the load of the machine.
1201 *
1202 * Given that Win 8 devices are forced to send a release, this will
1203 * only affect laggish machines and the ones that have a firmware
1204 * defect.
1205 */
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +02001206 if (app->quirks & MT_QUIRK_STICKY_FINGERS) {
Benjamin Tissoires96098272017-06-15 15:32:05 +02001207 if (test_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags))
1208 mod_timer(&td->release_timer,
1209 jiffies + msecs_to_jiffies(100));
1210 else
1211 del_timer(&td->release_timer);
1212 }
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +02001213
1214 clear_bit(MT_IO_FLAGS_RUNNING, &td->mt_io_flags);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001215}
1216
Dmitry Torokhovb2c68a22015-09-29 15:52:59 -07001217static int mt_touch_input_configured(struct hid_device *hdev,
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001218 struct hid_input *hi,
1219 struct mt_application *app)
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001220{
1221 struct mt_device *td = hid_get_drvdata(hdev);
1222 struct mt_class *cls = &td->mtclass;
1223 struct input_dev *input = hi->input;
Dmitry Torokhovb2c68a22015-09-29 15:52:59 -07001224 int ret;
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001225
1226 if (!td->maxcontacts)
1227 td->maxcontacts = MT_DEFAULT_MAXCONTACT;
1228
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001229 mt_post_parse(td, app);
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001230 if (td->serial_maybe)
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001231 mt_post_parse_default_settings(td, app);
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001232
1233 if (cls->is_indirect)
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001234 app->mt_flags |= INPUT_MT_POINTER;
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001235
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +02001236 if (app->quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001237 app->mt_flags |= INPUT_MT_DROP_UNUSED;
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001238
Benjamin Tissoires015fdaa2015-03-06 11:14:42 -05001239 /* check for clickpads */
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001240 if ((app->mt_flags & INPUT_MT_POINTER) &&
1241 (app->buttons_count == 1))
Seth Forshee2c6e0272015-03-11 17:26:41 -05001242 td->is_buttonpad = true;
1243
1244 if (td->is_buttonpad)
Benjamin Tissoires015fdaa2015-03-06 11:14:42 -05001245 __set_bit(INPUT_PROP_BUTTONPAD, input->propbit);
1246
Dmitry Torokhov28a042a2018-07-13 16:13:54 +02001247 app->pending_palm_slots = devm_kcalloc(&hi->input->dev,
1248 BITS_TO_LONGS(td->maxcontacts),
1249 sizeof(long),
1250 GFP_KERNEL);
1251 if (!app->pending_palm_slots)
1252 return -ENOMEM;
1253
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001254 ret = input_mt_init_slots(input, td->maxcontacts, app->mt_flags);
Dmitry Torokhovb2c68a22015-09-29 15:52:59 -07001255 if (ret)
1256 return ret;
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001257
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001258 app->mt_flags = 0;
Dmitry Torokhovb2c68a22015-09-29 15:52:59 -07001259 return 0;
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001260}
1261
João Paulo Rechi Vita957b8df2017-07-24 14:22:25 -07001262#define mt_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, \
1263 max, EV_KEY, (c))
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001264static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
1265 struct hid_field *field, struct hid_usage *usage,
1266 unsigned long **bit, int *max)
1267{
Benjamin Tissoires6aef7042014-02-28 11:41:25 -05001268 struct mt_device *td = hid_get_drvdata(hdev);
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001269 struct mt_application *application;
Benjamin Tissoires8dfe14b2018-07-13 16:13:47 +02001270 struct mt_report_data *rdata;
Benjamin Tissoires6aef7042014-02-28 11:41:25 -05001271
Benjamin Tissoires8dfe14b2018-07-13 16:13:47 +02001272 rdata = mt_find_report_data(td, field->report);
1273 if (!rdata) {
1274 hid_err(hdev, "failed to allocate data for report\n");
1275 return 0;
1276 }
1277
1278 application = rdata->application;
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +02001279
Benjamin Tissoires6aef7042014-02-28 11:41:25 -05001280 /*
1281 * If mtclass.export_all_inputs is not set, only map fields from
1282 * TouchScreen or TouchPad collections. We need to ignore fields
1283 * that belong to other collections such as Mouse that might have
1284 * the same GenericDesktop usages.
1285 */
1286 if (!td->mtclass.export_all_inputs &&
1287 field->application != HID_DG_TOUCHSCREEN &&
Benjamin Tissoiresfa11aa72013-03-22 18:38:32 +01001288 field->application != HID_DG_PEN &&
Benjamin Tissoires8fe89ef2016-11-25 14:27:23 +01001289 field->application != HID_DG_TOUCHPAD &&
1290 field->application != HID_GD_KEYBOARD &&
Hans de Goedee57f4e62017-08-22 08:37:52 +02001291 field->application != HID_GD_SYSTEM_CONTROL &&
João Paulo Rechi Vita1fbf74ef2017-07-24 14:22:24 -07001292 field->application != HID_CP_CONSUMER_CONTROL &&
João Paulo Rechi Vita957b8df2017-07-24 14:22:25 -07001293 field->application != HID_GD_WIRELESS_RADIO_CTLS &&
Benjamin Tissoiresba6b0552018-07-13 16:13:49 +02001294 field->application != HID_GD_SYSTEM_MULTIAXIS &&
João Paulo Rechi Vita957b8df2017-07-24 14:22:25 -07001295 !(field->application == HID_VD_ASUS_CUSTOM_MEDIA_KEYS &&
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +02001296 application->quirks & MT_QUIRK_ASUS_CUSTOM_UP))
Benjamin Tissoires6f492f22013-03-22 18:38:30 +01001297 return -1;
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001298
Benjamin Tissoires6aef7042014-02-28 11:41:25 -05001299 /*
João Paulo Rechi Vita957b8df2017-07-24 14:22:25 -07001300 * Some Asus keyboard+touchpad devices have the hotkeys defined in the
1301 * touchpad report descriptor. We need to treat these as an array to
1302 * map usages to input keys.
1303 */
Jiri Kosina39bbf402017-08-03 11:25:32 +02001304 if (field->application == HID_VD_ASUS_CUSTOM_MEDIA_KEYS &&
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +02001305 application->quirks & MT_QUIRK_ASUS_CUSTOM_UP &&
João Paulo Rechi Vita957b8df2017-07-24 14:22:25 -07001306 (usage->hid & HID_USAGE_PAGE) == HID_UP_CUSTOM) {
1307 set_bit(EV_REP, hi->input->evbit);
1308 if (field->flags & HID_MAIN_ITEM_VARIABLE)
1309 field->flags &= ~HID_MAIN_ITEM_VARIABLE;
1310 switch (usage->hid & HID_USAGE) {
1311 case 0x10: mt_map_key_clear(KEY_BRIGHTNESSDOWN); break;
1312 case 0x20: mt_map_key_clear(KEY_BRIGHTNESSUP); break;
1313 case 0x35: mt_map_key_clear(KEY_DISPLAY_OFF); break;
1314 case 0x6b: mt_map_key_clear(KEY_F21); break;
1315 case 0x6c: mt_map_key_clear(KEY_SLEEP); break;
1316 default:
1317 return -1;
1318 }
1319 return 1;
1320 }
1321
Benjamin Tissoiresba6b0552018-07-13 16:13:49 +02001322 if (rdata->is_mt_collection)
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001323 return mt_touch_input_mapping(hdev, hi, field, usage, bit, max,
1324 application);
Benjamin Tissoires6aef7042014-02-28 11:41:25 -05001325
Benjamin Tissoires7ffa13b2018-09-04 15:31:15 +02001326 /*
1327 * some egalax touchscreens have "application == DG_TOUCHSCREEN"
1328 * for the stylus. Overwrite the hid_input application
1329 */
1330 if (field->physical == HID_DG_STYLUS)
1331 hi->application = HID_DG_STYLUS;
1332
Benjamin Tissoires6aef7042014-02-28 11:41:25 -05001333 /* let hid-core decide for the others */
1334 return 0;
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001335}
1336
1337static int mt_input_mapped(struct hid_device *hdev, struct hid_input *hi,
1338 struct hid_field *field, struct hid_usage *usage,
1339 unsigned long **bit, int *max)
1340{
Benjamin Tissoiresba6b0552018-07-13 16:13:49 +02001341 struct mt_device *td = hid_get_drvdata(hdev);
1342 struct mt_report_data *rdata;
Benjamin Tissoiresfa11aa72013-03-22 18:38:32 +01001343
Benjamin Tissoiresba6b0552018-07-13 16:13:49 +02001344 rdata = mt_find_report_data(td, field->report);
1345 if (rdata && rdata->is_mt_collection) {
Dmitry Torokhov4cf56a89c2017-07-11 10:02:18 -07001346 /* We own these mappings, tell hid-input to ignore them */
1347 return -1;
1348 }
Benjamin Tissoires6aef7042014-02-28 11:41:25 -05001349
1350 /* let hid-core decide for the others */
1351 return 0;
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001352}
1353
1354static int mt_event(struct hid_device *hid, struct hid_field *field,
1355 struct hid_usage *usage, __s32 value)
1356{
1357 struct mt_device *td = hid_get_drvdata(hid);
Benjamin Tissoires8dfe14b2018-07-13 16:13:47 +02001358 struct mt_report_data *rdata;
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001359
Benjamin Tissoires8dfe14b2018-07-13 16:13:47 +02001360 rdata = mt_find_report_data(td, field->report);
1361 if (rdata && rdata->is_mt_collection)
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001362 return mt_touch_event(hid, field, usage, value);
1363
Benjamin Tissoirese55f6202014-02-28 11:41:24 -05001364 return 0;
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001365}
1366
1367static void mt_report(struct hid_device *hid, struct hid_report *report)
1368{
1369 struct mt_device *td = hid_get_drvdata(hid);
Benjamin Tissoirese55f6202014-02-28 11:41:24 -05001370 struct hid_field *field = report->field[0];
Benjamin Tissoires8dfe14b2018-07-13 16:13:47 +02001371 struct mt_report_data *rdata;
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001372
1373 if (!(hid->claimed & HID_CLAIMED_INPUT))
1374 return;
1375
Benjamin Tissoires8dfe14b2018-07-13 16:13:47 +02001376 rdata = mt_find_report_data(td, report);
1377 if (rdata && rdata->is_mt_collection)
1378 return mt_touch_report(hid, rdata);
Benjamin Tissoiresfa11aa72013-03-22 18:38:32 +01001379
Benjamin Tissoirese55f6202014-02-28 11:41:24 -05001380 if (field && field->hidinput && field->hidinput->input)
1381 input_sync(field->hidinput->input);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001382}
1383
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001384static bool mt_need_to_apply_feature(struct hid_device *hdev,
1385 struct hid_field *field,
Benjamin Tissoires02946f42018-04-24 10:04:37 +02001386 struct hid_usage *usage,
1387 enum latency_mode latency,
1388 bool surface_switch,
Benjamin Tissoiresec6adef2018-09-04 15:31:12 +02001389 bool button_switch,
1390 bool *inputmode_found)
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001391{
1392 struct mt_device *td = hid_get_drvdata(hdev);
Mathieu Magnaudetda10bc22014-11-22 12:02:07 +01001393 struct mt_class *cls = &td->mtclass;
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001394 struct hid_report *report = field->report;
1395 unsigned int index = usage->usage_index;
Mathieu Magnaudetda10bc22014-11-22 12:02:07 +01001396 char *buf;
Aaron Ma3064a032018-02-03 23:57:15 +08001397 u32 report_len;
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001398 int max;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001399
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001400 switch (usage->hid) {
1401 case HID_DG_INPUTMODE:
Benjamin Tissoiresec6adef2018-09-04 15:31:12 +02001402 /*
1403 * Some elan panels wrongly declare 2 input mode features,
1404 * and silently ignore when we set the value in the second
1405 * field. Skip the second feature and hope for the best.
1406 */
1407 if (*inputmode_found)
1408 return false;
1409
Mathieu Magnaudetda10bc22014-11-22 12:02:07 +01001410 if (cls->quirks & MT_QUIRK_FORCE_GET_FEATURE) {
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001411 report_len = hid_report_len(report);
1412 buf = hid_alloc_report_buf(report, GFP_KERNEL);
Mathieu Magnaudetda10bc22014-11-22 12:02:07 +01001413 if (!buf) {
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001414 hid_err(hdev,
1415 "failed to allocate buffer for report\n");
1416 return false;
Mathieu Magnaudetda10bc22014-11-22 12:02:07 +01001417 }
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001418 hid_hw_raw_request(hdev, report->id, buf, report_len,
Mathieu Magnaudetda10bc22014-11-22 12:02:07 +01001419 HID_FEATURE_REPORT,
1420 HID_REQ_GET_REPORT);
1421 kfree(buf);
1422 }
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001423
1424 field->value[index] = td->inputmode_value;
Benjamin Tissoiresec6adef2018-09-04 15:31:12 +02001425 *inputmode_found = true;
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001426 return true;
1427
1428 case HID_DG_CONTACTMAX:
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +02001429 if (cls->maxcontacts) {
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001430 max = min_t(int, field->logical_maximum,
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +02001431 cls->maxcontacts);
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001432 if (field->value[index] != max) {
1433 field->value[index] = max;
1434 return true;
1435 }
1436 }
1437 break;
Benjamin Tissoires02946f42018-04-24 10:04:37 +02001438
1439 case HID_DG_LATENCYMODE:
1440 field->value[index] = latency;
Jiri Kosina99c703a2018-05-16 11:02:07 +02001441 return true;
Benjamin Tissoires02946f42018-04-24 10:04:37 +02001442
1443 case HID_DG_SURFACESWITCH:
1444 field->value[index] = surface_switch;
Jiri Kosina99c703a2018-05-16 11:02:07 +02001445 return true;
Benjamin Tissoires02946f42018-04-24 10:04:37 +02001446
1447 case HID_DG_BUTTONSWITCH:
1448 field->value[index] = button_switch;
Jiri Kosina99c703a2018-05-16 11:02:07 +02001449 return true;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001450 }
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001451
1452 return false; /* no need to update the report */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001453}
1454
Benjamin Tissoires02946f42018-04-24 10:04:37 +02001455static void mt_set_modes(struct hid_device *hdev, enum latency_mode latency,
1456 bool surface_switch, bool button_switch)
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +01001457{
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001458 struct hid_report_enum *rep_enum;
1459 struct hid_report *rep;
1460 struct hid_usage *usage;
1461 int i, j;
1462 bool update_report;
Benjamin Tissoiresec6adef2018-09-04 15:31:12 +02001463 bool inputmode_found = false;
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +01001464
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001465 rep_enum = &hdev->report_enum[HID_FEATURE_REPORT];
1466 list_for_each_entry(rep, &rep_enum->report_list, list) {
1467 update_report = false;
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +01001468
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001469 for (i = 0; i < rep->maxfield; i++) {
1470 /* Ignore if report count is out of bounds. */
1471 if (rep->field[i]->report_count < 1)
1472 continue;
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +01001473
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001474 for (j = 0; j < rep->field[i]->maxusage; j++) {
1475 usage = &rep->field[i]->usage[j];
1476
1477 if (mt_need_to_apply_feature(hdev,
1478 rep->field[i],
Benjamin Tissoires02946f42018-04-24 10:04:37 +02001479 usage,
1480 latency,
1481 surface_switch,
Benjamin Tissoiresec6adef2018-09-04 15:31:12 +02001482 button_switch,
1483 &inputmode_found))
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001484 update_report = true;
1485 }
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +01001486 }
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001487
1488 if (update_report)
1489 hid_hw_request(hdev, rep, HID_REQ_SET_REPORT);
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +01001490 }
1491}
1492
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001493static void mt_post_parse_default_settings(struct mt_device *td,
1494 struct mt_application *app)
Henrik Rydberg4fa3a582012-05-01 08:40:01 +02001495{
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +02001496 __s32 quirks = app->quirks;
Henrik Rydberg4fa3a582012-05-01 08:40:01 +02001497
1498 /* unknown serial device needs special quirks */
Benjamin Tissoires01eaac72018-07-13 16:13:48 +02001499 if (list_is_singular(&app->mt_usages)) {
Henrik Rydberg4fa3a582012-05-01 08:40:01 +02001500 quirks |= MT_QUIRK_ALWAYS_VALID;
1501 quirks &= ~MT_QUIRK_NOT_SEEN_MEANS_UP;
1502 quirks &= ~MT_QUIRK_VALID_IS_INRANGE;
1503 quirks &= ~MT_QUIRK_VALID_IS_CONFIDENCE;
Benjamin Tissoirese0bb8f92013-01-31 17:22:27 +01001504 quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE;
Henrik Rydberg4fa3a582012-05-01 08:40:01 +02001505 }
1506
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +02001507 app->quirks = quirks;
Henrik Rydberg4fa3a582012-05-01 08:40:01 +02001508}
1509
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001510static void mt_post_parse(struct mt_device *td, struct mt_application *app)
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +02001511{
Benjamin Tissoires01eaac72018-07-13 16:13:48 +02001512 if (!app->have_contact_count)
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +02001513 app->quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE;
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +02001514}
1515
Dmitry Torokhovb2c68a22015-09-29 15:52:59 -07001516static int mt_input_configured(struct hid_device *hdev, struct hid_input *hi)
Henrik Rydberg76f59022012-09-01 20:11:34 +02001517{
1518 struct mt_device *td = hid_get_drvdata(hdev);
Benjamin Tissoiresc08d46a2013-07-24 19:38:05 +02001519 char *name;
1520 const char *suffix = NULL;
Benjamin Tissoires8dfe14b2018-07-13 16:13:47 +02001521 struct mt_report_data *rdata;
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001522 struct mt_application *mt_application = NULL;
Benjamin Tissoires40ec2602018-04-24 10:04:35 +02001523 struct hid_report *report;
Dmitry Torokhovb2c68a22015-09-29 15:52:59 -07001524 int ret;
Henrik Rydberg76f59022012-09-01 20:11:34 +02001525
Benjamin Tissoires40ec2602018-04-24 10:04:35 +02001526 list_for_each_entry(report, &hi->reports, hidinput_list) {
Benjamin Tissoires8dfe14b2018-07-13 16:13:47 +02001527 rdata = mt_find_report_data(td, report);
1528 if (!rdata) {
1529 hid_err(hdev, "failed to allocate data for report\n");
1530 return -ENOMEM;
1531 }
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001532
Benjamin Tissoires8dfe14b2018-07-13 16:13:47 +02001533 mt_application = rdata->application;
1534
1535 if (rdata->is_mt_collection) {
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001536 ret = mt_touch_input_configured(hdev, hi,
1537 mt_application);
Benjamin Tissoires40ec2602018-04-24 10:04:35 +02001538 if (ret)
1539 return ret;
1540 }
Benjamin Tissoires40ec2602018-04-24 10:04:35 +02001541 }
1542
Benjamin Tissoires7ffa13b2018-09-04 15:31:15 +02001543 switch (hi->application) {
1544 case HID_GD_KEYBOARD:
1545 case HID_GD_KEYPAD:
1546 case HID_GD_MOUSE:
1547 case HID_DG_TOUCHPAD:
1548 case HID_GD_SYSTEM_CONTROL:
1549 case HID_CP_CONSUMER_CONTROL:
1550 case HID_GD_WIRELESS_RADIO_CTLS:
1551 case HID_GD_SYSTEM_MULTIAXIS:
1552 /* already handled by hid core */
1553 break;
1554 case HID_DG_TOUCHSCREEN:
1555 /* we do not set suffix = "Touchscreen" */
1556 hi->input->name = hdev->name;
1557 break;
1558 case HID_DG_STYLUS:
1559 /* force BTN_STYLUS to allow tablet matching in udev */
1560 __set_bit(BTN_STYLUS, hi->input->keybit);
1561 break;
1562 case HID_VD_ASUS_CUSTOM_MEDIA_KEYS:
1563 suffix = "Custom Media Keys";
1564 break;
1565 default:
1566 suffix = "UNKNOWN";
1567 break;
Benjamin Tissoiresc08d46a2013-07-24 19:38:05 +02001568 }
1569
1570 if (suffix) {
1571 name = devm_kzalloc(&hi->input->dev,
1572 strlen(hdev->name) + strlen(suffix) + 2,
1573 GFP_KERNEL);
1574 if (name) {
1575 sprintf(name, "%s %s", hdev->name, suffix);
1576 hi->input->name = name;
1577 }
1578 }
Dmitry Torokhovb2c68a22015-09-29 15:52:59 -07001579
1580 return 0;
Henrik Rydberg76f59022012-09-01 20:11:34 +02001581}
1582
Benjamin Tissoiresf3287a92017-01-30 10:48:06 +01001583static void mt_fix_const_field(struct hid_field *field, unsigned int usage)
1584{
1585 if (field->usage[0].hid != usage ||
1586 !(field->flags & HID_MAIN_ITEM_CONSTANT))
1587 return;
1588
1589 field->flags &= ~HID_MAIN_ITEM_CONSTANT;
1590 field->flags |= HID_MAIN_ITEM_VARIABLE;
1591}
1592
1593static void mt_fix_const_fields(struct hid_device *hdev, unsigned int usage)
1594{
1595 struct hid_report *report;
1596 int i;
1597
1598 list_for_each_entry(report,
1599 &hdev->report_enum[HID_INPUT_REPORT].report_list,
1600 list) {
1601
1602 if (!report->maxfield)
1603 continue;
1604
1605 for (i = 0; i < report->maxfield; i++)
1606 if (report->field[i]->maxusage >= 1)
1607 mt_fix_const_field(report->field[i], usage);
1608 }
1609}
1610
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +02001611static void mt_release_contacts(struct hid_device *hid)
1612{
1613 struct hid_input *hidinput;
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001614 struct mt_application *application;
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +02001615 struct mt_device *td = hid_get_drvdata(hid);
1616
1617 list_for_each_entry(hidinput, &hid->inputs, list) {
1618 struct input_dev *input_dev = hidinput->input;
1619 struct input_mt *mt = input_dev->mt;
1620 int i;
1621
1622 if (mt) {
1623 for (i = 0; i < mt->num_slots; i++) {
1624 input_mt_slot(input_dev, i);
1625 input_mt_report_slot_state(input_dev,
1626 MT_TOOL_FINGER,
1627 false);
1628 }
1629 input_mt_sync_frame(input_dev);
1630 input_sync(input_dev);
1631 }
1632 }
1633
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001634 list_for_each_entry(application, &td->applications, list) {
1635 application->num_received = 0;
1636 }
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +02001637}
1638
Kees Cook0ee32772017-10-04 17:53:24 -07001639static void mt_expired_timeout(struct timer_list *t)
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +02001640{
Kees Cook0ee32772017-10-04 17:53:24 -07001641 struct mt_device *td = from_timer(td, t, release_timer);
1642 struct hid_device *hdev = td->hdev;
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +02001643
1644 /*
1645 * An input report came in just before we release the sticky fingers,
1646 * it will take care of the sticky fingers.
1647 */
1648 if (test_and_set_bit(MT_IO_FLAGS_RUNNING, &td->mt_io_flags))
1649 return;
Benjamin Tissoires96098272017-06-15 15:32:05 +02001650 if (test_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags))
1651 mt_release_contacts(hdev);
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +02001652 clear_bit(MT_IO_FLAGS_RUNNING, &td->mt_io_flags);
1653}
1654
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001655static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
1656{
Benjamin Tissoires2d936662011-01-11 16:45:54 +01001657 int ret, i;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001658 struct mt_device *td;
Benjamin Tissoirescf6d15d2018-07-13 16:13:44 +02001659 const struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */
Benjamin Tissoires2d936662011-01-11 16:45:54 +01001660
Henrik Rydberg94b5485c2012-08-08 21:45:50 +02001661 for (i = 0; mt_classes[i].name ; i++) {
1662 if (id->driver_data == mt_classes[i].name) {
1663 mtclass = &(mt_classes[i]);
1664 break;
Benjamin Tissoires2d936662011-01-11 16:45:54 +01001665 }
1666 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001667
Benjamin Tissoiresc08d46a2013-07-24 19:38:05 +02001668 td = devm_kzalloc(&hdev->dev, sizeof(struct mt_device), GFP_KERNEL);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001669 if (!td) {
1670 dev_err(&hdev->dev, "cannot allocate multitouch data\n");
1671 return -ENOMEM;
1672 }
Kees Cook0ee32772017-10-04 17:53:24 -07001673 td->hdev = hdev;
Benjamin Tissoireseec29e32011-11-23 10:54:28 +01001674 td->mtclass = *mtclass;
Andrew Duggan9abebed2014-03-19 13:39:03 -07001675 td->inputmode_value = MT_INPUTMODE_TOUCHSCREEN;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001676 hid_set_drvdata(hdev, td);
1677
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001678 INIT_LIST_HEAD(&td->applications);
Benjamin Tissoires8dfe14b2018-07-13 16:13:47 +02001679 INIT_LIST_HEAD(&td->reports);
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001680
Henrik Rydberg76f59022012-09-01 20:11:34 +02001681 if (id->vendor == HID_ANY_ID && id->product == HID_ANY_ID)
1682 td->serial_maybe = true;
1683
Benjamin Tissoiresb897f6d2016-11-25 14:27:22 +01001684 /* This allows the driver to correctly support devices
1685 * that emit events over several HID messages.
1686 */
1687 hdev->quirks |= HID_QUIRK_NO_INPUT_SYNC;
1688
1689 /*
1690 * This allows the driver to handle different input sensors
Benjamin Tissoires40ec2602018-04-24 10:04:35 +02001691 * that emits events through different applications on the same HID
Benjamin Tissoiresb897f6d2016-11-25 14:27:22 +01001692 * device.
1693 */
Benjamin Tissoires40ec2602018-04-24 10:04:35 +02001694 hdev->quirks |= HID_QUIRK_INPUT_PER_APP;
Benjamin Tissoiresb897f6d2016-11-25 14:27:22 +01001695
Benjamin Tissoires0d6c3012018-09-04 15:31:14 +02001696 if (id->group != HID_GROUP_MULTITOUCH_WIN_8)
1697 hdev->quirks |= HID_QUIRK_MULTI_INPUT;
1698
Kees Cook0ee32772017-10-04 17:53:24 -07001699 timer_setup(&td->release_timer, mt_expired_timeout, 0);
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +02001700
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001701 ret = hid_parse(hdev);
1702 if (ret != 0)
Benjamin Tissoiresc08d46a2013-07-24 19:38:05 +02001703 return ret;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001704
Benjamin Tissoiresf3287a92017-01-30 10:48:06 +01001705 if (mtclass->quirks & MT_QUIRK_FIX_CONST_CONTACT_ID)
1706 mt_fix_const_fields(hdev, HID_DG_CONTACTID);
1707
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001708 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
Benjamin Tissoires2d936662011-01-11 16:45:54 +01001709 if (ret)
Benjamin Tissoiresc08d46a2013-07-24 19:38:05 +02001710 return ret;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001711
Benjamin Tissoireseec29e32011-11-23 10:54:28 +01001712 ret = sysfs_create_group(&hdev->dev.kobj, &mt_attribute_group);
Nicholas Krause0c4b3c62016-02-04 10:52:40 -05001713 if (ret)
1714 dev_warn(&hdev->dev, "Cannot allocate sysfs group for %s\n",
1715 hdev->name);
Benjamin Tissoireseec29e32011-11-23 10:54:28 +01001716
Benjamin Tissoires02946f42018-04-24 10:04:37 +02001717 mt_set_modes(hdev, HID_LATENCY_NORMAL, true, true);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001718
1719 return 0;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001720}
1721
1722#ifdef CONFIG_PM
1723static int mt_reset_resume(struct hid_device *hdev)
1724{
Benson Leungd3e69b92016-03-11 14:19:49 -08001725 mt_release_contacts(hdev);
Benjamin Tissoires02946f42018-04-24 10:04:37 +02001726 mt_set_modes(hdev, HID_LATENCY_NORMAL, true, true);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001727 return 0;
1728}
Scott Liudfeefd12012-08-15 17:21:55 +08001729
1730static int mt_resume(struct hid_device *hdev)
1731{
Scott Liudfeefd12012-08-15 17:21:55 +08001732 /* Some Elan legacy devices require SET_IDLE to be set on resume.
1733 * It should be safe to send it to other devices too.
1734 * Tested on 3M, Stantum, Cypress, Zytronic, eGalax, and Elan panels. */
1735
Benjamin Tissoires4ba25d32013-02-27 16:38:18 +01001736 hid_hw_idle(hdev, 0, 0, HID_REQ_SET_IDLE);
Scott Liudfeefd12012-08-15 17:21:55 +08001737
1738 return 0;
1739}
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001740#endif
1741
1742static void mt_remove(struct hid_device *hdev)
1743{
Benjamin Tissoiresb897f6d2016-11-25 14:27:22 +01001744 struct mt_device *td = hid_get_drvdata(hdev);
1745
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +02001746 del_timer_sync(&td->release_timer);
1747
Benjamin Tissoireseec29e32011-11-23 10:54:28 +01001748 sysfs_remove_group(&hdev->dev.kobj, &mt_attribute_group);
Benjamin Tissoires59392122013-05-29 10:45:09 +02001749 hid_hw_stop(hdev);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001750}
1751
Benjamin Tissoires0fa9c612014-02-28 11:41:23 -05001752/*
1753 * This list contains only:
1754 * - VID/PID of products not working with the default multitouch handling
1755 * - 2 generic rules.
1756 * So there is no point in adding here any device with MT_CLS_DEFAULT.
1757 */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001758static const struct hid_device_id mt_devices[] = {
1759
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +01001760 /* 3M panels */
1761 { .driver_data = MT_CLS_3M,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001762 MT_USB_DEVICE(USB_VENDOR_ID_3M,
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +01001763 USB_DEVICE_ID_3M1968) },
1764 { .driver_data = MT_CLS_3M,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001765 MT_USB_DEVICE(USB_VENDOR_ID_3M,
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +01001766 USB_DEVICE_ID_3M2256) },
Benjamin Tissoiresc4fad872011-12-23 15:41:00 +01001767 { .driver_data = MT_CLS_3M,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001768 MT_USB_DEVICE(USB_VENDOR_ID_3M,
Benjamin Tissoiresc4fad872011-12-23 15:41:00 +01001769 USB_DEVICE_ID_3M3266) },
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +01001770
Masaki Ota504c9322017-06-16 09:29:39 +09001771 /* Alps devices */
1772 { .driver_data = MT_CLS_WIN_8_DUAL,
1773 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
1774 USB_VENDOR_ID_ALPS_JP,
1775 HID_DEVICE_ID_ALPS_U1_DUAL_PTP) },
1776 { .driver_data = MT_CLS_WIN_8_DUAL,
1777 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
1778 USB_VENDOR_ID_ALPS_JP,
1779 HID_DEVICE_ID_ALPS_U1_DUAL_3BTN_PTP) },
Kai-Heng Feng0a95fc72019-06-14 16:56:55 +08001780 { .driver_data = MT_CLS_WIN_8_DUAL,
1781 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
1782 USB_VENDOR_ID_ALPS_JP,
1783 HID_DEVICE_ID_ALPS_1222) },
Masaki Ota504c9322017-06-16 09:29:39 +09001784
Pavel Tatashin56d859e2017-08-25 18:06:04 -04001785 /* Lenovo X1 TAB Gen 2 */
1786 { .driver_data = MT_CLS_WIN_8_DUAL,
1787 HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8,
1788 USB_VENDOR_ID_LENOVO,
1789 USB_DEVICE_ID_LENOVO_X1_TAB) },
1790
Mikael Wikström8d5037d2019-02-09 19:05:26 +01001791 /* Lenovo X1 TAB Gen 3 */
1792 { .driver_data = MT_CLS_WIN_8_DUAL,
1793 HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8,
1794 USB_VENDOR_ID_LENOVO,
1795 USB_DEVICE_ID_LENOVO_X1_TAB3) },
1796
Benjamin Tissoires6aef7042014-02-28 11:41:25 -05001797 /* Anton devices */
1798 { .driver_data = MT_CLS_EXPORT_ALL_INPUTS,
1799 MT_USB_DEVICE(USB_VENDOR_ID_ANTON,
1800 USB_DEVICE_ID_ANTON_TOUCH_PAD) },
Benjamin Tissoirese6aac342011-05-19 14:18:13 +02001801
João Paulo Rechi Vita957b8df2017-07-24 14:22:25 -07001802 /* Asus T304UA */
1803 { .driver_data = MT_CLS_ASUS,
1804 HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8,
1805 USB_VENDOR_ID_ASUSTEK,
1806 USB_DEVICE_ID_ASUSTEK_T304_KEYBOARD) },
1807
Benjamin Tissoiresb1057122011-12-23 15:40:59 +01001808 /* Atmel panels */
1809 { .driver_data = MT_CLS_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001810 MT_USB_DEVICE(USB_VENDOR_ID_ATMEL,
Benjamin Tissoires841cb152012-03-06 10:53:45 +01001811 USB_DEVICE_ID_ATMEL_MXT_DIGITIZER) },
Benjamin Tissoiresb1057122011-12-23 15:40:59 +01001812
Jiri Kosina9ed32692012-04-20 12:15:44 +02001813 /* Baanto multitouch devices */
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01001814 { .driver_data = MT_CLS_NSMU,
Jiri Kosina16b79bb2012-05-05 23:32:54 +02001815 MT_USB_DEVICE(USB_VENDOR_ID_BAANTO,
Jiri Kosina9ed32692012-04-20 12:15:44 +02001816 USB_DEVICE_ID_BAANTO_MT_190W2) },
Benjamin Tissoires0fa9c612014-02-28 11:41:23 -05001817
Benjamin Tissoiresa841b622011-03-18 14:27:54 +01001818 /* Cando panels */
1819 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001820 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
Benjamin Tissoiresa841b622011-03-18 14:27:54 +01001821 USB_DEVICE_ID_CANDO_MULTI_TOUCH) },
Benjamin Tissoiresa841b622011-03-18 14:27:54 +01001822 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001823 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
Benjamin Tissoiresa841b622011-03-18 14:27:54 +01001824 USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6) },
1825
Austin Zhang942fd422011-05-28 02:03:47 +08001826 /* Chunghwa Telecom touch panels */
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01001827 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001828 MT_USB_DEVICE(USB_VENDOR_ID_CHUNGHWAT,
Austin Zhang942fd422011-05-28 02:03:47 +08001829 USB_DEVICE_ID_CHUNGHWAT_MULTITOUCH) },
1830
Kai-Heng Feng12d43aa2018-11-14 05:35:20 +00001831 /* Cirque devices */
1832 { .driver_data = MT_CLS_WIN_8_DUAL,
1833 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
1834 I2C_VENDOR_ID_CIRQUE,
1835 I2C_PRODUCT_ID_CIRQUE_121F) },
1836
Yang Bo070f63b2015-07-20 09:40:28 -07001837 /* CJTouch panels */
1838 { .driver_data = MT_CLS_NSMU,
1839 MT_USB_DEVICE(USB_VENDOR_ID_CJTOUCH,
1840 USB_DEVICE_ID_CJTOUCH_MULTI_TOUCH_0020) },
1841 { .driver_data = MT_CLS_NSMU,
1842 MT_USB_DEVICE(USB_VENDOR_ID_CJTOUCH,
1843 USB_DEVICE_ID_CJTOUCH_MULTI_TOUCH_0040) },
1844
Benjamin Tissoires79603dc2011-05-19 14:18:14 +02001845 /* CVTouch panels */
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01001846 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001847 MT_USB_DEVICE(USB_VENDOR_ID_CVTOUCH,
Benjamin Tissoires79603dc2011-05-19 14:18:14 +02001848 USB_DEVICE_ID_CVTOUCH_SCREEN) },
1849
Benjamin Tissoires22408282011-05-20 15:59:34 +02001850 /* eGalax devices (resistive) */
Benjamin Tissoirese36f6902011-11-23 10:54:31 +01001851 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001852 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +01001853 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480D) },
1854 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001855 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +01001856 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480E) },
Benjamin Tissoires22408282011-05-20 15:59:34 +02001857
1858 /* eGalax devices (capacitive) */
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +01001859 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001860 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +01001861 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7207) },
Benjamin Tissoirese36f6902011-11-23 10:54:31 +01001862 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001863 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +01001864 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_720C) },
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +01001865 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001866 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +01001867 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7224) },
Benjamin Tissoires2ce09df2012-03-06 17:57:02 +01001868 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001869 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoires2ce09df2012-03-06 17:57:02 +01001870 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_722A) },
Benjamin Tissoires22408282011-05-20 15:59:34 +02001871 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001872 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoires22408282011-05-20 15:59:34 +02001873 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_725E) },
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +01001874 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001875 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +01001876 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7262) },
Benjamin Tissoirese36f6902011-11-23 10:54:31 +01001877 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001878 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoires22408282011-05-20 15:59:34 +02001879 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_726B) },
Benjamin Tissoires22408282011-05-20 15:59:34 +02001880 { .driver_data = MT_CLS_EGALAX,
1881 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +01001882 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72A1) },
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +01001883 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001884 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +01001885 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72AA) },
Benjamin Tissoirese36f6902011-11-23 10:54:31 +01001886 { .driver_data = MT_CLS_EGALAX,
Andy Shevchenkoaa672da2013-05-17 14:34:48 +03001887 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
1888 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72C4) },
1889 { .driver_data = MT_CLS_EGALAX,
1890 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
1891 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72D0) },
1892 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001893 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoires66f06122011-11-23 10:54:33 +01001894 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72FA) },
1895 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001896 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Marek Vasutbb9ff212011-11-23 10:54:32 +01001897 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7302) },
Benjamin Tissoires1b723e82011-11-23 10:54:34 +01001898 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001899 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +01001900 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7349) },
1901 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001902 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Thierry Redingae01c9e2012-08-09 08:34:48 +02001903 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_73F7) },
1904 { .driver_data = MT_CLS_EGALAX_SERIAL,
1905 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +01001906 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_A001) },
Benjamin Tissoires22408282011-05-20 15:59:34 +02001907
Tomas Sokorai7c7606a2014-04-23 10:42:41 -04001908 /* Elitegroup panel */
1909 { .driver_data = MT_CLS_SERIAL,
1910 MT_USB_DEVICE(USB_VENDOR_ID_ELITEGROUP,
1911 USB_DEVICE_ID_ELITEGROUP_05D8) },
1912
Henrik Rydberg77723e32012-09-07 19:37:40 +02001913 /* Flatfrog Panels */
1914 { .driver_data = MT_CLS_FLATFROG,
1915 MT_USB_DEVICE(USB_VENDOR_ID_FLATFROG,
1916 USB_DEVICE_ID_MULTITOUCH_3200) },
1917
Benjamin Tissoires3db187e2014-01-23 16:33:14 -05001918 /* FocalTech Panels */
1919 { .driver_data = MT_CLS_SERIAL,
1920 MT_USB_DEVICE(USB_VENDOR_ID_CYGNAL,
1921 USB_DEVICE_ID_FOCALTECH_FTXXXX_MULTITOUCH) },
1922
Benjamin Tissoires5572da02011-01-07 23:47:27 +01001923 /* GeneralTouch panel */
Xianhan Yuf5ff4e12012-09-28 10:18:59 +08001924 { .driver_data = MT_CLS_GENERALTOUCH_TWOFINGERS,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001925 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
Benjamin Tissoires5572da02011-01-07 23:47:27 +01001926 USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS) },
Xianhan Yuf5ff4e12012-09-28 10:18:59 +08001927 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
1928 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1929 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PWT_TENFINGERS) },
Luosong7b226292013-10-02 11:20:00 +02001930 { .driver_data = MT_CLS_GENERALTOUCH_TWOFINGERS,
1931 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1932 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0101) },
1933 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
1934 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1935 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0102) },
1936 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
1937 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1938 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0106) },
1939 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
1940 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1941 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_010A) },
1942 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
1943 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1944 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_E100) },
Benjamin Tissoires5572da02011-01-07 23:47:27 +01001945
Andreas Nielsen4d5df5d2012-03-19 15:41:03 +01001946 /* Gametel game controller */
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01001947 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001948 MT_BT_DEVICE(USB_VENDOR_ID_FRUCTEL,
Andreas Nielsen4d5df5d2012-03-19 15:41:03 +01001949 USB_DEVICE_ID_GAMETEL_MT_MODE) },
1950
Benjamin Tissoiresee0fbd12011-05-19 14:18:15 +02001951 /* GoodTouch panels */
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01001952 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001953 MT_USB_DEVICE(USB_VENDOR_ID_GOODTOUCH,
Benjamin Tissoiresee0fbd12011-05-19 14:18:15 +02001954 USB_DEVICE_ID_GOODTOUCH_000f) },
1955
Benjamin Tissoires54580362011-11-29 13:13:12 +01001956 /* Hanvon panels */
1957 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001958 MT_USB_DEVICE(USB_VENDOR_ID_HANVON_ALT,
Benjamin Tissoires54580362011-11-29 13:13:12 +01001959 USB_DEVICE_ID_HANVON_ALT_MULTITOUCH) },
1960
Austin Zhang4e61f0d2011-05-09 23:54:14 +08001961 /* Ilitek dual touch panel */
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01001962 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001963 MT_USB_DEVICE(USB_VENDOR_ID_ILITEK,
Austin Zhang4e61f0d2011-05-09 23:54:14 +08001964 USB_DEVICE_ID_ILITEK_MULTITOUCH) },
1965
Benjamin Tissoiresf3287a92017-01-30 10:48:06 +01001966 /* LG Melfas panel */
1967 { .driver_data = MT_CLS_LG,
1968 HID_USB_DEVICE(USB_VENDOR_ID_LG,
1969 USB_DEVICE_ID_LG_MELFAS_MT) },
1970
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +02001971 /* MosArt panels */
1972 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001973 MT_USB_DEVICE(USB_VENDOR_ID_ASUS,
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +02001974 USB_DEVICE_ID_ASUS_T91MT)},
1975 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001976 MT_USB_DEVICE(USB_VENDOR_ID_ASUS,
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +02001977 USB_DEVICE_ID_ASUSTEK_MULTITOUCH_YFO) },
1978 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001979 MT_USB_DEVICE(USB_VENDOR_ID_TURBOX,
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +02001980 USB_DEVICE_ID_TURBOX_TOUCHSCREEN_MOSART) },
1981
Austin Hendrix4db703e2012-06-04 15:27:51 -07001982 /* Novatek Panel */
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01001983 { .driver_data = MT_CLS_NSMU,
Jiri Kosina4380d812012-06-06 16:28:33 +02001984 MT_USB_DEVICE(USB_VENDOR_ID_NOVATEK,
Austin Hendrix4db703e2012-06-04 15:27:51 -07001985 USB_DEVICE_ID_NOVATEK_PCT) },
1986
Benjamin Tissoiresa80e8032016-05-31 17:31:15 +02001987 /* Ntrig Panel */
1988 { .driver_data = MT_CLS_NSMU,
1989 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
1990 USB_VENDOR_ID_NTRIG, 0x1b05) },
1991
Hans de Goedefb55b402017-11-22 12:57:07 +01001992 /* Panasonic panels */
1993 { .driver_data = MT_CLS_PANASONIC,
1994 MT_USB_DEVICE(USB_VENDOR_ID_PANASONIC,
1995 USB_DEVICE_ID_PANABOARD_UBT780) },
1996 { .driver_data = MT_CLS_PANASONIC,
1997 MT_USB_DEVICE(USB_VENDOR_ID_PANASONIC,
1998 USB_DEVICE_ID_PANABOARD_UBT880) },
1999
Aaron Tianb7ea95f2011-12-15 11:09:06 +08002000 /* PixArt optical touch screen */
2001 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02002002 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
Aaron Tianb7ea95f2011-12-15 11:09:06 +08002003 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN) },
2004 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02002005 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
Aaron Tianb7ea95f2011-12-15 11:09:06 +08002006 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN1) },
2007 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02002008 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
Aaron Tianb7ea95f2011-12-15 11:09:06 +08002009 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN2) },
2010
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01002011 /* PixCir-based panels */
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +01002012 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02002013 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01002014 USB_DEVICE_ID_CANDO_PIXCIR_MULTI_TOUCH) },
2015
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +01002016 /* Quanta-based panels */
2017 { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02002018 MT_USB_DEVICE(USB_VENDOR_ID_QUANTA,
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +01002019 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3001) },
Forest Bonda6802e02013-10-21 12:38:49 -04002020
Benjamin Tissoires843e4752018-03-20 12:04:46 +01002021 /* Razer touchpads */
2022 { .driver_data = MT_CLS_RAZER_BLADE_STEALTH,
2023 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
2024 USB_VENDOR_ID_SYNAPTICS, 0x8323) },
2025
Benjamin Tissoires043b4032011-03-18 14:27:53 +01002026 /* Stantum panels */
Benjamin Tissoiresbf5af9b2011-05-19 14:18:18 +02002027 { .driver_data = MT_CLS_CONFIDENCE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02002028 MT_USB_DEVICE(USB_VENDOR_ID_STANTUM_STM,
Benjamin Tissoires043b4032011-03-18 14:27:53 +01002029 USB_DEVICE_ID_MTP_STM)},
Benjamin Tissoires043b4032011-03-18 14:27:53 +01002030
Benjamin Tissoires847672c2012-02-04 17:08:50 +01002031 /* TopSeed panels */
2032 { .driver_data = MT_CLS_TOPSEED,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02002033 MT_USB_DEVICE(USB_VENDOR_ID_TOPSEED2,
Benjamin Tissoires847672c2012-02-04 17:08:50 +01002034 USB_DEVICE_ID_TOPSEED2_PERIPAD_701) },
2035
Benjamin Tissoires5e74e562011-05-19 14:18:16 +02002036 /* Touch International panels */
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01002037 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02002038 MT_USB_DEVICE(USB_VENDOR_ID_TOUCH_INTL,
Benjamin Tissoires5e74e562011-05-19 14:18:16 +02002039 USB_DEVICE_ID_TOUCH_INTL_MULTI_TOUCH) },
2040
Benjamin Tissoires617b64f2011-05-19 14:18:17 +02002041 /* Unitec panels */
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01002042 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02002043 MT_USB_DEVICE(USB_VENDOR_ID_UNITEC,
Benjamin Tissoires617b64f2011-05-19 14:18:17 +02002044 USB_DEVICE_ID_UNITEC_USB_TOUCH_0709) },
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01002045 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02002046 MT_USB_DEVICE(USB_VENDOR_ID_UNITEC,
Benjamin Tissoires617b64f2011-05-19 14:18:17 +02002047 USB_DEVICE_ID_UNITEC_USB_TOUCH_0A19) },
KaiChung Chengbf9d1212013-11-21 10:04:30 +01002048
Mathieu Magnaudetda10bc22014-11-22 12:02:07 +01002049 /* VTL panels */
2050 { .driver_data = MT_CLS_VTL,
2051 MT_USB_DEVICE(USB_VENDOR_ID_VTL,
2052 USB_DEVICE_ID_VTL_MULTITOUCH_FF3F) },
2053
KaiChung Chengbf9d1212013-11-21 10:04:30 +01002054 /* Wistron panels */
2055 { .driver_data = MT_CLS_NSMU,
2056 MT_USB_DEVICE(USB_VENDOR_ID_WISTRON,
2057 USB_DEVICE_ID_WISTRON_OPTICAL_TOUCH) },
2058
ice chienbc8a2a92011-07-15 16:58:06 +08002059 /* XAT */
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01002060 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02002061 MT_USB_DEVICE(USB_VENDOR_ID_XAT,
ice chienbc8a2a92011-07-15 16:58:06 +08002062 USB_DEVICE_ID_XAT_CSR) },
Benjamin Tissoires617b64f2011-05-19 14:18:17 +02002063
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09002064 /* Xiroku */
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01002065 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02002066 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09002067 USB_DEVICE_ID_XIROKU_SPX) },
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01002068 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02002069 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09002070 USB_DEVICE_ID_XIROKU_MPX) },
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01002071 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02002072 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09002073 USB_DEVICE_ID_XIROKU_CSR) },
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01002074 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02002075 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09002076 USB_DEVICE_ID_XIROKU_SPX1) },
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01002077 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02002078 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09002079 USB_DEVICE_ID_XIROKU_MPX1) },
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01002080 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02002081 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09002082 USB_DEVICE_ID_XIROKU_CSR1) },
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01002083 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02002084 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09002085 USB_DEVICE_ID_XIROKU_SPX2) },
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01002086 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02002087 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09002088 USB_DEVICE_ID_XIROKU_MPX2) },
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01002089 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02002090 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09002091 USB_DEVICE_ID_XIROKU_CSR2) },
2092
Wei-Ning Huang0e822322017-06-21 10:43:25 +08002093 /* Google MT devices */
2094 { .driver_data = MT_CLS_GOOGLE,
2095 HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY, USB_VENDOR_ID_GOOGLE,
2096 USB_DEVICE_ID_GOOGLE_TOUCH_ROSE) },
2097
Henrik Rydberg4fa3a582012-05-01 08:40:01 +02002098 /* Generic MT device */
2099 { HID_DEVICE(HID_BUS_ANY, HID_GROUP_MULTITOUCH, HID_ANY_ID, HID_ANY_ID) },
Benjamin Tissoiresf961bd32013-08-22 14:51:08 +02002100
2101 /* Generic Win 8 certified MT device */
2102 { .driver_data = MT_CLS_WIN_8,
2103 HID_DEVICE(HID_BUS_ANY, HID_GROUP_MULTITOUCH_WIN_8,
2104 HID_ANY_ID, HID_ANY_ID) },
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01002105 { }
2106};
2107MODULE_DEVICE_TABLE(hid, mt_devices);
2108
2109static const struct hid_usage_id mt_grabbed_usages[] = {
2110 { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID },
2111 { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
2112};
2113
2114static struct hid_driver mt_driver = {
2115 .name = "hid-multitouch",
2116 .id_table = mt_devices,
2117 .probe = mt_probe,
2118 .remove = mt_remove,
2119 .input_mapping = mt_input_mapping,
2120 .input_mapped = mt_input_mapped,
Henrik Rydberg76f59022012-09-01 20:11:34 +02002121 .input_configured = mt_input_configured,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01002122 .feature_mapping = mt_feature_mapping,
2123 .usage_table = mt_grabbed_usages,
2124 .event = mt_event,
Benjamin Tissoires55978fa2013-01-31 17:22:24 +01002125 .report = mt_report,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01002126#ifdef CONFIG_PM
2127 .reset_resume = mt_reset_resume,
Scott Liudfeefd12012-08-15 17:21:55 +08002128 .resume = mt_resume,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01002129#endif
2130};
H Hartley Sweetenf4254582012-12-17 15:28:26 -07002131module_hid_driver(mt_driver);