blob: 40fbb7c52723378eaf32d351f9541dd7ef0d61e3 [file] [log] [blame]
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001/*
2 * HID driver for multitouch panels
3 *
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +01004 * Copyright (c) 2010-2012 Stephane Chatty <chatty@enac.fr>
Benjamin Tissoiresb0a78682013-02-25 11:31:49 +01005 * Copyright (c) 2010-2013 Benjamin Tissoires <benjamin.tissoires@gmail.com>
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +01006 * Copyright (c) 2010-2012 Ecole Nationale de l'Aviation Civile, France
Benjamin Tissoiresb0a78682013-02-25 11:31:49 +01007 * Copyright (c) 2012-2013 Red Hat, Inc
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01008 *
Richard Nauber4875ac12011-03-09 06:20:57 +01009 * This code is partly based on hid-egalax.c:
10 *
11 * Copyright (c) 2010 Stephane Chatty <chatty@enac.fr>
12 * Copyright (c) 2010 Henrik Rydberg <rydberg@euromail.se>
13 * Copyright (c) 2010 Canonical, Ltd.
14 *
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +010015 * This code is partly based on hid-3m-pct.c:
16 *
17 * Copyright (c) 2009-2010 Stephane Chatty <chatty@enac.fr>
18 * Copyright (c) 2010 Henrik Rydberg <rydberg@euromail.se>
19 * Copyright (c) 2010 Canonical, Ltd.
20 *
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010021 */
22
23/*
24 * This program is free software; you can redistribute it and/or modify it
25 * under the terms of the GNU General Public License as published by the Free
26 * Software Foundation; either version 2 of the License, or (at your option)
27 * any later version.
28 */
29
Benjamin Tissoiresb0a78682013-02-25 11:31:49 +010030/*
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +020031 * This driver is regularly tested thanks to the test suite in hid-tools[1].
Benjamin Tissoiresb0a78682013-02-25 11:31:49 +010032 * Please run these regression tests before patching this module so that
33 * your patch won't break existing known devices.
34 *
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +020035 * [1] https://gitlab.freedesktop.org/libevdev/hid-tools
Benjamin Tissoiresb0a78682013-02-25 11:31:49 +010036 */
37
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010038#include <linux/device.h>
39#include <linux/hid.h>
40#include <linux/module.h>
41#include <linux/slab.h>
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010042#include <linux/input/mt.h>
Nicolas Boichat29cc3092017-08-22 09:10:11 +080043#include <linux/jiffies.h>
Benjamin Tissoires49a5a822013-03-22 18:38:33 +010044#include <linux/string.h>
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +020045#include <linux/timer.h>
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010046
47
48MODULE_AUTHOR("Stephane Chatty <chatty@enac.fr>");
Benjamin Tissoiresef2fafb2011-01-31 11:28:21 +010049MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>");
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010050MODULE_DESCRIPTION("HID multitouch panels");
51MODULE_LICENSE("GPL");
52
53#include "hid-ids.h"
54
55/* quirks to control the device */
Benjamin Tissoiresfd911892017-06-15 15:32:03 +020056#define MT_QUIRK_NOT_SEEN_MEANS_UP BIT(0)
57#define MT_QUIRK_SLOT_IS_CONTACTID BIT(1)
58#define MT_QUIRK_CYPRESS BIT(2)
59#define MT_QUIRK_SLOT_IS_CONTACTNUMBER BIT(3)
60#define MT_QUIRK_ALWAYS_VALID BIT(4)
61#define MT_QUIRK_VALID_IS_INRANGE BIT(5)
62#define MT_QUIRK_VALID_IS_CONFIDENCE BIT(6)
63#define MT_QUIRK_CONFIDENCE BIT(7)
64#define MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE BIT(8)
65#define MT_QUIRK_NO_AREA BIT(9)
66#define MT_QUIRK_IGNORE_DUPLICATES BIT(10)
67#define MT_QUIRK_HOVERING BIT(11)
68#define MT_QUIRK_CONTACT_CNT_ACCURATE BIT(12)
69#define MT_QUIRK_FORCE_GET_FEATURE BIT(13)
70#define MT_QUIRK_FIX_CONST_CONTACT_ID BIT(14)
71#define MT_QUIRK_TOUCH_SIZE_SCALING BIT(15)
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +020072#define MT_QUIRK_STICKY_FINGERS BIT(16)
João Paulo Rechi Vita957b8df2017-07-24 14:22:25 -070073#define MT_QUIRK_ASUS_CUSTOM_UP BIT(17)
Benjamin Tissoiresd9c57a72018-03-20 12:04:45 +010074#define MT_QUIRK_WIN8_PTP_BUTTONS BIT(18)
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010075
Andrew Duggan9abebed2014-03-19 13:39:03 -070076#define MT_INPUTMODE_TOUCHSCREEN 0x02
77#define MT_INPUTMODE_TOUCHPAD 0x03
78
Seth Forshee2c6e0272015-03-11 17:26:41 -050079#define MT_BUTTONTYPE_CLICKPAD 0
80
Benjamin Tissoires02946f42018-04-24 10:04:37 +020081enum latency_mode {
82 HID_LATENCY_NORMAL = 0,
83 HID_LATENCY_HIGH = 1,
84};
85
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +020086#define MT_IO_FLAGS_RUNNING 0
Benjamin Tissoires96098272017-06-15 15:32:05 +020087#define MT_IO_FLAGS_ACTIVE_SLOTS 1
88#define MT_IO_FLAGS_PENDING_SLOTS 2
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +020089
Benjamin Tissoires01eaac72018-07-13 16:13:48 +020090static const bool mtrue = true; /* default for true */
91static const bool mfalse; /* default for false */
92static const __s32 mzero; /* default for 0 */
93
94#define DEFAULT_TRUE ((void *)&mtrue)
95#define DEFAULT_FALSE ((void *)&mfalse)
96#define DEFAULT_ZERO ((void *)&mzero)
97
98struct mt_usages {
99 struct list_head list;
100 __s32 *x, *y, *cx, *cy, *p, *w, *h, *a;
101 __s32 *contactid; /* the device ContactID assigned to this slot */
102 bool *tip_state; /* is the touch valid? */
103 bool *inrange_state; /* is the finger in proximity of the sensor? */
104 bool *confidence_state; /* is the touch made by a finger? */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100105};
106
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200107struct mt_application {
108 struct list_head list;
109 unsigned int application;
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200110 struct list_head mt_usages; /* mt usages list */
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +0200111
112 __s32 quirks;
113
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200114 __s32 *scantime; /* scantime reported */
115 __s32 scantime_logical_max; /* max value for raw scantime */
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200116
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200117 __s32 *raw_cc; /* contact count in the report */
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200118 int left_button_state; /* left button state */
119 unsigned int mt_flags; /* flags to pass to input-mt */
120
Dmitry Torokhov28a042a2018-07-13 16:13:54 +0200121 unsigned long *pending_palm_slots; /* slots where we reported palm
122 * and need to release */
123
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200124 __u8 num_received; /* how many contacts we received */
125 __u8 num_expected; /* expected last contact index */
126 __u8 buttons_count; /* number of physical buttons per touchpad */
127 __u8 touches_by_report; /* how many touches are present in one report:
128 * 1 means we should use a serial protocol
129 * > 1 means hybrid (multitouch) protocol
130 */
131
132 __s32 dev_time; /* the scan time provided by the device */
133 unsigned long jiffies; /* the frame's jiffies */
134 int timestamp; /* the timestamp to be sent */
135 int prev_scantime; /* scantime reported previously */
136
137 bool have_contact_count;
138};
139
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100140struct mt_class {
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100141 __s32 name; /* MT_CLS */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100142 __s32 quirks;
143 __s32 sn_move; /* Signal/noise ratio for move events */
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100144 __s32 sn_width; /* Signal/noise ratio for width events */
145 __s32 sn_height; /* Signal/noise ratio for height events */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100146 __s32 sn_pressure; /* Signal/noise ratio for pressure events */
147 __u8 maxcontacts;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100148 bool is_indirect; /* true for touchpads */
Benjamin Tissoires6aef7042014-02-28 11:41:25 -0500149 bool export_all_inputs; /* do not ignore mouse, keyboards, etc... */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100150};
151
Benjamin Tissoires8dfe14b2018-07-13 16:13:47 +0200152struct mt_report_data {
153 struct list_head list;
154 struct hid_report *report;
155 struct mt_application *application;
156 bool is_mt_collection;
157};
158
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100159struct mt_device {
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100160 struct mt_class mtclass; /* our mt device class */
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +0200161 struct timer_list release_timer; /* to release sticky fingers */
Kees Cook0ee32772017-10-04 17:53:24 -0700162 struct hid_device *hdev; /* hid_device we're attached to */
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +0200163 unsigned long mt_io_flags; /* mt flags (MT_IO_FLAGS_*) */
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +0200164 __u8 inputmode_value; /* InputMode HID feature value */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100165 __u8 maxcontacts;
Seth Forshee2c6e0272015-03-11 17:26:41 -0500166 bool is_buttonpad; /* is this device a button pad? */
Henrik Rydberg76f59022012-09-01 20:11:34 +0200167 bool serial_maybe; /* need to check for serial protocol */
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200168
169 struct list_head applications;
Benjamin Tissoires8dfe14b2018-07-13 16:13:47 +0200170 struct list_head reports;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100171};
172
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200173static void mt_post_parse_default_settings(struct mt_device *td,
174 struct mt_application *app);
175static void mt_post_parse(struct mt_device *td, struct mt_application *app);
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +0100176
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100177/* classes of device behavior */
Benjamin Tissoires22408282011-05-20 15:59:34 +0200178#define MT_CLS_DEFAULT 0x0001
179
Stephane Chattya062cc52011-09-17 22:27:30 +0200180#define MT_CLS_SERIAL 0x0002
181#define MT_CLS_CONFIDENCE 0x0003
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +0100182#define MT_CLS_CONFIDENCE_CONTACT_ID 0x0004
183#define MT_CLS_CONFIDENCE_MINUS_ONE 0x0005
184#define MT_CLS_DUAL_INRANGE_CONTACTID 0x0006
185#define MT_CLS_DUAL_INRANGE_CONTACTNUMBER 0x0007
Benjamin Tissoires0fa9c612014-02-28 11:41:23 -0500186/* reserved 0x0008 */
Aaron Tianb7ea95f2011-12-15 11:09:06 +0800187#define MT_CLS_INRANGE_CONTACTNUMBER 0x0009
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +0100188#define MT_CLS_NSMU 0x000a
Benjamin Tissoires0fa9c612014-02-28 11:41:23 -0500189/* reserved 0x0010 */
190/* reserved 0x0011 */
Benjamin Tissoiresf961bd32013-08-22 14:51:08 +0200191#define MT_CLS_WIN_8 0x0012
Benjamin Tissoires6aef7042014-02-28 11:41:25 -0500192#define MT_CLS_EXPORT_ALL_INPUTS 0x0013
Masaki Ota504c9322017-06-16 09:29:39 +0900193#define MT_CLS_WIN_8_DUAL 0x0014
Benjamin Tissoires22408282011-05-20 15:59:34 +0200194
195/* vendor specific classes */
196#define MT_CLS_3M 0x0101
Benjamin Tissoires0fa9c612014-02-28 11:41:23 -0500197/* reserved 0x0102 */
Benjamin Tissoires22408282011-05-20 15:59:34 +0200198#define MT_CLS_EGALAX 0x0103
Benjamin Tissoires1b723e82011-11-23 10:54:34 +0100199#define MT_CLS_EGALAX_SERIAL 0x0104
Benjamin Tissoires847672c2012-02-04 17:08:50 +0100200#define MT_CLS_TOPSEED 0x0105
Denis Kovalev2258e862012-02-14 00:50:33 -0800201#define MT_CLS_PANASONIC 0x0106
Henrik Rydberg77723e32012-09-07 19:37:40 +0200202#define MT_CLS_FLATFROG 0x0107
Jiri Kosinacdcd3ac2012-10-01 14:38:54 +0200203#define MT_CLS_GENERALTOUCH_TWOFINGERS 0x0108
204#define MT_CLS_GENERALTOUCH_PWT_TENFINGERS 0x0109
Benjamin Tissoiresf3287a92017-01-30 10:48:06 +0100205#define MT_CLS_LG 0x010a
João Paulo Rechi Vita957b8df2017-07-24 14:22:25 -0700206#define MT_CLS_ASUS 0x010b
Mathieu Magnaudetda10bc22014-11-22 12:02:07 +0100207#define MT_CLS_VTL 0x0110
Wei-Ning Huang0e822322017-06-21 10:43:25 +0800208#define MT_CLS_GOOGLE 0x0111
Benjamin Tissoires843e4752018-03-20 12:04:46 +0100209#define MT_CLS_RAZER_BLADE_STEALTH 0x0112
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100210
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100211#define MT_DEFAULT_MAXCONTACT 10
Benjamin Tissoiresafbcb042012-11-14 16:59:18 +0100212#define MT_MAX_MAXCONTACT 250
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100213
Nicolas Boichat29cc3092017-08-22 09:10:11 +0800214/*
215 * Resync device and local timestamps after that many microseconds without
216 * receiving data.
217 */
218#define MAX_TIMESTAMP_INTERVAL 1000000
219
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200220#define MT_USB_DEVICE(v, p) HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH, v, p)
221#define MT_BT_DEVICE(v, p) HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_MULTITOUCH, v, p)
222
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100223/*
224 * these device-dependent functions determine what slot corresponds
225 * to a valid contact that was just read.
226 */
227
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200228static int cypress_compute_slot(struct mt_application *application,
229 struct mt_usages *slot)
Benjamin Tissoiresa3b5e572011-01-07 23:46:30 +0100230{
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200231 if (*slot->contactid != 0 || application->num_received == 0)
232 return *slot->contactid;
Benjamin Tissoiresa3b5e572011-01-07 23:46:30 +0100233 else
234 return -1;
235}
236
Benjamin Tissoirescf6d15d2018-07-13 16:13:44 +0200237static const struct mt_class mt_classes[] = {
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100238 { .name = MT_CLS_DEFAULT,
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +0100239 .quirks = MT_QUIRK_ALWAYS_VALID |
240 MT_QUIRK_CONTACT_CNT_ACCURATE },
241 { .name = MT_CLS_NSMU,
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100242 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP },
Stephane Chattya062cc52011-09-17 22:27:30 +0200243 { .name = MT_CLS_SERIAL,
244 .quirks = MT_QUIRK_ALWAYS_VALID},
Benjamin Tissoires22408282011-05-20 15:59:34 +0200245 { .name = MT_CLS_CONFIDENCE,
246 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE },
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +0100247 { .name = MT_CLS_CONFIDENCE_CONTACT_ID,
248 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
249 MT_QUIRK_SLOT_IS_CONTACTID },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200250 { .name = MT_CLS_CONFIDENCE_MINUS_ONE,
251 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
252 MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE },
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +0100253 { .name = MT_CLS_DUAL_INRANGE_CONTACTID,
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100254 .quirks = MT_QUIRK_VALID_IS_INRANGE |
255 MT_QUIRK_SLOT_IS_CONTACTID,
256 .maxcontacts = 2 },
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +0100257 { .name = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100258 .quirks = MT_QUIRK_VALID_IS_INRANGE |
259 MT_QUIRK_SLOT_IS_CONTACTNUMBER,
260 .maxcontacts = 2 },
Aaron Tianb7ea95f2011-12-15 11:09:06 +0800261 { .name = MT_CLS_INRANGE_CONTACTNUMBER,
262 .quirks = MT_QUIRK_VALID_IS_INRANGE |
263 MT_QUIRK_SLOT_IS_CONTACTNUMBER },
Benjamin Tissoiresf961bd32013-08-22 14:51:08 +0200264 { .name = MT_CLS_WIN_8,
265 .quirks = MT_QUIRK_ALWAYS_VALID |
266 MT_QUIRK_IGNORE_DUPLICATES |
267 MT_QUIRK_HOVERING |
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +0200268 MT_QUIRK_CONTACT_CNT_ACCURATE |
Benjamin Tissoiresd9c57a72018-03-20 12:04:45 +0100269 MT_QUIRK_STICKY_FINGERS |
270 MT_QUIRK_WIN8_PTP_BUTTONS },
Benjamin Tissoires6aef7042014-02-28 11:41:25 -0500271 { .name = MT_CLS_EXPORT_ALL_INPUTS,
272 .quirks = MT_QUIRK_ALWAYS_VALID |
273 MT_QUIRK_CONTACT_CNT_ACCURATE,
274 .export_all_inputs = true },
Masaki Ota504c9322017-06-16 09:29:39 +0900275 { .name = MT_CLS_WIN_8_DUAL,
276 .quirks = MT_QUIRK_ALWAYS_VALID |
277 MT_QUIRK_IGNORE_DUPLICATES |
278 MT_QUIRK_HOVERING |
Benjamin Tissoiresd9c57a72018-03-20 12:04:45 +0100279 MT_QUIRK_CONTACT_CNT_ACCURATE |
280 MT_QUIRK_WIN8_PTP_BUTTONS,
Masaki Ota504c9322017-06-16 09:29:39 +0900281 .export_all_inputs = true },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200282
283 /*
284 * vendor specific classes
285 */
286 { .name = MT_CLS_3M,
287 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
HungNien Chene9d0a262017-03-06 11:30:14 +0800288 MT_QUIRK_SLOT_IS_CONTACTID |
289 MT_QUIRK_TOUCH_SIZE_SCALING,
Benjamin Tissoires22408282011-05-20 15:59:34 +0200290 .sn_move = 2048,
291 .sn_width = 128,
Henrik Rydbergc5d40be2012-09-05 16:58:12 +0200292 .sn_height = 128,
293 .maxcontacts = 60,
294 },
Richard Nauber4875ac12011-03-09 06:20:57 +0100295 { .name = MT_CLS_EGALAX,
296 .quirks = MT_QUIRK_SLOT_IS_CONTACTID |
Benjamin Tissoires2261bb92011-11-23 10:54:29 +0100297 MT_QUIRK_VALID_IS_INRANGE,
Richard Nauber4875ac12011-03-09 06:20:57 +0100298 .sn_move = 4096,
299 .sn_pressure = 32,
300 },
Benjamin Tissoires1b723e82011-11-23 10:54:34 +0100301 { .name = MT_CLS_EGALAX_SERIAL,
302 .quirks = MT_QUIRK_SLOT_IS_CONTACTID |
303 MT_QUIRK_ALWAYS_VALID,
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100304 .sn_move = 4096,
305 .sn_pressure = 32,
306 },
Benjamin Tissoires847672c2012-02-04 17:08:50 +0100307 { .name = MT_CLS_TOPSEED,
308 .quirks = MT_QUIRK_ALWAYS_VALID,
309 .is_indirect = true,
310 .maxcontacts = 2,
311 },
Denis Kovalev2258e862012-02-14 00:50:33 -0800312 { .name = MT_CLS_PANASONIC,
313 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP,
314 .maxcontacts = 4 },
Xianhan Yuf5ff4e12012-09-28 10:18:59 +0800315 { .name = MT_CLS_GENERALTOUCH_TWOFINGERS,
316 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
317 MT_QUIRK_VALID_IS_INRANGE |
Luosong7b226292013-10-02 11:20:00 +0200318 MT_QUIRK_SLOT_IS_CONTACTID,
Xianhan Yuf5ff4e12012-09-28 10:18:59 +0800319 .maxcontacts = 2
320 },
321 { .name = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
322 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
Luosong7b226292013-10-02 11:20:00 +0200323 MT_QUIRK_SLOT_IS_CONTACTID
Xianhan Yuf5ff4e12012-09-28 10:18:59 +0800324 },
Benjamin Tissoires043b4032011-03-18 14:27:53 +0100325
Henrik Rydberg77723e32012-09-07 19:37:40 +0200326 { .name = MT_CLS_FLATFROG,
327 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
328 MT_QUIRK_NO_AREA,
329 .sn_move = 2048,
330 .maxcontacts = 40,
331 },
Benjamin Tissoiresf3287a92017-01-30 10:48:06 +0100332 { .name = MT_CLS_LG,
333 .quirks = MT_QUIRK_ALWAYS_VALID |
334 MT_QUIRK_FIX_CONST_CONTACT_ID |
335 MT_QUIRK_IGNORE_DUPLICATES |
336 MT_QUIRK_HOVERING |
337 MT_QUIRK_CONTACT_CNT_ACCURATE },
João Paulo Rechi Vita957b8df2017-07-24 14:22:25 -0700338 { .name = MT_CLS_ASUS,
339 .quirks = MT_QUIRK_ALWAYS_VALID |
340 MT_QUIRK_CONTACT_CNT_ACCURATE |
341 MT_QUIRK_ASUS_CUSTOM_UP },
Mathieu Magnaudetda10bc22014-11-22 12:02:07 +0100342 { .name = MT_CLS_VTL,
343 .quirks = MT_QUIRK_ALWAYS_VALID |
344 MT_QUIRK_CONTACT_CNT_ACCURATE |
345 MT_QUIRK_FORCE_GET_FEATURE,
346 },
Wei-Ning Huang0e822322017-06-21 10:43:25 +0800347 { .name = MT_CLS_GOOGLE,
348 .quirks = MT_QUIRK_ALWAYS_VALID |
349 MT_QUIRK_CONTACT_CNT_ACCURATE |
350 MT_QUIRK_SLOT_IS_CONTACTID |
351 MT_QUIRK_HOVERING
352 },
Benjamin Tissoires843e4752018-03-20 12:04:46 +0100353 { .name = MT_CLS_RAZER_BLADE_STEALTH,
354 .quirks = MT_QUIRK_ALWAYS_VALID |
355 MT_QUIRK_IGNORE_DUPLICATES |
356 MT_QUIRK_HOVERING |
357 MT_QUIRK_CONTACT_CNT_ACCURATE |
358 MT_QUIRK_WIN8_PTP_BUTTONS,
359 },
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100360 { }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100361};
362
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100363static ssize_t mt_show_quirks(struct device *dev,
364 struct device_attribute *attr,
365 char *buf)
366{
Geliang Tangee79a8f2015-12-27 17:25:21 +0800367 struct hid_device *hdev = to_hid_device(dev);
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100368 struct mt_device *td = hid_get_drvdata(hdev);
369
370 return sprintf(buf, "%u\n", td->mtclass.quirks);
371}
372
373static ssize_t mt_set_quirks(struct device *dev,
374 struct device_attribute *attr,
375 const char *buf, size_t count)
376{
Geliang Tangee79a8f2015-12-27 17:25:21 +0800377 struct hid_device *hdev = to_hid_device(dev);
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100378 struct mt_device *td = hid_get_drvdata(hdev);
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200379 struct mt_application *application;
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100380
381 unsigned long val;
382
383 if (kstrtoul(buf, 0, &val))
384 return -EINVAL;
385
386 td->mtclass.quirks = val;
387
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200388 list_for_each_entry(application, &td->applications, list) {
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +0200389 application->quirks = val;
390 if (!application->have_contact_count)
391 application->quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE;
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200392 }
393
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100394 return count;
395}
396
397static DEVICE_ATTR(quirks, S_IWUSR | S_IRUGO, mt_show_quirks, mt_set_quirks);
398
399static struct attribute *sysfs_attrs[] = {
400 &dev_attr_quirks.attr,
401 NULL
402};
403
Arvind Yadav9182fb92017-08-03 16:56:43 +0530404static const struct attribute_group mt_attribute_group = {
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100405 .attrs = sysfs_attrs
406};
407
Mika Westerberg6d4f5442015-10-07 15:33:43 +0300408static void mt_get_feature(struct hid_device *hdev, struct hid_report *report)
409{
Aaron Ma3064a032018-02-03 23:57:15 +0800410 int ret;
411 u32 size = hid_report_len(report);
Mika Westerberg6d4f5442015-10-07 15:33:43 +0300412 u8 *buf;
413
414 /*
Benjamin Tissoiresb897f6d2016-11-25 14:27:22 +0100415 * Do not fetch the feature report if the device has been explicitly
416 * marked as non-capable.
Mika Westerberg6d4f5442015-10-07 15:33:43 +0300417 */
Benjamin Tissoiresadaabbf2018-03-20 12:04:50 +0100418 if (hdev->quirks & HID_QUIRK_NO_INIT_REPORTS)
Mika Westerberg6d4f5442015-10-07 15:33:43 +0300419 return;
420
421 buf = hid_alloc_report_buf(report, GFP_KERNEL);
422 if (!buf)
423 return;
424
425 ret = hid_hw_raw_request(hdev, report->id, buf, size,
426 HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
427 if (ret < 0) {
428 dev_warn(&hdev->dev, "failed to fetch feature %d\n",
429 report->id);
430 } else {
431 ret = hid_report_raw_event(hdev, HID_FEATURE_REPORT, buf,
432 size, 0);
433 if (ret)
434 dev_warn(&hdev->dev, "failed to report feature\n");
435 }
436
437 kfree(buf);
438}
439
Henrik Rydbergf635bd12011-02-24 19:30:59 +0100440static void mt_feature_mapping(struct hid_device *hdev,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100441 struct hid_field *field, struct hid_usage *usage)
442{
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100443 struct mt_device *td = hid_get_drvdata(hdev);
444
445 switch (usage->hid) {
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100446 case HID_DG_CONTACTMAX:
Mika Westerberg6d4f5442015-10-07 15:33:43 +0300447 mt_get_feature(hdev, field->report);
448
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100449 td->maxcontacts = field->value[0];
Benjamin Tissoiresafbcb042012-11-14 16:59:18 +0100450 if (!td->maxcontacts &&
451 field->logical_maximum <= MT_MAX_MAXCONTACT)
452 td->maxcontacts = field->logical_maximum;
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100453 if (td->mtclass.maxcontacts)
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100454 /* check if the maxcontacts is given by the class */
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100455 td->maxcontacts = td->mtclass.maxcontacts;
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100456
457 break;
Seth Forshee2c6e0272015-03-11 17:26:41 -0500458 case HID_DG_BUTTONTYPE:
459 if (usage->usage_index >= field->report_count) {
460 dev_err(&hdev->dev, "HID_DG_BUTTONTYPE out of range\n");
461 break;
462 }
463
Mika Westerberg6d4f5442015-10-07 15:33:43 +0300464 mt_get_feature(hdev, field->report);
Seth Forshee2c6e0272015-03-11 17:26:41 -0500465 if (field->value[usage->usage_index] == MT_BUTTONTYPE_CLICKPAD)
466 td->is_buttonpad = true;
467
468 break;
Benjamin Tissoires45c5c682016-03-07 11:02:38 +0100469 case 0xff0000c5:
470 /* Retrieve the Win8 blob once to enable some devices */
471 if (usage->usage_index == 0)
472 mt_get_feature(hdev, field->report);
473 break;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100474 }
475}
476
477static void set_abs(struct input_dev *input, unsigned int code,
478 struct hid_field *field, int snratio)
479{
480 int fmin = field->logical_minimum;
481 int fmax = field->logical_maximum;
482 int fuzz = snratio ? (fmax - fmin) / snratio : 0;
483 input_set_abs_params(input, code, fmin, fmax, fuzz, 0);
Benjamin Tissoires37cf6e62012-11-14 16:59:13 +0100484 input_abs_set_res(input, code, hidinput_calc_abs_res(field, code));
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100485}
486
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200487static struct mt_usages *mt_allocate_usage(struct hid_device *hdev,
488 struct mt_application *application)
489{
490 struct mt_usages *usage;
491
492 usage = devm_kzalloc(&hdev->dev, sizeof(*usage), GFP_KERNEL);
493 if (!usage)
494 return NULL;
495
496 /* set some defaults so we do not need to check for null pointers */
497 usage->x = DEFAULT_ZERO;
498 usage->y = DEFAULT_ZERO;
499 usage->cx = DEFAULT_ZERO;
500 usage->cy = DEFAULT_ZERO;
501 usage->p = DEFAULT_ZERO;
502 usage->w = DEFAULT_ZERO;
503 usage->h = DEFAULT_ZERO;
504 usage->a = DEFAULT_ZERO;
505 usage->contactid = DEFAULT_ZERO;
506 usage->tip_state = DEFAULT_FALSE;
507 usage->inrange_state = DEFAULT_FALSE;
508 usage->confidence_state = DEFAULT_TRUE;
509
510 list_add_tail(&usage->list, &application->mt_usages);
511
512 return usage;
513}
514
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200515static struct mt_application *mt_allocate_application(struct mt_device *td,
516 unsigned int application)
517{
518 struct mt_application *mt_application;
519
520 mt_application = devm_kzalloc(&td->hdev->dev, sizeof(*mt_application),
521 GFP_KERNEL);
522 if (!mt_application)
523 return NULL;
524
525 mt_application->application = application;
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200526 INIT_LIST_HEAD(&mt_application->mt_usages);
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200527
528 if (application == HID_DG_TOUCHSCREEN)
529 mt_application->mt_flags |= INPUT_MT_DIRECT;
530
531 /*
532 * Model touchscreens providing buttons as touchpads.
533 */
534 if (application == HID_DG_TOUCHPAD) {
535 mt_application->mt_flags |= INPUT_MT_POINTER;
536 td->inputmode_value = MT_INPUTMODE_TOUCHPAD;
537 }
538
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200539 mt_application->scantime = DEFAULT_ZERO;
540 mt_application->raw_cc = DEFAULT_ZERO;
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +0200541 mt_application->quirks = td->mtclass.quirks;
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200542
543 list_add_tail(&mt_application->list, &td->applications);
544
545 return mt_application;
546}
547
548static struct mt_application *mt_find_application(struct mt_device *td,
549 unsigned int application)
550{
551 struct mt_application *tmp, *mt_application = NULL;
552
553 list_for_each_entry(tmp, &td->applications, list) {
554 if (application == tmp->application) {
555 mt_application = tmp;
556 break;
557 }
558 }
559
560 if (!mt_application)
561 mt_application = mt_allocate_application(td, application);
562
563 return mt_application;
564}
565
Benjamin Tissoires8dfe14b2018-07-13 16:13:47 +0200566static struct mt_report_data *mt_allocate_report_data(struct mt_device *td,
567 struct hid_report *report)
568{
569 struct mt_report_data *rdata;
570 struct hid_field *field;
571 int r, n;
572
573 rdata = devm_kzalloc(&td->hdev->dev, sizeof(*rdata), GFP_KERNEL);
574 if (!rdata)
575 return NULL;
576
577 rdata->report = report;
578 rdata->application = mt_find_application(td, report->application);
579
580 if (!rdata->application) {
581 devm_kfree(&td->hdev->dev, rdata);
582 return NULL;
583 }
584
585 for (r = 0; r < report->maxfield; r++) {
586 field = report->field[r];
587
588 if (!(HID_MAIN_ITEM_VARIABLE & field->flags))
589 continue;
590
591 for (n = 0; n < field->report_count; n++) {
592 if (field->usage[n].hid == HID_DG_CONTACTID)
593 rdata->is_mt_collection = true;
594 }
595 }
596
597 list_add_tail(&rdata->list, &td->reports);
598
599 return rdata;
600}
601
602static struct mt_report_data *mt_find_report_data(struct mt_device *td,
603 struct hid_report *report)
604{
605 struct mt_report_data *tmp, *rdata = NULL;
606
607 list_for_each_entry(tmp, &td->reports, list) {
608 if (report == tmp->report) {
609 rdata = tmp;
610 break;
611 }
612 }
613
614 if (!rdata)
615 rdata = mt_allocate_report_data(td, report);
616
617 return rdata;
618}
619
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200620static void mt_store_field(struct hid_device *hdev,
621 struct mt_application *application,
622 __s32 *value,
623 size_t offset)
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100624{
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200625 struct mt_usages *usage;
626 __s32 **target;
Benjamin Tissoires3ac36d152012-05-04 14:53:46 +0200627
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200628 if (list_empty(&application->mt_usages))
629 usage = mt_allocate_usage(hdev, application);
630 else
631 usage = list_last_entry(&application->mt_usages,
632 struct mt_usages,
633 list);
634
635 if (!usage)
Benjamin Tissoires3ac36d152012-05-04 14:53:46 +0200636 return;
637
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200638 target = (__s32 **)((char *)usage + offset);
639
640 /* the value has already been filled, create a new slot */
641 if (*target != DEFAULT_TRUE &&
642 *target != DEFAULT_FALSE &&
643 *target != DEFAULT_ZERO) {
644 usage = mt_allocate_usage(hdev, application);
645 if (!usage)
646 return;
647
648 target = (__s32 **)((char *)usage + offset);
649 }
650
651 *target = value;
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100652}
653
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200654#define MT_STORE_FIELD(__name) \
655 mt_store_field(hdev, app, \
656 &field->value[usage->usage_index], \
657 offsetof(struct mt_usages, __name))
658
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +0100659static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100660 struct hid_field *field, struct hid_usage *usage,
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200661 unsigned long **bit, int *max, struct mt_application *app)
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100662{
663 struct mt_device *td = hid_get_drvdata(hdev);
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100664 struct mt_class *cls = &td->mtclass;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100665 int code;
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100666 struct hid_usage *prev_usage = NULL;
Richard Nauber4875ac12011-03-09 06:20:57 +0100667
Henrik Rydberg76f59022012-09-01 20:11:34 +0200668 /*
669 * Model touchscreens providing buttons as touchpads.
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100670 */
Benjamin Tissoiresba6b0552018-07-13 16:13:49 +0200671 if (field->application == HID_DG_TOUCHSCREEN &&
672 (usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON) {
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200673 app->mt_flags |= INPUT_MT_POINTER;
Andrew Duggan9abebed2014-03-19 13:39:03 -0700674 td->inputmode_value = MT_INPUTMODE_TOUCHPAD;
675 }
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100676
Benjamin Tissoires015fdaa2015-03-06 11:14:42 -0500677 /* count the buttons on touchpads */
678 if ((usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON)
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200679 app->buttons_count++;
Benjamin Tissoires015fdaa2015-03-06 11:14:42 -0500680
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100681 if (usage->usage_index)
682 prev_usage = &field->usage[usage->usage_index - 1];
683
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100684 switch (usage->hid & HID_USAGE_PAGE) {
685
686 case HID_UP_GENDESK:
687 switch (usage->hid) {
688 case HID_GD_X:
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200689 if (prev_usage && (prev_usage->hid == usage->hid)) {
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200690 code = ABS_MT_TOOL_X;
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200691 MT_STORE_FIELD(cx);
692 } else {
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200693 code = ABS_MT_POSITION_X;
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200694 MT_STORE_FIELD(x);
695 }
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100696
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200697 set_abs(hi->input, code, field, cls->sn_move);
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200698
Benjamin Tissoiresba6b0552018-07-13 16:13:49 +0200699 /*
700 * A system multi-axis that exports X and Y has a high
701 * chance of being used directly on a surface
702 */
703 if (field->application == HID_GD_SYSTEM_MULTIAXIS) {
704 __set_bit(INPUT_PROP_DIRECT,
705 hi->input->propbit);
706 input_set_abs_params(hi->input,
707 ABS_MT_TOOL_TYPE,
708 MT_TOOL_DIAL,
709 MT_TOOL_DIAL, 0, 0);
710 }
711
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100712 return 1;
713 case HID_GD_Y:
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200714 if (prev_usage && (prev_usage->hid == usage->hid)) {
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200715 code = ABS_MT_TOOL_Y;
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200716 MT_STORE_FIELD(cy);
717 } else {
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200718 code = ABS_MT_POSITION_Y;
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200719 MT_STORE_FIELD(y);
720 }
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100721
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200722 set_abs(hi->input, code, field, cls->sn_move);
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200723
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100724 return 1;
725 }
726 return 0;
727
728 case HID_UP_DIGITIZER:
729 switch (usage->hid) {
730 case HID_DG_INRANGE:
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +0200731 if (app->quirks & MT_QUIRK_HOVERING) {
Benjamin Tissoires9b3bb9b82012-11-14 16:59:24 +0100732 input_set_abs_params(hi->input,
733 ABS_MT_DISTANCE, 0, 1, 0, 0);
734 }
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200735 MT_STORE_FIELD(inrange_state);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100736 return 1;
737 case HID_DG_CONFIDENCE:
Masaki Ota504c9322017-06-16 09:29:39 +0900738 if ((cls->name == MT_CLS_WIN_8 ||
739 cls->name == MT_CLS_WIN_8_DUAL) &&
Dmitry Torokhovf9024372018-07-13 16:13:53 +0200740 (field->application == HID_DG_TOUCHPAD ||
741 field->application == HID_DG_TOUCHSCREEN))
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +0200742 app->quirks |= MT_QUIRK_CONFIDENCE;
Dmitry Torokhov9152c7d2018-07-13 16:13:52 +0200743
744 if (app->quirks & MT_QUIRK_CONFIDENCE)
745 input_set_abs_params(hi->input,
746 ABS_MT_TOOL_TYPE,
747 MT_TOOL_FINGER,
748 MT_TOOL_PALM, 0, 0);
749
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200750 MT_STORE_FIELD(confidence_state);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100751 return 1;
752 case HID_DG_TIPSWITCH:
Benjamin Tissoiresba6b0552018-07-13 16:13:49 +0200753 if (field->application != HID_GD_SYSTEM_MULTIAXIS)
754 input_set_capability(hi->input,
755 EV_KEY, BTN_TOUCH);
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200756 MT_STORE_FIELD(tip_state);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100757 return 1;
758 case HID_DG_CONTACTID:
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200759 MT_STORE_FIELD(contactid);
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200760 app->touches_by_report++;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100761 return 1;
762 case HID_DG_WIDTH:
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +0200763 if (!(app->quirks & MT_QUIRK_NO_AREA))
Henrik Rydberg77723e32012-09-07 19:37:40 +0200764 set_abs(hi->input, ABS_MT_TOUCH_MAJOR, field,
765 cls->sn_width);
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200766 MT_STORE_FIELD(w);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100767 return 1;
768 case HID_DG_HEIGHT:
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +0200769 if (!(app->quirks & MT_QUIRK_NO_AREA)) {
Henrik Rydberg77723e32012-09-07 19:37:40 +0200770 set_abs(hi->input, ABS_MT_TOUCH_MINOR, field,
771 cls->sn_height);
Wei-Ning Huang00720272017-10-12 14:21:43 +0800772
773 /*
774 * Only set ABS_MT_ORIENTATION if it is not
775 * already set by the HID_DG_AZIMUTH usage.
776 */
777 if (!test_bit(ABS_MT_ORIENTATION,
778 hi->input->absbit))
779 input_set_abs_params(hi->input,
780 ABS_MT_ORIENTATION, 0, 1, 0, 0);
Henrik Rydberg77723e32012-09-07 19:37:40 +0200781 }
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200782 MT_STORE_FIELD(h);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100783 return 1;
784 case HID_DG_TIPPRESSURE:
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100785 set_abs(hi->input, ABS_MT_PRESSURE, field,
786 cls->sn_pressure);
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200787 MT_STORE_FIELD(p);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100788 return 1;
Nicolas Boichat29cc3092017-08-22 09:10:11 +0800789 case HID_DG_SCANTIME:
Nicolas Boichat29cc3092017-08-22 09:10:11 +0800790 input_set_capability(hi->input, EV_MSC, MSC_TIMESTAMP);
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200791 app->scantime = &field->value[usage->usage_index];
792 app->scantime_logical_max = field->logical_maximum;
Nicolas Boichat29cc3092017-08-22 09:10:11 +0800793 return 1;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100794 case HID_DG_CONTACTCOUNT:
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200795 app->have_contact_count = true;
796 app->raw_cc = &field->value[usage->usage_index];
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100797 return 1;
Wei-Ning Huang00720272017-10-12 14:21:43 +0800798 case HID_DG_AZIMUTH:
Wei-Ning Huang00720272017-10-12 14:21:43 +0800799 /*
800 * Azimuth has the range of [0, MAX) representing a full
801 * revolution. Set ABS_MT_ORIENTATION to a quarter of
802 * MAX according the definition of ABS_MT_ORIENTATION
803 */
804 input_set_abs_params(hi->input, ABS_MT_ORIENTATION,
805 -field->logical_maximum / 4,
806 field->logical_maximum / 4,
807 cls->sn_move ?
808 field->logical_maximum / cls->sn_move : 0, 0);
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200809 MT_STORE_FIELD(a);
Wei-Ning Huang00720272017-10-12 14:21:43 +0800810 return 1;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100811 case HID_DG_CONTACTMAX:
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200812 /* contact max are global to the report */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100813 return -1;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100814 case HID_DG_TOUCH:
815 /* Legacy devices use TIPSWITCH and not TOUCH.
816 * Let's just ignore this field. */
817 return -1;
Alan Cox65b258e2012-10-25 15:35:25 +0100818 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100819 /* let hid-input decide for the others */
820 return 0;
821
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100822 case HID_UP_BUTTON:
823 code = BTN_MOUSE + ((usage->hid - 1) & HID_USAGE);
Benjamin Tissoires594312b2016-11-25 11:08:10 +0100824 /*
825 * MS PTP spec says that external buttons left and right have
826 * usages 2 and 3.
827 */
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +0200828 if ((app->quirks & MT_QUIRK_WIN8_PTP_BUTTONS) &&
Benjamin Tissoires594312b2016-11-25 11:08:10 +0100829 field->application == HID_DG_TOUCHPAD &&
830 (usage->hid & HID_USAGE) > 1)
831 code--;
Benjamin Tissoiresba6b0552018-07-13 16:13:49 +0200832
833 if (field->application == HID_GD_SYSTEM_MULTIAXIS)
834 code = BTN_0 + ((usage->hid - 1) & HID_USAGE);
835
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100836 hid_map_usage(hi, usage, bit, max, EV_KEY, code);
837 input_set_capability(hi->input, EV_KEY, code);
838 return 1;
839
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100840 case 0xff000000:
841 /* we do not want to map these: no input-oriented meaning */
842 return -1;
843 }
844
845 return 0;
846}
847
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200848static int mt_compute_slot(struct mt_device *td, struct mt_application *app,
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200849 struct mt_usages *slot,
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200850 struct input_dev *input)
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100851{
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +0200852 __s32 quirks = app->quirks;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100853
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100854 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID)
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200855 return *slot->contactid;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100856
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100857 if (quirks & MT_QUIRK_CYPRESS)
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200858 return cypress_compute_slot(app, slot);
Benjamin Tissoiresa3b5e572011-01-07 23:46:30 +0100859
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100860 if (quirks & MT_QUIRK_SLOT_IS_CONTACTNUMBER)
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200861 return app->num_received;
Benjamin Tissoires5572da02011-01-07 23:47:27 +0100862
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +0200863 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE)
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200864 return *slot->contactid - 1;
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +0200865
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200866 return input_mt_get_slot_by_key(input, *slot->contactid);
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200867}
868
Dmitry Torokhov28a042a2018-07-13 16:13:54 +0200869static void mt_release_pending_palms(struct mt_device *td,
870 struct mt_application *app,
871 struct input_dev *input)
872{
873 int slotnum;
874 bool need_sync = false;
875
876 for_each_set_bit(slotnum, app->pending_palm_slots, td->maxcontacts) {
877 clear_bit(slotnum, app->pending_palm_slots);
878
879 input_mt_slot(input, slotnum);
880 input_mt_report_slot_state(input, MT_TOOL_PALM, false);
881
882 need_sync = true;
883 }
884
885 if (need_sync) {
886 input_mt_sync_frame(input);
887 input_sync(input);
888 }
889}
890
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200891/*
892 * this function is called when a whole packet has been received and processed,
893 * so that it can decide what to send to the input layer.
894 */
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200895static void mt_sync_frame(struct mt_device *td, struct mt_application *app,
896 struct input_dev *input)
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200897{
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +0200898 if (app->quirks & MT_QUIRK_WIN8_PTP_BUTTONS)
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200899 input_event(input, EV_KEY, BTN_LEFT, app->left_button_state);
Hans de Goede127e71b2017-11-22 12:57:10 +0100900
Henrik Rydberg76f59022012-09-01 20:11:34 +0200901 input_mt_sync_frame(input);
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200902 input_event(input, EV_MSC, MSC_TIMESTAMP, app->timestamp);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100903 input_sync(input);
Dmitry Torokhov28a042a2018-07-13 16:13:54 +0200904
905 mt_release_pending_palms(td, app, input);
906
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200907 app->num_received = 0;
908 app->left_button_state = 0;
909
Benjamin Tissoires96098272017-06-15 15:32:05 +0200910 if (test_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags))
911 set_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags);
912 else
913 clear_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags);
914 clear_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100915}
916
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200917static int mt_compute_timestamp(struct mt_application *app, __s32 value)
Nicolas Boichat29cc3092017-08-22 09:10:11 +0800918{
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200919 long delta = value - app->prev_scantime;
920 unsigned long jdelta = jiffies_to_usecs(jiffies - app->jiffies);
Nicolas Boichat29cc3092017-08-22 09:10:11 +0800921
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200922 app->jiffies = jiffies;
Nicolas Boichat29cc3092017-08-22 09:10:11 +0800923
924 if (delta < 0)
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200925 delta += app->scantime_logical_max;
Nicolas Boichat29cc3092017-08-22 09:10:11 +0800926
927 /* HID_DG_SCANTIME is expressed in 100us, we want it in us. */
928 delta *= 100;
929
930 if (jdelta > MAX_TIMESTAMP_INTERVAL)
931 /* No data received for a while, resync the timestamp. */
932 return 0;
933 else
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +0200934 return app->timestamp + delta;
Nicolas Boichat29cc3092017-08-22 09:10:11 +0800935}
936
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +0100937static int mt_touch_event(struct hid_device *hid, struct hid_field *field,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100938 struct hid_usage *usage, __s32 value)
939{
Benjamin Tissoires55978fa2013-01-31 17:22:24 +0100940 /* we will handle the hidinput part later, now remains hiddev */
941 if (hid->claimed & HID_CLAIMED_HIDDEV && hid->hiddev_hid_event)
942 hid->hiddev_hid_event(hid, field, usage, value);
943
944 return 1;
945}
946
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200947static int mt_process_slot(struct mt_device *td, struct input_dev *input,
948 struct mt_application *app,
949 struct mt_usages *slot)
Benjamin Tissoires55978fa2013-01-31 17:22:24 +0100950{
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200951 struct input_mt *mt = input->mt;
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +0200952 __s32 quirks = app->quirks;
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200953 bool valid = true;
954 bool confidence_state = true;
955 bool inrange_state = false;
956 int active;
957 int slotnum;
Benjamin Tissoiresba6b0552018-07-13 16:13:49 +0200958 int tool = MT_TOOL_FINGER;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100959
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200960 if (!slot)
961 return -EINVAL;
962
963 if ((quirks & MT_QUIRK_CONTACT_CNT_ACCURATE) &&
964 app->num_received >= app->num_expected)
965 return -EAGAIN;
966
967 if (!(quirks & MT_QUIRK_ALWAYS_VALID)) {
968 if (quirks & MT_QUIRK_VALID_IS_INRANGE)
969 valid = *slot->inrange_state;
970 if (quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
971 valid = *slot->tip_state;
972 if (quirks & MT_QUIRK_VALID_IS_CONFIDENCE)
973 valid = *slot->confidence_state;
974
975 if (!valid)
976 return 0;
977 }
978
979 slotnum = mt_compute_slot(td, app, slot, input);
980 if (slotnum < 0 || slotnum >= td->maxcontacts)
981 return 0;
982
983 if ((quirks & MT_QUIRK_IGNORE_DUPLICATES) && mt) {
984 struct input_mt_slot *i_slot = &mt->slots[slotnum];
985
986 if (input_mt_is_active(i_slot) &&
987 input_mt_is_used(mt, i_slot))
988 return -EAGAIN;
989 }
990
991 if (quirks & MT_QUIRK_CONFIDENCE)
992 confidence_state = *slot->confidence_state;
993
994 if (quirks & MT_QUIRK_HOVERING)
995 inrange_state = *slot->inrange_state;
996
Dmitry Torokhov9152c7d2018-07-13 16:13:52 +0200997 active = *slot->tip_state || inrange_state;
Benjamin Tissoires01eaac72018-07-13 16:13:48 +0200998
Benjamin Tissoiresba6b0552018-07-13 16:13:49 +0200999 if (app->application == HID_GD_SYSTEM_MULTIAXIS)
1000 tool = MT_TOOL_DIAL;
Dmitry Torokhov28a042a2018-07-13 16:13:54 +02001001 else if (unlikely(!confidence_state)) {
Dmitry Torokhov9152c7d2018-07-13 16:13:52 +02001002 tool = MT_TOOL_PALM;
Dmitry Torokhov28a042a2018-07-13 16:13:54 +02001003 if (!active &&
1004 input_mt_is_active(&mt->slots[slotnum])) {
1005 /*
1006 * The non-confidence was reported for
1007 * previously valid contact that is also no
1008 * longer valid. We can't simply report
1009 * lift-off as userspace will not be aware
1010 * of non-confidence, so we need to split
1011 * it into 2 events: active MT_TOOL_PALM
1012 * and a separate liftoff.
1013 */
1014 active = true;
1015 set_bit(slotnum, app->pending_palm_slots);
1016 }
1017 }
Benjamin Tissoiresba6b0552018-07-13 16:13:49 +02001018
Benjamin Tissoires01eaac72018-07-13 16:13:48 +02001019 input_mt_slot(input, slotnum);
Benjamin Tissoiresba6b0552018-07-13 16:13:49 +02001020 input_mt_report_slot_state(input, tool, active);
Benjamin Tissoires01eaac72018-07-13 16:13:48 +02001021 if (active) {
1022 /* this finger is in proximity of the sensor */
1023 int wide = (*slot->w > *slot->h);
1024 int major = max(*slot->w, *slot->h);
1025 int minor = min(*slot->w, *slot->h);
1026 int orientation = wide;
1027 int max_azimuth;
1028 int azimuth;
1029
1030 if (slot->a != DEFAULT_ZERO) {
Wei-Ning Huang00720272017-10-12 14:21:43 +08001031 /*
1032 * Azimuth is counter-clockwise and ranges from [0, MAX)
1033 * (a full revolution). Convert it to clockwise ranging
1034 * [-MAX/2, MAX/2].
1035 *
1036 * Note that ABS_MT_ORIENTATION require us to report
1037 * the limit of [-MAX/4, MAX/4], but the value can go
1038 * out of range to [-MAX/2, MAX/2] to report an upside
1039 * down ellipsis.
1040 */
Benjamin Tissoires01eaac72018-07-13 16:13:48 +02001041 azimuth = *slot->a;
1042 max_azimuth = input_abs_get_max(input,
1043 ABS_MT_ORIENTATION);
1044 if (azimuth > max_azimuth * 2)
1045 azimuth -= max_azimuth * 4;
1046 orientation = -azimuth;
1047 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001048
Benjamin Tissoires01eaac72018-07-13 16:13:48 +02001049 if (quirks & MT_QUIRK_TOUCH_SIZE_SCALING) {
Dmitry Torokhov9152c7d2018-07-13 16:13:52 +02001050 /*
1051 * divided by two to match visual scale of touch
1052 * for devices with this quirk
1053 */
Benjamin Tissoires01eaac72018-07-13 16:13:48 +02001054 major = major >> 1;
1055 minor = minor >> 1;
1056 }
Hans de Goede55746d22017-11-22 12:57:09 +01001057
Benjamin Tissoires01eaac72018-07-13 16:13:48 +02001058 input_event(input, EV_ABS, ABS_MT_POSITION_X, *slot->x);
1059 input_event(input, EV_ABS, ABS_MT_POSITION_Y, *slot->y);
1060 input_event(input, EV_ABS, ABS_MT_TOOL_X, *slot->cx);
1061 input_event(input, EV_ABS, ABS_MT_TOOL_Y, *slot->cy);
1062 input_event(input, EV_ABS, ABS_MT_DISTANCE, !*slot->tip_state);
1063 input_event(input, EV_ABS, ABS_MT_ORIENTATION, orientation);
1064 input_event(input, EV_ABS, ABS_MT_PRESSURE, *slot->p);
1065 input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, major);
1066 input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, minor);
Hans de Goede127e71b2017-11-22 12:57:10 +01001067
Benjamin Tissoires01eaac72018-07-13 16:13:48 +02001068 set_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags);
1069 }
1070
1071 return 0;
1072}
1073
1074static void mt_process_mt_event(struct hid_device *hid,
1075 struct mt_application *app,
1076 struct hid_field *field,
1077 struct hid_usage *usage,
1078 __s32 value,
1079 bool first_packet)
1080{
1081 __s32 quirks = app->quirks;
1082 struct input_dev *input = field->hidinput->input;
1083
1084 if (!usage->type || !(hid->claimed & HID_CLAIMED_INPUT))
1085 return;
1086
1087 if (quirks & MT_QUIRK_WIN8_PTP_BUTTONS) {
1088
1089 /*
1090 * For Win8 PTP touchpads we should only look at
1091 * non finger/touch events in the first_packet of a
1092 * (possible) multi-packet frame.
1093 */
1094 if (!first_packet)
1095 return;
1096
1097 /*
1098 * For Win8 PTP touchpads we map both the clickpad click
1099 * and any "external" left buttons to BTN_LEFT if a
1100 * device claims to have both we need to report 1 for
1101 * BTN_LEFT if either is pressed, so we or all values
1102 * together and report the result in mt_sync_frame().
1103 */
1104 if (usage->type == EV_KEY && usage->code == BTN_LEFT) {
1105 app->left_button_state |= value;
Benjamin Tissoires55978fa2013-01-31 17:22:24 +01001106 return;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001107 }
1108 }
Benjamin Tissoires01eaac72018-07-13 16:13:48 +02001109
1110 input_event(input, usage->type, usage->code, value);
Benjamin Tissoires55978fa2013-01-31 17:22:24 +01001111}
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001112
Benjamin Tissoires8dfe14b2018-07-13 16:13:47 +02001113static void mt_touch_report(struct hid_device *hid,
1114 struct mt_report_data *rdata)
Benjamin Tissoires55978fa2013-01-31 17:22:24 +01001115{
1116 struct mt_device *td = hid_get_drvdata(hid);
Benjamin Tissoires8dfe14b2018-07-13 16:13:47 +02001117 struct hid_report *report = rdata->report;
1118 struct mt_application *app = rdata->application;
Benjamin Tissoires55978fa2013-01-31 17:22:24 +01001119 struct hid_field *field;
Benjamin Tissoires01eaac72018-07-13 16:13:48 +02001120 struct input_dev *input;
1121 struct mt_usages *slot;
Hans de Goede55746d22017-11-22 12:57:09 +01001122 bool first_packet;
Benjamin Tissoires55978fa2013-01-31 17:22:24 +01001123 unsigned count;
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001124 int r, n;
1125 int scantime = 0;
1126 int contact_count = -1;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001127
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +02001128 /* sticky fingers release in progress, abort */
1129 if (test_and_set_bit(MT_IO_FLAGS_RUNNING, &td->mt_io_flags))
1130 return;
1131
Benjamin Tissoires01eaac72018-07-13 16:13:48 +02001132 scantime = *app->scantime;
1133 app->timestamp = mt_compute_timestamp(app, scantime);
1134 if (app->raw_cc != DEFAULT_ZERO)
1135 contact_count = *app->raw_cc;
1136
Benjamin Tissoiresc2517f62013-01-31 17:22:25 +01001137 /*
1138 * Includes multi-packet support where subsequent
1139 * packets are sent with zero contactcount.
1140 */
Benjamin Tissoires01eaac72018-07-13 16:13:48 +02001141 if (contact_count >= 0) {
Hans de Goedeaf8dc4d2017-11-22 12:57:08 +01001142 /*
1143 * For Win8 PTPs the first packet (td->num_received == 0) may
1144 * have a contactcount of 0 if there only is a button event.
1145 * We double check that this is not a continuation packet
1146 * of a possible multi-packet frame be checking that the
1147 * timestamp has changed.
1148 */
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +02001149 if ((app->quirks & MT_QUIRK_WIN8_PTP_BUTTONS) &&
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001150 app->num_received == 0 &&
1151 app->prev_scantime != scantime)
1152 app->num_expected = contact_count;
Hans de Goedeaf8dc4d2017-11-22 12:57:08 +01001153 /* A non 0 contact count always indicates a first packet */
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001154 else if (contact_count)
1155 app->num_expected = contact_count;
Benjamin Tissoires7e3cc442013-02-06 12:10:47 +01001156 }
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001157 app->prev_scantime = scantime;
Benjamin Tissoiresc2517f62013-01-31 17:22:25 +01001158
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001159 first_packet = app->num_received == 0;
Benjamin Tissoires01eaac72018-07-13 16:13:48 +02001160
1161 input = report->field[0]->hidinput->input;
1162
1163 list_for_each_entry(slot, &app->mt_usages, list) {
1164 if (!mt_process_slot(td, input, app, slot))
1165 app->num_received++;
1166 }
1167
Benjamin Tissoires55978fa2013-01-31 17:22:24 +01001168 for (r = 0; r < report->maxfield; r++) {
1169 field = report->field[r];
1170 count = field->report_count;
1171
1172 if (!(HID_MAIN_ITEM_VARIABLE & field->flags))
1173 continue;
1174
1175 for (n = 0; n < count; n++)
Benjamin Tissoires01eaac72018-07-13 16:13:48 +02001176 mt_process_mt_event(hid, app, field,
1177 &field->usage[n], field->value[n],
1178 first_packet);
Benjamin Tissoires55978fa2013-01-31 17:22:24 +01001179 }
Benjamin Tissoires5b62efd2013-02-27 16:23:15 +01001180
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001181 if (app->num_received >= app->num_expected)
Benjamin Tissoires01eaac72018-07-13 16:13:48 +02001182 mt_sync_frame(td, app, input);
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +02001183
1184 /*
1185 * Windows 8 specs says 2 things:
1186 * - once a contact has been reported, it has to be reported in each
1187 * subsequent report
1188 * - the report rate when fingers are present has to be at least
1189 * the refresh rate of the screen, 60 or 120 Hz
1190 *
1191 * I interprete this that the specification forces a report rate of
1192 * at least 60 Hz for a touchscreen to be certified.
1193 * Which means that if we do not get a report whithin 16 ms, either
1194 * something wrong happens, either the touchscreen forgets to send
1195 * a release. Taking a reasonable margin allows to remove issues
1196 * with USB communication or the load of the machine.
1197 *
1198 * Given that Win 8 devices are forced to send a release, this will
1199 * only affect laggish machines and the ones that have a firmware
1200 * defect.
1201 */
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +02001202 if (app->quirks & MT_QUIRK_STICKY_FINGERS) {
Benjamin Tissoires96098272017-06-15 15:32:05 +02001203 if (test_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags))
1204 mod_timer(&td->release_timer,
1205 jiffies + msecs_to_jiffies(100));
1206 else
1207 del_timer(&td->release_timer);
1208 }
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +02001209
1210 clear_bit(MT_IO_FLAGS_RUNNING, &td->mt_io_flags);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001211}
1212
Dmitry Torokhovb2c68a22015-09-29 15:52:59 -07001213static int mt_touch_input_configured(struct hid_device *hdev,
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001214 struct hid_input *hi,
1215 struct mt_application *app)
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001216{
1217 struct mt_device *td = hid_get_drvdata(hdev);
1218 struct mt_class *cls = &td->mtclass;
1219 struct input_dev *input = hi->input;
Dmitry Torokhovb2c68a22015-09-29 15:52:59 -07001220 int ret;
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001221
1222 if (!td->maxcontacts)
1223 td->maxcontacts = MT_DEFAULT_MAXCONTACT;
1224
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001225 mt_post_parse(td, app);
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001226 if (td->serial_maybe)
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001227 mt_post_parse_default_settings(td, app);
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001228
1229 if (cls->is_indirect)
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001230 app->mt_flags |= INPUT_MT_POINTER;
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001231
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +02001232 if (app->quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001233 app->mt_flags |= INPUT_MT_DROP_UNUSED;
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001234
Benjamin Tissoires015fdaa2015-03-06 11:14:42 -05001235 /* check for clickpads */
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001236 if ((app->mt_flags & INPUT_MT_POINTER) &&
1237 (app->buttons_count == 1))
Seth Forshee2c6e0272015-03-11 17:26:41 -05001238 td->is_buttonpad = true;
1239
1240 if (td->is_buttonpad)
Benjamin Tissoires015fdaa2015-03-06 11:14:42 -05001241 __set_bit(INPUT_PROP_BUTTONPAD, input->propbit);
1242
Dmitry Torokhov28a042a2018-07-13 16:13:54 +02001243 app->pending_palm_slots = devm_kcalloc(&hi->input->dev,
1244 BITS_TO_LONGS(td->maxcontacts),
1245 sizeof(long),
1246 GFP_KERNEL);
1247 if (!app->pending_palm_slots)
1248 return -ENOMEM;
1249
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001250 ret = input_mt_init_slots(input, td->maxcontacts, app->mt_flags);
Dmitry Torokhovb2c68a22015-09-29 15:52:59 -07001251 if (ret)
1252 return ret;
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001253
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001254 app->mt_flags = 0;
Dmitry Torokhovb2c68a22015-09-29 15:52:59 -07001255 return 0;
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001256}
1257
João Paulo Rechi Vita957b8df2017-07-24 14:22:25 -07001258#define mt_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, \
1259 max, EV_KEY, (c))
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001260static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
1261 struct hid_field *field, struct hid_usage *usage,
1262 unsigned long **bit, int *max)
1263{
Benjamin Tissoires6aef7042014-02-28 11:41:25 -05001264 struct mt_device *td = hid_get_drvdata(hdev);
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001265 struct mt_application *application;
Benjamin Tissoires8dfe14b2018-07-13 16:13:47 +02001266 struct mt_report_data *rdata;
Benjamin Tissoires6aef7042014-02-28 11:41:25 -05001267
Benjamin Tissoires8dfe14b2018-07-13 16:13:47 +02001268 rdata = mt_find_report_data(td, field->report);
1269 if (!rdata) {
1270 hid_err(hdev, "failed to allocate data for report\n");
1271 return 0;
1272 }
1273
1274 application = rdata->application;
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +02001275
Benjamin Tissoires6aef7042014-02-28 11:41:25 -05001276 /*
1277 * If mtclass.export_all_inputs is not set, only map fields from
1278 * TouchScreen or TouchPad collections. We need to ignore fields
1279 * that belong to other collections such as Mouse that might have
1280 * the same GenericDesktop usages.
1281 */
1282 if (!td->mtclass.export_all_inputs &&
1283 field->application != HID_DG_TOUCHSCREEN &&
Benjamin Tissoiresfa11aa72013-03-22 18:38:32 +01001284 field->application != HID_DG_PEN &&
Benjamin Tissoires8fe89ef2016-11-25 14:27:23 +01001285 field->application != HID_DG_TOUCHPAD &&
1286 field->application != HID_GD_KEYBOARD &&
Hans de Goedee57f4e62017-08-22 08:37:52 +02001287 field->application != HID_GD_SYSTEM_CONTROL &&
João Paulo Rechi Vita1fbf74ef2017-07-24 14:22:24 -07001288 field->application != HID_CP_CONSUMER_CONTROL &&
João Paulo Rechi Vita957b8df2017-07-24 14:22:25 -07001289 field->application != HID_GD_WIRELESS_RADIO_CTLS &&
Benjamin Tissoiresba6b0552018-07-13 16:13:49 +02001290 field->application != HID_GD_SYSTEM_MULTIAXIS &&
João Paulo Rechi Vita957b8df2017-07-24 14:22:25 -07001291 !(field->application == HID_VD_ASUS_CUSTOM_MEDIA_KEYS &&
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +02001292 application->quirks & MT_QUIRK_ASUS_CUSTOM_UP))
Benjamin Tissoires6f492f22013-03-22 18:38:30 +01001293 return -1;
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001294
Benjamin Tissoires6aef7042014-02-28 11:41:25 -05001295 /*
João Paulo Rechi Vita957b8df2017-07-24 14:22:25 -07001296 * Some Asus keyboard+touchpad devices have the hotkeys defined in the
1297 * touchpad report descriptor. We need to treat these as an array to
1298 * map usages to input keys.
1299 */
Jiri Kosina39bbf402017-08-03 11:25:32 +02001300 if (field->application == HID_VD_ASUS_CUSTOM_MEDIA_KEYS &&
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +02001301 application->quirks & MT_QUIRK_ASUS_CUSTOM_UP &&
João Paulo Rechi Vita957b8df2017-07-24 14:22:25 -07001302 (usage->hid & HID_USAGE_PAGE) == HID_UP_CUSTOM) {
1303 set_bit(EV_REP, hi->input->evbit);
1304 if (field->flags & HID_MAIN_ITEM_VARIABLE)
1305 field->flags &= ~HID_MAIN_ITEM_VARIABLE;
1306 switch (usage->hid & HID_USAGE) {
1307 case 0x10: mt_map_key_clear(KEY_BRIGHTNESSDOWN); break;
1308 case 0x20: mt_map_key_clear(KEY_BRIGHTNESSUP); break;
1309 case 0x35: mt_map_key_clear(KEY_DISPLAY_OFF); break;
1310 case 0x6b: mt_map_key_clear(KEY_F21); break;
1311 case 0x6c: mt_map_key_clear(KEY_SLEEP); break;
1312 default:
1313 return -1;
1314 }
1315 return 1;
1316 }
1317
Benjamin Tissoiresba6b0552018-07-13 16:13:49 +02001318 if (rdata->is_mt_collection)
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001319 return mt_touch_input_mapping(hdev, hi, field, usage, bit, max,
1320 application);
Benjamin Tissoires6aef7042014-02-28 11:41:25 -05001321
1322 /* let hid-core decide for the others */
1323 return 0;
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001324}
1325
1326static int mt_input_mapped(struct hid_device *hdev, struct hid_input *hi,
1327 struct hid_field *field, struct hid_usage *usage,
1328 unsigned long **bit, int *max)
1329{
Benjamin Tissoiresba6b0552018-07-13 16:13:49 +02001330 struct mt_device *td = hid_get_drvdata(hdev);
1331 struct mt_report_data *rdata;
Benjamin Tissoiresfa11aa72013-03-22 18:38:32 +01001332
Benjamin Tissoiresba6b0552018-07-13 16:13:49 +02001333 rdata = mt_find_report_data(td, field->report);
1334 if (rdata && rdata->is_mt_collection) {
Dmitry Torokhov4cf56a89c2017-07-11 10:02:18 -07001335 /* We own these mappings, tell hid-input to ignore them */
1336 return -1;
1337 }
Benjamin Tissoires6aef7042014-02-28 11:41:25 -05001338
1339 /* let hid-core decide for the others */
1340 return 0;
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001341}
1342
1343static int mt_event(struct hid_device *hid, struct hid_field *field,
1344 struct hid_usage *usage, __s32 value)
1345{
1346 struct mt_device *td = hid_get_drvdata(hid);
Benjamin Tissoires8dfe14b2018-07-13 16:13:47 +02001347 struct mt_report_data *rdata;
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001348
Benjamin Tissoires8dfe14b2018-07-13 16:13:47 +02001349 rdata = mt_find_report_data(td, field->report);
1350 if (rdata && rdata->is_mt_collection)
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001351 return mt_touch_event(hid, field, usage, value);
1352
Benjamin Tissoirese55f6202014-02-28 11:41:24 -05001353 return 0;
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001354}
1355
1356static void mt_report(struct hid_device *hid, struct hid_report *report)
1357{
1358 struct mt_device *td = hid_get_drvdata(hid);
Benjamin Tissoirese55f6202014-02-28 11:41:24 -05001359 struct hid_field *field = report->field[0];
Benjamin Tissoires8dfe14b2018-07-13 16:13:47 +02001360 struct mt_report_data *rdata;
Benjamin Tissoiresa69c5f82013-03-22 18:38:29 +01001361
1362 if (!(hid->claimed & HID_CLAIMED_INPUT))
1363 return;
1364
Benjamin Tissoires8dfe14b2018-07-13 16:13:47 +02001365 rdata = mt_find_report_data(td, report);
1366 if (rdata && rdata->is_mt_collection)
1367 return mt_touch_report(hid, rdata);
Benjamin Tissoiresfa11aa72013-03-22 18:38:32 +01001368
Benjamin Tissoirese55f6202014-02-28 11:41:24 -05001369 if (field && field->hidinput && field->hidinput->input)
1370 input_sync(field->hidinput->input);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001371}
1372
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001373static bool mt_need_to_apply_feature(struct hid_device *hdev,
1374 struct hid_field *field,
Benjamin Tissoires02946f42018-04-24 10:04:37 +02001375 struct hid_usage *usage,
1376 enum latency_mode latency,
1377 bool surface_switch,
1378 bool button_switch)
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001379{
1380 struct mt_device *td = hid_get_drvdata(hdev);
Mathieu Magnaudetda10bc22014-11-22 12:02:07 +01001381 struct mt_class *cls = &td->mtclass;
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001382 struct hid_report *report = field->report;
1383 unsigned int index = usage->usage_index;
Mathieu Magnaudetda10bc22014-11-22 12:02:07 +01001384 char *buf;
Aaron Ma3064a032018-02-03 23:57:15 +08001385 u32 report_len;
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001386 int max;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001387
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001388 switch (usage->hid) {
1389 case HID_DG_INPUTMODE:
Mathieu Magnaudetda10bc22014-11-22 12:02:07 +01001390 if (cls->quirks & MT_QUIRK_FORCE_GET_FEATURE) {
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001391 report_len = hid_report_len(report);
1392 buf = hid_alloc_report_buf(report, GFP_KERNEL);
Mathieu Magnaudetda10bc22014-11-22 12:02:07 +01001393 if (!buf) {
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001394 hid_err(hdev,
1395 "failed to allocate buffer for report\n");
1396 return false;
Mathieu Magnaudetda10bc22014-11-22 12:02:07 +01001397 }
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001398 hid_hw_raw_request(hdev, report->id, buf, report_len,
Mathieu Magnaudetda10bc22014-11-22 12:02:07 +01001399 HID_FEATURE_REPORT,
1400 HID_REQ_GET_REPORT);
1401 kfree(buf);
1402 }
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001403
1404 field->value[index] = td->inputmode_value;
1405 return true;
1406
1407 case HID_DG_CONTACTMAX:
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +02001408 if (cls->maxcontacts) {
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001409 max = min_t(int, field->logical_maximum,
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +02001410 cls->maxcontacts);
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001411 if (field->value[index] != max) {
1412 field->value[index] = max;
1413 return true;
1414 }
1415 }
1416 break;
Benjamin Tissoires02946f42018-04-24 10:04:37 +02001417
1418 case HID_DG_LATENCYMODE:
1419 field->value[index] = latency;
Jiri Kosina99c703a2018-05-16 11:02:07 +02001420 return true;
Benjamin Tissoires02946f42018-04-24 10:04:37 +02001421
1422 case HID_DG_SURFACESWITCH:
1423 field->value[index] = surface_switch;
Jiri Kosina99c703a2018-05-16 11:02:07 +02001424 return true;
Benjamin Tissoires02946f42018-04-24 10:04:37 +02001425
1426 case HID_DG_BUTTONSWITCH:
1427 field->value[index] = button_switch;
Jiri Kosina99c703a2018-05-16 11:02:07 +02001428 return true;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001429 }
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001430
1431 return false; /* no need to update the report */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001432}
1433
Benjamin Tissoires02946f42018-04-24 10:04:37 +02001434static void mt_set_modes(struct hid_device *hdev, enum latency_mode latency,
1435 bool surface_switch, bool button_switch)
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +01001436{
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001437 struct hid_report_enum *rep_enum;
1438 struct hid_report *rep;
1439 struct hid_usage *usage;
1440 int i, j;
1441 bool update_report;
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +01001442
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001443 rep_enum = &hdev->report_enum[HID_FEATURE_REPORT];
1444 list_for_each_entry(rep, &rep_enum->report_list, list) {
1445 update_report = false;
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +01001446
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001447 for (i = 0; i < rep->maxfield; i++) {
1448 /* Ignore if report count is out of bounds. */
1449 if (rep->field[i]->report_count < 1)
1450 continue;
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +01001451
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001452 for (j = 0; j < rep->field[i]->maxusage; j++) {
1453 usage = &rep->field[i]->usage[j];
1454
1455 if (mt_need_to_apply_feature(hdev,
1456 rep->field[i],
Benjamin Tissoires02946f42018-04-24 10:04:37 +02001457 usage,
1458 latency,
1459 surface_switch,
1460 button_switch))
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001461 update_report = true;
1462 }
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +01001463 }
Benjamin Tissoires7f81c8d2018-04-24 10:04:36 +02001464
1465 if (update_report)
1466 hid_hw_request(hdev, rep, HID_REQ_SET_REPORT);
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +01001467 }
1468}
1469
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001470static void mt_post_parse_default_settings(struct mt_device *td,
1471 struct mt_application *app)
Henrik Rydberg4fa3a582012-05-01 08:40:01 +02001472{
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +02001473 __s32 quirks = app->quirks;
Henrik Rydberg4fa3a582012-05-01 08:40:01 +02001474
1475 /* unknown serial device needs special quirks */
Benjamin Tissoires01eaac72018-07-13 16:13:48 +02001476 if (list_is_singular(&app->mt_usages)) {
Henrik Rydberg4fa3a582012-05-01 08:40:01 +02001477 quirks |= MT_QUIRK_ALWAYS_VALID;
1478 quirks &= ~MT_QUIRK_NOT_SEEN_MEANS_UP;
1479 quirks &= ~MT_QUIRK_VALID_IS_INRANGE;
1480 quirks &= ~MT_QUIRK_VALID_IS_CONFIDENCE;
Benjamin Tissoirese0bb8f92013-01-31 17:22:27 +01001481 quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE;
Henrik Rydberg4fa3a582012-05-01 08:40:01 +02001482 }
1483
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +02001484 app->quirks = quirks;
Henrik Rydberg4fa3a582012-05-01 08:40:01 +02001485}
1486
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001487static void mt_post_parse(struct mt_device *td, struct mt_application *app)
Benjamin Tissoires3ac36d152012-05-04 14:53:46 +02001488{
Benjamin Tissoires01eaac72018-07-13 16:13:48 +02001489 if (!app->have_contact_count)
Benjamin Tissoires3ceb3822018-07-13 16:13:46 +02001490 app->quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE;
Benjamin Tissoires3ac36d152012-05-04 14:53:46 +02001491}
1492
Dmitry Torokhovb2c68a22015-09-29 15:52:59 -07001493static int mt_input_configured(struct hid_device *hdev, struct hid_input *hi)
Henrik Rydberg76f59022012-09-01 20:11:34 +02001494{
1495 struct mt_device *td = hid_get_drvdata(hdev);
Benjamin Tissoiresc08d46a2013-07-24 19:38:05 +02001496 char *name;
1497 const char *suffix = NULL;
Benjamin Tissoires40ec2602018-04-24 10:04:35 +02001498 unsigned int application = 0;
Benjamin Tissoires8dfe14b2018-07-13 16:13:47 +02001499 struct mt_report_data *rdata;
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001500 struct mt_application *mt_application = NULL;
Benjamin Tissoires40ec2602018-04-24 10:04:35 +02001501 struct hid_report *report;
Dmitry Torokhovb2c68a22015-09-29 15:52:59 -07001502 int ret;
Henrik Rydberg76f59022012-09-01 20:11:34 +02001503
Benjamin Tissoires40ec2602018-04-24 10:04:35 +02001504 list_for_each_entry(report, &hi->reports, hidinput_list) {
1505 application = report->application;
Benjamin Tissoires8dfe14b2018-07-13 16:13:47 +02001506 rdata = mt_find_report_data(td, report);
1507 if (!rdata) {
1508 hid_err(hdev, "failed to allocate data for report\n");
1509 return -ENOMEM;
1510 }
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001511
Benjamin Tissoires8dfe14b2018-07-13 16:13:47 +02001512 mt_application = rdata->application;
1513
1514 if (rdata->is_mt_collection) {
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001515 ret = mt_touch_input_configured(hdev, hi,
1516 mt_application);
Benjamin Tissoires40ec2602018-04-24 10:04:35 +02001517 if (ret)
1518 return ret;
1519 }
Henrik Rydberg76f59022012-09-01 20:11:34 +02001520
Benjamin Tissoires40ec2602018-04-24 10:04:35 +02001521 /*
1522 * some egalax touchscreens have "application == DG_TOUCHSCREEN"
1523 * for the stylus. Check this first, and then rely on
1524 * the application field.
1525 */
1526 if (report->field[0]->physical == HID_DG_STYLUS) {
Benjamin Tissoires6aef7042014-02-28 11:41:25 -05001527 suffix = "Pen";
1528 /* force BTN_STYLUS to allow tablet matching in udev */
1529 __set_bit(BTN_STYLUS, hi->input->keybit);
Benjamin Tissoires40ec2602018-04-24 10:04:35 +02001530 }
1531 }
1532
1533 if (!suffix) {
1534 switch (application) {
1535 case HID_GD_KEYBOARD:
1536 case HID_GD_KEYPAD:
1537 case HID_GD_MOUSE:
1538 case HID_DG_TOUCHPAD:
1539 case HID_GD_SYSTEM_CONTROL:
1540 case HID_CP_CONSUMER_CONTROL:
1541 case HID_GD_WIRELESS_RADIO_CTLS:
Benjamin Tissoiresba6b0552018-07-13 16:13:49 +02001542 case HID_GD_SYSTEM_MULTIAXIS:
Benjamin Tissoires40ec2602018-04-24 10:04:35 +02001543 /* already handled by hid core */
Benjamin Tissoires6aef7042014-02-28 11:41:25 -05001544 break;
1545 case HID_DG_TOUCHSCREEN:
1546 /* we do not set suffix = "Touchscreen" */
Benjamin Tissoires40ec2602018-04-24 10:04:35 +02001547 hi->input->name = hdev->name;
Benjamin Tissoires6aef7042014-02-28 11:41:25 -05001548 break;
Benjamin Tissoires40ec2602018-04-24 10:04:35 +02001549 case HID_DG_STYLUS:
1550 /* force BTN_STYLUS to allow tablet matching in udev */
1551 __set_bit(BTN_STYLUS, hi->input->keybit);
João Paulo Rechi Vita1fbf74ef2017-07-24 14:22:24 -07001552 break;
João Paulo Rechi Vita957b8df2017-07-24 14:22:25 -07001553 case HID_VD_ASUS_CUSTOM_MEDIA_KEYS:
1554 suffix = "Custom Media Keys";
1555 break;
Benjamin Tissoires6aef7042014-02-28 11:41:25 -05001556 default:
1557 suffix = "UNKNOWN";
1558 break;
1559 }
Benjamin Tissoiresc08d46a2013-07-24 19:38:05 +02001560 }
1561
1562 if (suffix) {
1563 name = devm_kzalloc(&hi->input->dev,
1564 strlen(hdev->name) + strlen(suffix) + 2,
1565 GFP_KERNEL);
1566 if (name) {
1567 sprintf(name, "%s %s", hdev->name, suffix);
1568 hi->input->name = name;
1569 }
1570 }
Dmitry Torokhovb2c68a22015-09-29 15:52:59 -07001571
1572 return 0;
Henrik Rydberg76f59022012-09-01 20:11:34 +02001573}
1574
Benjamin Tissoiresf3287a92017-01-30 10:48:06 +01001575static void mt_fix_const_field(struct hid_field *field, unsigned int usage)
1576{
1577 if (field->usage[0].hid != usage ||
1578 !(field->flags & HID_MAIN_ITEM_CONSTANT))
1579 return;
1580
1581 field->flags &= ~HID_MAIN_ITEM_CONSTANT;
1582 field->flags |= HID_MAIN_ITEM_VARIABLE;
1583}
1584
1585static void mt_fix_const_fields(struct hid_device *hdev, unsigned int usage)
1586{
1587 struct hid_report *report;
1588 int i;
1589
1590 list_for_each_entry(report,
1591 &hdev->report_enum[HID_INPUT_REPORT].report_list,
1592 list) {
1593
1594 if (!report->maxfield)
1595 continue;
1596
1597 for (i = 0; i < report->maxfield; i++)
1598 if (report->field[i]->maxusage >= 1)
1599 mt_fix_const_field(report->field[i], usage);
1600 }
1601}
1602
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +02001603static void mt_release_contacts(struct hid_device *hid)
1604{
1605 struct hid_input *hidinput;
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001606 struct mt_application *application;
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +02001607 struct mt_device *td = hid_get_drvdata(hid);
1608
1609 list_for_each_entry(hidinput, &hid->inputs, list) {
1610 struct input_dev *input_dev = hidinput->input;
1611 struct input_mt *mt = input_dev->mt;
1612 int i;
1613
1614 if (mt) {
1615 for (i = 0; i < mt->num_slots; i++) {
1616 input_mt_slot(input_dev, i);
1617 input_mt_report_slot_state(input_dev,
1618 MT_TOOL_FINGER,
1619 false);
1620 }
1621 input_mt_sync_frame(input_dev);
1622 input_sync(input_dev);
1623 }
1624 }
1625
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001626 list_for_each_entry(application, &td->applications, list) {
1627 application->num_received = 0;
1628 }
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +02001629}
1630
Kees Cook0ee32772017-10-04 17:53:24 -07001631static void mt_expired_timeout(struct timer_list *t)
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +02001632{
Kees Cook0ee32772017-10-04 17:53:24 -07001633 struct mt_device *td = from_timer(td, t, release_timer);
1634 struct hid_device *hdev = td->hdev;
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +02001635
1636 /*
1637 * An input report came in just before we release the sticky fingers,
1638 * it will take care of the sticky fingers.
1639 */
1640 if (test_and_set_bit(MT_IO_FLAGS_RUNNING, &td->mt_io_flags))
1641 return;
Benjamin Tissoires96098272017-06-15 15:32:05 +02001642 if (test_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags))
1643 mt_release_contacts(hdev);
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +02001644 clear_bit(MT_IO_FLAGS_RUNNING, &td->mt_io_flags);
1645}
1646
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001647static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
1648{
Benjamin Tissoires2d936662011-01-11 16:45:54 +01001649 int ret, i;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001650 struct mt_device *td;
Benjamin Tissoirescf6d15d2018-07-13 16:13:44 +02001651 const struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */
Benjamin Tissoires2d936662011-01-11 16:45:54 +01001652
Henrik Rydberg94b5485c2012-08-08 21:45:50 +02001653 for (i = 0; mt_classes[i].name ; i++) {
1654 if (id->driver_data == mt_classes[i].name) {
1655 mtclass = &(mt_classes[i]);
1656 break;
Benjamin Tissoires2d936662011-01-11 16:45:54 +01001657 }
1658 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001659
Benjamin Tissoiresc08d46a2013-07-24 19:38:05 +02001660 td = devm_kzalloc(&hdev->dev, sizeof(struct mt_device), GFP_KERNEL);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001661 if (!td) {
1662 dev_err(&hdev->dev, "cannot allocate multitouch data\n");
1663 return -ENOMEM;
1664 }
Kees Cook0ee32772017-10-04 17:53:24 -07001665 td->hdev = hdev;
Benjamin Tissoireseec29e32011-11-23 10:54:28 +01001666 td->mtclass = *mtclass;
Andrew Duggan9abebed2014-03-19 13:39:03 -07001667 td->inputmode_value = MT_INPUTMODE_TOUCHSCREEN;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001668 hid_set_drvdata(hdev, td);
1669
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001670 INIT_LIST_HEAD(&td->applications);
Benjamin Tissoires8dfe14b2018-07-13 16:13:47 +02001671 INIT_LIST_HEAD(&td->reports);
Benjamin Tissoiresf146d1c2018-07-13 16:13:45 +02001672
Henrik Rydberg76f59022012-09-01 20:11:34 +02001673 if (id->vendor == HID_ANY_ID && id->product == HID_ANY_ID)
1674 td->serial_maybe = true;
1675
Benjamin Tissoiresb897f6d2016-11-25 14:27:22 +01001676 /* This allows the driver to correctly support devices
1677 * that emit events over several HID messages.
1678 */
1679 hdev->quirks |= HID_QUIRK_NO_INPUT_SYNC;
1680
1681 /*
1682 * This allows the driver to handle different input sensors
Benjamin Tissoires40ec2602018-04-24 10:04:35 +02001683 * that emits events through different applications on the same HID
Benjamin Tissoiresb897f6d2016-11-25 14:27:22 +01001684 * device.
1685 */
Benjamin Tissoires40ec2602018-04-24 10:04:35 +02001686 hdev->quirks |= HID_QUIRK_INPUT_PER_APP;
Benjamin Tissoiresb897f6d2016-11-25 14:27:22 +01001687
Kees Cook0ee32772017-10-04 17:53:24 -07001688 timer_setup(&td->release_timer, mt_expired_timeout, 0);
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +02001689
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001690 ret = hid_parse(hdev);
1691 if (ret != 0)
Benjamin Tissoiresc08d46a2013-07-24 19:38:05 +02001692 return ret;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001693
Benjamin Tissoiresf3287a92017-01-30 10:48:06 +01001694 if (mtclass->quirks & MT_QUIRK_FIX_CONST_CONTACT_ID)
1695 mt_fix_const_fields(hdev, HID_DG_CONTACTID);
1696
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001697 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
Benjamin Tissoires2d936662011-01-11 16:45:54 +01001698 if (ret)
Benjamin Tissoiresc08d46a2013-07-24 19:38:05 +02001699 return ret;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001700
Benjamin Tissoireseec29e32011-11-23 10:54:28 +01001701 ret = sysfs_create_group(&hdev->dev.kobj, &mt_attribute_group);
Nicholas Krause0c4b3c62016-02-04 10:52:40 -05001702 if (ret)
1703 dev_warn(&hdev->dev, "Cannot allocate sysfs group for %s\n",
1704 hdev->name);
Benjamin Tissoireseec29e32011-11-23 10:54:28 +01001705
Benjamin Tissoires02946f42018-04-24 10:04:37 +02001706 mt_set_modes(hdev, HID_LATENCY_NORMAL, true, true);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001707
1708 return 0;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001709}
1710
1711#ifdef CONFIG_PM
1712static int mt_reset_resume(struct hid_device *hdev)
1713{
Benson Leungd3e69b92016-03-11 14:19:49 -08001714 mt_release_contacts(hdev);
Benjamin Tissoires02946f42018-04-24 10:04:37 +02001715 mt_set_modes(hdev, HID_LATENCY_NORMAL, true, true);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001716 return 0;
1717}
Scott Liudfeefd12012-08-15 17:21:55 +08001718
1719static int mt_resume(struct hid_device *hdev)
1720{
Scott Liudfeefd12012-08-15 17:21:55 +08001721 /* Some Elan legacy devices require SET_IDLE to be set on resume.
1722 * It should be safe to send it to other devices too.
1723 * Tested on 3M, Stantum, Cypress, Zytronic, eGalax, and Elan panels. */
1724
Benjamin Tissoires4ba25d32013-02-27 16:38:18 +01001725 hid_hw_idle(hdev, 0, 0, HID_REQ_SET_IDLE);
Scott Liudfeefd12012-08-15 17:21:55 +08001726
1727 return 0;
1728}
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001729#endif
1730
1731static void mt_remove(struct hid_device *hdev)
1732{
Benjamin Tissoiresb897f6d2016-11-25 14:27:22 +01001733 struct mt_device *td = hid_get_drvdata(hdev);
1734
Benjamin Tissoires4f4001b2017-06-15 15:32:04 +02001735 del_timer_sync(&td->release_timer);
1736
Benjamin Tissoireseec29e32011-11-23 10:54:28 +01001737 sysfs_remove_group(&hdev->dev.kobj, &mt_attribute_group);
Benjamin Tissoires59392122013-05-29 10:45:09 +02001738 hid_hw_stop(hdev);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001739}
1740
Benjamin Tissoires0fa9c612014-02-28 11:41:23 -05001741/*
1742 * This list contains only:
1743 * - VID/PID of products not working with the default multitouch handling
1744 * - 2 generic rules.
1745 * So there is no point in adding here any device with MT_CLS_DEFAULT.
1746 */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001747static const struct hid_device_id mt_devices[] = {
1748
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +01001749 /* 3M panels */
1750 { .driver_data = MT_CLS_3M,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001751 MT_USB_DEVICE(USB_VENDOR_ID_3M,
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +01001752 USB_DEVICE_ID_3M1968) },
1753 { .driver_data = MT_CLS_3M,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001754 MT_USB_DEVICE(USB_VENDOR_ID_3M,
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +01001755 USB_DEVICE_ID_3M2256) },
Benjamin Tissoiresc4fad872011-12-23 15:41:00 +01001756 { .driver_data = MT_CLS_3M,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001757 MT_USB_DEVICE(USB_VENDOR_ID_3M,
Benjamin Tissoiresc4fad872011-12-23 15:41:00 +01001758 USB_DEVICE_ID_3M3266) },
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +01001759
Masaki Ota504c9322017-06-16 09:29:39 +09001760 /* Alps devices */
1761 { .driver_data = MT_CLS_WIN_8_DUAL,
1762 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
1763 USB_VENDOR_ID_ALPS_JP,
1764 HID_DEVICE_ID_ALPS_U1_DUAL_PTP) },
1765 { .driver_data = MT_CLS_WIN_8_DUAL,
1766 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
1767 USB_VENDOR_ID_ALPS_JP,
1768 HID_DEVICE_ID_ALPS_U1_DUAL_3BTN_PTP) },
1769
Pavel Tatashin56d859e2017-08-25 18:06:04 -04001770 /* Lenovo X1 TAB Gen 2 */
1771 { .driver_data = MT_CLS_WIN_8_DUAL,
1772 HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8,
1773 USB_VENDOR_ID_LENOVO,
1774 USB_DEVICE_ID_LENOVO_X1_TAB) },
1775
Benjamin Tissoires6aef7042014-02-28 11:41:25 -05001776 /* Anton devices */
1777 { .driver_data = MT_CLS_EXPORT_ALL_INPUTS,
1778 MT_USB_DEVICE(USB_VENDOR_ID_ANTON,
1779 USB_DEVICE_ID_ANTON_TOUCH_PAD) },
Benjamin Tissoirese6aac342011-05-19 14:18:13 +02001780
João Paulo Rechi Vita957b8df2017-07-24 14:22:25 -07001781 /* Asus T304UA */
1782 { .driver_data = MT_CLS_ASUS,
1783 HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8,
1784 USB_VENDOR_ID_ASUSTEK,
1785 USB_DEVICE_ID_ASUSTEK_T304_KEYBOARD) },
1786
Benjamin Tissoiresb1057122011-12-23 15:40:59 +01001787 /* Atmel panels */
1788 { .driver_data = MT_CLS_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001789 MT_USB_DEVICE(USB_VENDOR_ID_ATMEL,
Benjamin Tissoires841cb152012-03-06 10:53:45 +01001790 USB_DEVICE_ID_ATMEL_MXT_DIGITIZER) },
Benjamin Tissoiresb1057122011-12-23 15:40:59 +01001791
Jiri Kosina9ed32692012-04-20 12:15:44 +02001792 /* Baanto multitouch devices */
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01001793 { .driver_data = MT_CLS_NSMU,
Jiri Kosina16b79bb2012-05-05 23:32:54 +02001794 MT_USB_DEVICE(USB_VENDOR_ID_BAANTO,
Jiri Kosina9ed32692012-04-20 12:15:44 +02001795 USB_DEVICE_ID_BAANTO_MT_190W2) },
Benjamin Tissoires0fa9c612014-02-28 11:41:23 -05001796
Benjamin Tissoiresa841b622011-03-18 14:27:54 +01001797 /* Cando panels */
1798 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001799 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
Benjamin Tissoiresa841b622011-03-18 14:27:54 +01001800 USB_DEVICE_ID_CANDO_MULTI_TOUCH) },
Benjamin Tissoiresa841b622011-03-18 14:27:54 +01001801 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001802 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
Benjamin Tissoiresa841b622011-03-18 14:27:54 +01001803 USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6) },
1804
Austin Zhang942fd422011-05-28 02:03:47 +08001805 /* Chunghwa Telecom touch panels */
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01001806 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001807 MT_USB_DEVICE(USB_VENDOR_ID_CHUNGHWAT,
Austin Zhang942fd422011-05-28 02:03:47 +08001808 USB_DEVICE_ID_CHUNGHWAT_MULTITOUCH) },
1809
Yang Bo070f63b2015-07-20 09:40:28 -07001810 /* CJTouch panels */
1811 { .driver_data = MT_CLS_NSMU,
1812 MT_USB_DEVICE(USB_VENDOR_ID_CJTOUCH,
1813 USB_DEVICE_ID_CJTOUCH_MULTI_TOUCH_0020) },
1814 { .driver_data = MT_CLS_NSMU,
1815 MT_USB_DEVICE(USB_VENDOR_ID_CJTOUCH,
1816 USB_DEVICE_ID_CJTOUCH_MULTI_TOUCH_0040) },
1817
Benjamin Tissoires79603dc2011-05-19 14:18:14 +02001818 /* CVTouch panels */
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01001819 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001820 MT_USB_DEVICE(USB_VENDOR_ID_CVTOUCH,
Benjamin Tissoires79603dc2011-05-19 14:18:14 +02001821 USB_DEVICE_ID_CVTOUCH_SCREEN) },
1822
Benjamin Tissoires22408282011-05-20 15:59:34 +02001823 /* eGalax devices (resistive) */
Benjamin Tissoirese36f6902011-11-23 10:54:31 +01001824 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001825 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +01001826 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480D) },
1827 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001828 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +01001829 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480E) },
Benjamin Tissoires22408282011-05-20 15:59:34 +02001830
1831 /* eGalax devices (capacitive) */
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +01001832 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001833 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +01001834 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7207) },
Benjamin Tissoirese36f6902011-11-23 10:54:31 +01001835 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001836 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +01001837 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_720C) },
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +01001838 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001839 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +01001840 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7224) },
Benjamin Tissoires2ce09df2012-03-06 17:57:02 +01001841 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001842 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoires2ce09df2012-03-06 17:57:02 +01001843 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_722A) },
Benjamin Tissoires22408282011-05-20 15:59:34 +02001844 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001845 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoires22408282011-05-20 15:59:34 +02001846 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_725E) },
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +01001847 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001848 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +01001849 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7262) },
Benjamin Tissoirese36f6902011-11-23 10:54:31 +01001850 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001851 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoires22408282011-05-20 15:59:34 +02001852 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_726B) },
Benjamin Tissoires22408282011-05-20 15:59:34 +02001853 { .driver_data = MT_CLS_EGALAX,
1854 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +01001855 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72A1) },
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +01001856 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001857 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +01001858 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72AA) },
Benjamin Tissoirese36f6902011-11-23 10:54:31 +01001859 { .driver_data = MT_CLS_EGALAX,
Andy Shevchenkoaa672da2013-05-17 14:34:48 +03001860 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
1861 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72C4) },
1862 { .driver_data = MT_CLS_EGALAX,
1863 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
1864 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72D0) },
1865 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001866 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoires66f06122011-11-23 10:54:33 +01001867 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72FA) },
1868 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001869 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Marek Vasutbb9ff212011-11-23 10:54:32 +01001870 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7302) },
Benjamin Tissoires1b723e82011-11-23 10:54:34 +01001871 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001872 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +01001873 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7349) },
1874 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001875 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Thierry Redingae01c9e2012-08-09 08:34:48 +02001876 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_73F7) },
1877 { .driver_data = MT_CLS_EGALAX_SERIAL,
1878 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +01001879 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_A001) },
Benjamin Tissoires22408282011-05-20 15:59:34 +02001880
Tomas Sokorai7c7606a2014-04-23 10:42:41 -04001881 /* Elitegroup panel */
1882 { .driver_data = MT_CLS_SERIAL,
1883 MT_USB_DEVICE(USB_VENDOR_ID_ELITEGROUP,
1884 USB_DEVICE_ID_ELITEGROUP_05D8) },
1885
Henrik Rydberg77723e32012-09-07 19:37:40 +02001886 /* Flatfrog Panels */
1887 { .driver_data = MT_CLS_FLATFROG,
1888 MT_USB_DEVICE(USB_VENDOR_ID_FLATFROG,
1889 USB_DEVICE_ID_MULTITOUCH_3200) },
1890
Benjamin Tissoires3db187e2014-01-23 16:33:14 -05001891 /* FocalTech Panels */
1892 { .driver_data = MT_CLS_SERIAL,
1893 MT_USB_DEVICE(USB_VENDOR_ID_CYGNAL,
1894 USB_DEVICE_ID_FOCALTECH_FTXXXX_MULTITOUCH) },
1895
Benjamin Tissoires5572da02011-01-07 23:47:27 +01001896 /* GeneralTouch panel */
Xianhan Yuf5ff4e12012-09-28 10:18:59 +08001897 { .driver_data = MT_CLS_GENERALTOUCH_TWOFINGERS,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001898 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
Benjamin Tissoires5572da02011-01-07 23:47:27 +01001899 USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS) },
Xianhan Yuf5ff4e12012-09-28 10:18:59 +08001900 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
1901 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1902 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PWT_TENFINGERS) },
Luosong7b226292013-10-02 11:20:00 +02001903 { .driver_data = MT_CLS_GENERALTOUCH_TWOFINGERS,
1904 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1905 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0101) },
1906 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
1907 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1908 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0102) },
1909 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
1910 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1911 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0106) },
1912 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
1913 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1914 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_010A) },
1915 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
1916 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1917 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_E100) },
Benjamin Tissoires5572da02011-01-07 23:47:27 +01001918
Andreas Nielsen4d5df5d2012-03-19 15:41:03 +01001919 /* Gametel game controller */
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01001920 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001921 MT_BT_DEVICE(USB_VENDOR_ID_FRUCTEL,
Andreas Nielsen4d5df5d2012-03-19 15:41:03 +01001922 USB_DEVICE_ID_GAMETEL_MT_MODE) },
1923
Benjamin Tissoiresee0fbd12011-05-19 14:18:15 +02001924 /* GoodTouch panels */
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01001925 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001926 MT_USB_DEVICE(USB_VENDOR_ID_GOODTOUCH,
Benjamin Tissoiresee0fbd12011-05-19 14:18:15 +02001927 USB_DEVICE_ID_GOODTOUCH_000f) },
1928
Benjamin Tissoires54580362011-11-29 13:13:12 +01001929 /* Hanvon panels */
1930 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001931 MT_USB_DEVICE(USB_VENDOR_ID_HANVON_ALT,
Benjamin Tissoires54580362011-11-29 13:13:12 +01001932 USB_DEVICE_ID_HANVON_ALT_MULTITOUCH) },
1933
Austin Zhang4e61f0d2011-05-09 23:54:14 +08001934 /* Ilitek dual touch panel */
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01001935 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001936 MT_USB_DEVICE(USB_VENDOR_ID_ILITEK,
Austin Zhang4e61f0d2011-05-09 23:54:14 +08001937 USB_DEVICE_ID_ILITEK_MULTITOUCH) },
1938
Benjamin Tissoiresf3287a92017-01-30 10:48:06 +01001939 /* LG Melfas panel */
1940 { .driver_data = MT_CLS_LG,
1941 HID_USB_DEVICE(USB_VENDOR_ID_LG,
1942 USB_DEVICE_ID_LG_MELFAS_MT) },
1943
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +02001944 /* MosArt panels */
1945 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001946 MT_USB_DEVICE(USB_VENDOR_ID_ASUS,
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +02001947 USB_DEVICE_ID_ASUS_T91MT)},
1948 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001949 MT_USB_DEVICE(USB_VENDOR_ID_ASUS,
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +02001950 USB_DEVICE_ID_ASUSTEK_MULTITOUCH_YFO) },
1951 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001952 MT_USB_DEVICE(USB_VENDOR_ID_TURBOX,
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +02001953 USB_DEVICE_ID_TURBOX_TOUCHSCREEN_MOSART) },
1954
Austin Hendrix4db703e2012-06-04 15:27:51 -07001955 /* Novatek Panel */
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01001956 { .driver_data = MT_CLS_NSMU,
Jiri Kosina4380d812012-06-06 16:28:33 +02001957 MT_USB_DEVICE(USB_VENDOR_ID_NOVATEK,
Austin Hendrix4db703e2012-06-04 15:27:51 -07001958 USB_DEVICE_ID_NOVATEK_PCT) },
1959
Benjamin Tissoiresa80e8032016-05-31 17:31:15 +02001960 /* Ntrig Panel */
1961 { .driver_data = MT_CLS_NSMU,
1962 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
1963 USB_VENDOR_ID_NTRIG, 0x1b05) },
1964
Hans de Goedefb55b402017-11-22 12:57:07 +01001965 /* Panasonic panels */
1966 { .driver_data = MT_CLS_PANASONIC,
1967 MT_USB_DEVICE(USB_VENDOR_ID_PANASONIC,
1968 USB_DEVICE_ID_PANABOARD_UBT780) },
1969 { .driver_data = MT_CLS_PANASONIC,
1970 MT_USB_DEVICE(USB_VENDOR_ID_PANASONIC,
1971 USB_DEVICE_ID_PANABOARD_UBT880) },
1972
Aaron Tianb7ea95f2011-12-15 11:09:06 +08001973 /* PixArt optical touch screen */
1974 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001975 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
Aaron Tianb7ea95f2011-12-15 11:09:06 +08001976 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN) },
1977 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001978 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
Aaron Tianb7ea95f2011-12-15 11:09:06 +08001979 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN1) },
1980 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001981 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
Aaron Tianb7ea95f2011-12-15 11:09:06 +08001982 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN2) },
1983
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001984 /* PixCir-based panels */
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +01001985 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001986 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001987 USB_DEVICE_ID_CANDO_PIXCIR_MULTI_TOUCH) },
1988
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +01001989 /* Quanta-based panels */
1990 { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001991 MT_USB_DEVICE(USB_VENDOR_ID_QUANTA,
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +01001992 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3001) },
Forest Bonda6802e02013-10-21 12:38:49 -04001993
Benjamin Tissoires843e4752018-03-20 12:04:46 +01001994 /* Razer touchpads */
1995 { .driver_data = MT_CLS_RAZER_BLADE_STEALTH,
1996 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
1997 USB_VENDOR_ID_SYNAPTICS, 0x8323) },
1998
Benjamin Tissoires043b4032011-03-18 14:27:53 +01001999 /* Stantum panels */
Benjamin Tissoiresbf5af9b2011-05-19 14:18:18 +02002000 { .driver_data = MT_CLS_CONFIDENCE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02002001 MT_USB_DEVICE(USB_VENDOR_ID_STANTUM_STM,
Benjamin Tissoires043b4032011-03-18 14:27:53 +01002002 USB_DEVICE_ID_MTP_STM)},
Benjamin Tissoires043b4032011-03-18 14:27:53 +01002003
Benjamin Tissoires847672c2012-02-04 17:08:50 +01002004 /* TopSeed panels */
2005 { .driver_data = MT_CLS_TOPSEED,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02002006 MT_USB_DEVICE(USB_VENDOR_ID_TOPSEED2,
Benjamin Tissoires847672c2012-02-04 17:08:50 +01002007 USB_DEVICE_ID_TOPSEED2_PERIPAD_701) },
2008
Benjamin Tissoires5e74e562011-05-19 14:18:16 +02002009 /* Touch International panels */
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01002010 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02002011 MT_USB_DEVICE(USB_VENDOR_ID_TOUCH_INTL,
Benjamin Tissoires5e74e562011-05-19 14:18:16 +02002012 USB_DEVICE_ID_TOUCH_INTL_MULTI_TOUCH) },
2013
Benjamin Tissoires617b64f2011-05-19 14:18:17 +02002014 /* Unitec panels */
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01002015 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02002016 MT_USB_DEVICE(USB_VENDOR_ID_UNITEC,
Benjamin Tissoires617b64f2011-05-19 14:18:17 +02002017 USB_DEVICE_ID_UNITEC_USB_TOUCH_0709) },
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01002018 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02002019 MT_USB_DEVICE(USB_VENDOR_ID_UNITEC,
Benjamin Tissoires617b64f2011-05-19 14:18:17 +02002020 USB_DEVICE_ID_UNITEC_USB_TOUCH_0A19) },
KaiChung Chengbf9d1212013-11-21 10:04:30 +01002021
Mathieu Magnaudetda10bc22014-11-22 12:02:07 +01002022 /* VTL panels */
2023 { .driver_data = MT_CLS_VTL,
2024 MT_USB_DEVICE(USB_VENDOR_ID_VTL,
2025 USB_DEVICE_ID_VTL_MULTITOUCH_FF3F) },
2026
KaiChung Chengbf9d1212013-11-21 10:04:30 +01002027 /* Wistron panels */
2028 { .driver_data = MT_CLS_NSMU,
2029 MT_USB_DEVICE(USB_VENDOR_ID_WISTRON,
2030 USB_DEVICE_ID_WISTRON_OPTICAL_TOUCH) },
2031
ice chienbc8a2a92011-07-15 16:58:06 +08002032 /* XAT */
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01002033 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02002034 MT_USB_DEVICE(USB_VENDOR_ID_XAT,
ice chienbc8a2a92011-07-15 16:58:06 +08002035 USB_DEVICE_ID_XAT_CSR) },
Benjamin Tissoires617b64f2011-05-19 14:18:17 +02002036
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09002037 /* Xiroku */
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01002038 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02002039 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09002040 USB_DEVICE_ID_XIROKU_SPX) },
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01002041 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02002042 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09002043 USB_DEVICE_ID_XIROKU_MPX) },
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01002044 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02002045 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09002046 USB_DEVICE_ID_XIROKU_CSR) },
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01002047 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02002048 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09002049 USB_DEVICE_ID_XIROKU_SPX1) },
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01002050 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02002051 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09002052 USB_DEVICE_ID_XIROKU_MPX1) },
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01002053 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02002054 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09002055 USB_DEVICE_ID_XIROKU_CSR1) },
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01002056 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02002057 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09002058 USB_DEVICE_ID_XIROKU_SPX2) },
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01002059 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02002060 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09002061 USB_DEVICE_ID_XIROKU_MPX2) },
Benjamin Tissoiresdc3e1d82013-01-31 17:22:31 +01002062 { .driver_data = MT_CLS_NSMU,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02002063 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09002064 USB_DEVICE_ID_XIROKU_CSR2) },
2065
Wei-Ning Huang0e822322017-06-21 10:43:25 +08002066 /* Google MT devices */
2067 { .driver_data = MT_CLS_GOOGLE,
2068 HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY, USB_VENDOR_ID_GOOGLE,
2069 USB_DEVICE_ID_GOOGLE_TOUCH_ROSE) },
2070
Henrik Rydberg4fa3a582012-05-01 08:40:01 +02002071 /* Generic MT device */
2072 { HID_DEVICE(HID_BUS_ANY, HID_GROUP_MULTITOUCH, HID_ANY_ID, HID_ANY_ID) },
Benjamin Tissoiresf961bd32013-08-22 14:51:08 +02002073
2074 /* Generic Win 8 certified MT device */
2075 { .driver_data = MT_CLS_WIN_8,
2076 HID_DEVICE(HID_BUS_ANY, HID_GROUP_MULTITOUCH_WIN_8,
2077 HID_ANY_ID, HID_ANY_ID) },
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01002078 { }
2079};
2080MODULE_DEVICE_TABLE(hid, mt_devices);
2081
2082static const struct hid_usage_id mt_grabbed_usages[] = {
2083 { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID },
2084 { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
2085};
2086
2087static struct hid_driver mt_driver = {
2088 .name = "hid-multitouch",
2089 .id_table = mt_devices,
2090 .probe = mt_probe,
2091 .remove = mt_remove,
2092 .input_mapping = mt_input_mapping,
2093 .input_mapped = mt_input_mapped,
Henrik Rydberg76f59022012-09-01 20:11:34 +02002094 .input_configured = mt_input_configured,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01002095 .feature_mapping = mt_feature_mapping,
2096 .usage_table = mt_grabbed_usages,
2097 .event = mt_event,
Benjamin Tissoires55978fa2013-01-31 17:22:24 +01002098 .report = mt_report,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01002099#ifdef CONFIG_PM
2100 .reset_resume = mt_reset_resume,
Scott Liudfeefd12012-08-15 17:21:55 +08002101 .resume = mt_resume,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01002102#endif
2103};
H Hartley Sweetenf4254582012-12-17 15:28:26 -07002104module_hid_driver(mt_driver);