hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/hid/hid-multitouch.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * HID driver for multitouch panels
34 *
....@@ -17,14 +18,9 @@
1718 * Copyright (c) 2009-2010 Stephane Chatty <chatty@enac.fr>
1819 * Copyright (c) 2010 Henrik Rydberg <rydberg@euromail.se>
1920 * Copyright (c) 2010 Canonical, Ltd.
20
- *
2121 */
2222
2323 /*
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.
2824 */
2925
3026 /*
....@@ -72,6 +68,8 @@
7268 #define MT_QUIRK_STICKY_FINGERS BIT(16)
7369 #define MT_QUIRK_ASUS_CUSTOM_UP BIT(17)
7470 #define MT_QUIRK_WIN8_PTP_BUTTONS BIT(18)
71
+#define MT_QUIRK_SEPARATE_APP_REPORT BIT(19)
72
+#define MT_QUIRK_FORCE_MULTI_INPUT BIT(20)
7573
7674 #define MT_INPUTMODE_TOUCHSCREEN 0x02
7775 #define MT_INPUTMODE_TOUCHPAD 0x03
....@@ -107,6 +105,7 @@
107105 struct mt_application {
108106 struct list_head list;
109107 unsigned int application;
108
+ unsigned int report_id;
110109 struct list_head mt_usages; /* mt usages list */
111110
112111 __s32 quirks;
....@@ -190,7 +189,8 @@
190189 /* reserved 0x0011 */
191190 #define MT_CLS_WIN_8 0x0012
192191 #define MT_CLS_EXPORT_ALL_INPUTS 0x0013
193
-#define MT_CLS_WIN_8_DUAL 0x0014
192
+/* reserved 0x0014 */
193
+#define MT_CLS_WIN_8_FORCE_MULTI_INPUT 0x0015
194194
195195 /* vendor specific classes */
196196 #define MT_CLS_3M 0x0101
....@@ -207,6 +207,7 @@
207207 #define MT_CLS_VTL 0x0110
208208 #define MT_CLS_GOOGLE 0x0111
209209 #define MT_CLS_RAZER_BLADE_STEALTH 0x0112
210
+#define MT_CLS_SMART_TECH 0x0113
210211
211212 #define MT_DEFAULT_MAXCONTACT 10
212213 #define MT_MAX_MAXCONTACT 250
....@@ -267,17 +268,20 @@
267268 MT_QUIRK_HOVERING |
268269 MT_QUIRK_CONTACT_CNT_ACCURATE |
269270 MT_QUIRK_STICKY_FINGERS |
270
- MT_QUIRK_WIN8_PTP_BUTTONS },
271
+ MT_QUIRK_WIN8_PTP_BUTTONS,
272
+ .export_all_inputs = true },
271273 { .name = MT_CLS_EXPORT_ALL_INPUTS,
272274 .quirks = MT_QUIRK_ALWAYS_VALID |
273275 MT_QUIRK_CONTACT_CNT_ACCURATE,
274276 .export_all_inputs = true },
275
- { .name = MT_CLS_WIN_8_DUAL,
277
+ { .name = MT_CLS_WIN_8_FORCE_MULTI_INPUT,
276278 .quirks = MT_QUIRK_ALWAYS_VALID |
277279 MT_QUIRK_IGNORE_DUPLICATES |
278280 MT_QUIRK_HOVERING |
279281 MT_QUIRK_CONTACT_CNT_ACCURATE |
280
- MT_QUIRK_WIN8_PTP_BUTTONS,
282
+ MT_QUIRK_STICKY_FINGERS |
283
+ MT_QUIRK_WIN8_PTP_BUTTONS |
284
+ MT_QUIRK_FORCE_MULTI_INPUT,
281285 .export_all_inputs = true },
282286
283287 /*
....@@ -356,6 +360,12 @@
356360 MT_QUIRK_HOVERING |
357361 MT_QUIRK_CONTACT_CNT_ACCURATE |
358362 MT_QUIRK_WIN8_PTP_BUTTONS,
363
+ },
364
+ { .name = MT_CLS_SMART_TECH,
365
+ .quirks = MT_QUIRK_ALWAYS_VALID |
366
+ MT_QUIRK_IGNORE_DUPLICATES |
367
+ MT_QUIRK_CONTACT_CNT_ACCURATE |
368
+ MT_QUIRK_SEPARATE_APP_REPORT,
359369 },
360370 { }
361371 };
....@@ -513,8 +523,9 @@
513523 }
514524
515525 static struct mt_application *mt_allocate_application(struct mt_device *td,
516
- unsigned int application)
526
+ struct hid_report *report)
517527 {
528
+ unsigned int application = report->application;
518529 struct mt_application *mt_application;
519530
520531 mt_application = devm_kzalloc(&td->hdev->dev, sizeof(*mt_application),
....@@ -539,6 +550,7 @@
539550 mt_application->scantime = DEFAULT_ZERO;
540551 mt_application->raw_cc = DEFAULT_ZERO;
541552 mt_application->quirks = td->mtclass.quirks;
553
+ mt_application->report_id = report->id;
542554
543555 list_add_tail(&mt_application->list, &td->applications);
544556
....@@ -546,19 +558,23 @@
546558 }
547559
548560 static struct mt_application *mt_find_application(struct mt_device *td,
549
- unsigned int application)
561
+ struct hid_report *report)
550562 {
563
+ unsigned int application = report->application;
551564 struct mt_application *tmp, *mt_application = NULL;
552565
553566 list_for_each_entry(tmp, &td->applications, list) {
554567 if (application == tmp->application) {
555
- mt_application = tmp;
556
- break;
568
+ if (!(td->mtclass.quirks & MT_QUIRK_SEPARATE_APP_REPORT) ||
569
+ tmp->report_id == report->id) {
570
+ mt_application = tmp;
571
+ break;
572
+ }
557573 }
558574 }
559575
560576 if (!mt_application)
561
- mt_application = mt_allocate_application(td, application);
577
+ mt_application = mt_allocate_application(td, report);
562578
563579 return mt_application;
564580 }
....@@ -575,7 +591,7 @@
575591 return NULL;
576592
577593 rdata->report = report;
578
- rdata->application = mt_find_application(td, report->application);
594
+ rdata->application = mt_find_application(td, report);
579595
580596 if (!rdata->application) {
581597 devm_kfree(&td->hdev->dev, rdata);
....@@ -747,7 +763,7 @@
747763 return 1;
748764 case HID_DG_CONFIDENCE:
749765 if ((cls->name == MT_CLS_WIN_8 ||
750
- cls->name == MT_CLS_WIN_8_DUAL) &&
766
+ cls->name == MT_CLS_WIN_8_FORCE_MULTI_INPUT) &&
751767 (field->application == HID_DG_TOUCHPAD ||
752768 field->application == HID_DG_TOUCHSCREEN))
753769 app->quirks |= MT_QUIRK_CONFIDENCE;
....@@ -890,7 +906,7 @@
890906 clear_bit(slotnum, app->pending_palm_slots);
891907
892908 input_mt_slot(input, slotnum);
893
- input_mt_report_slot_state(input, MT_TOOL_PALM, false);
909
+ input_mt_report_slot_inactive(input);
894910
895911 need_sync = true;
896912 }
....@@ -1139,7 +1155,7 @@
11391155 int contact_count = -1;
11401156
11411157 /* sticky fingers release in progress, abort */
1142
- if (test_and_set_bit(MT_IO_FLAGS_RUNNING, &td->mt_io_flags))
1158
+ if (test_and_set_bit_lock(MT_IO_FLAGS_RUNNING, &td->mt_io_flags))
11431159 return;
11441160
11451161 scantime = *app->scantime;
....@@ -1220,7 +1236,7 @@
12201236 del_timer(&td->release_timer);
12211237 }
12221238
1223
- clear_bit(MT_IO_FLAGS_RUNNING, &td->mt_io_flags);
1239
+ clear_bit_unlock(MT_IO_FLAGS_RUNNING, &td->mt_io_flags);
12241240 }
12251241
12261242 static int mt_touch_input_configured(struct hid_device *hdev,
....@@ -1331,6 +1347,13 @@
13311347 if (rdata->is_mt_collection)
13321348 return mt_touch_input_mapping(hdev, hi, field, usage, bit, max,
13331349 application);
1350
+
1351
+ /*
1352
+ * some egalax touchscreens have "application == DG_TOUCHSCREEN"
1353
+ * for the stylus. Overwrite the hid_input application
1354
+ */
1355
+ if (field->physical == HID_DG_STYLUS)
1356
+ hi->application = HID_DG_STYLUS;
13341357
13351358 /* let hid-core decide for the others */
13361359 return 0;
....@@ -1518,16 +1541,13 @@
15181541 static int mt_input_configured(struct hid_device *hdev, struct hid_input *hi)
15191542 {
15201543 struct mt_device *td = hid_get_drvdata(hdev);
1521
- char *name;
15221544 const char *suffix = NULL;
1523
- unsigned int application = 0;
15241545 struct mt_report_data *rdata;
15251546 struct mt_application *mt_application = NULL;
15261547 struct hid_report *report;
15271548 int ret;
15281549
15291550 list_for_each_entry(report, &hi->reports, hidinput_list) {
1530
- application = report->application;
15311551 rdata = mt_find_report_data(td, report);
15321552 if (!rdata) {
15331553 hid_err(hdev, "failed to allocate data for report\n");
....@@ -1542,57 +1562,41 @@
15421562 if (ret)
15431563 return ret;
15441564 }
1545
-
1546
- /*
1547
- * some egalax touchscreens have "application == DG_TOUCHSCREEN"
1548
- * for the stylus. Check this first, and then rely on
1549
- * the application field.
1550
- */
1551
- if (report->field[0]->physical == HID_DG_STYLUS) {
1552
- suffix = "Pen";
1553
- /* force BTN_STYLUS to allow tablet matching in udev */
1554
- __set_bit(BTN_STYLUS, hi->input->keybit);
1555
- }
15561565 }
15571566
1558
- if (!suffix) {
1559
- switch (application) {
1560
- case HID_GD_KEYBOARD:
1561
- case HID_GD_KEYPAD:
1562
- case HID_GD_MOUSE:
1563
- case HID_DG_TOUCHPAD:
1564
- case HID_GD_SYSTEM_CONTROL:
1565
- case HID_CP_CONSUMER_CONTROL:
1566
- case HID_GD_WIRELESS_RADIO_CTLS:
1567
- case HID_GD_SYSTEM_MULTIAXIS:
1568
- /* already handled by hid core */
1569
- break;
1570
- case HID_DG_TOUCHSCREEN:
1571
- /* we do not set suffix = "Touchscreen" */
1572
- hi->input->name = hdev->name;
1573
- break;
1574
- case HID_DG_STYLUS:
1575
- /* force BTN_STYLUS to allow tablet matching in udev */
1576
- __set_bit(BTN_STYLUS, hi->input->keybit);
1577
- break;
1578
- case HID_VD_ASUS_CUSTOM_MEDIA_KEYS:
1579
- suffix = "Custom Media Keys";
1580
- break;
1581
- default:
1582
- suffix = "UNKNOWN";
1583
- break;
1584
- }
1567
+ switch (hi->application) {
1568
+ case HID_GD_KEYBOARD:
1569
+ case HID_GD_KEYPAD:
1570
+ case HID_GD_MOUSE:
1571
+ case HID_DG_TOUCHPAD:
1572
+ case HID_GD_SYSTEM_CONTROL:
1573
+ case HID_CP_CONSUMER_CONTROL:
1574
+ case HID_GD_WIRELESS_RADIO_CTLS:
1575
+ case HID_GD_SYSTEM_MULTIAXIS:
1576
+ /* already handled by hid core */
1577
+ break;
1578
+ case HID_DG_TOUCHSCREEN:
1579
+ /* we do not set suffix = "Touchscreen" */
1580
+ hi->input->name = hdev->name;
1581
+ break;
1582
+ case HID_VD_ASUS_CUSTOM_MEDIA_KEYS:
1583
+ suffix = "Custom Media Keys";
1584
+ break;
1585
+ case HID_DG_STYLUS:
1586
+ /* force BTN_STYLUS to allow tablet matching in udev */
1587
+ __set_bit(BTN_STYLUS, hi->input->keybit);
1588
+ fallthrough;
1589
+ case HID_DG_PEN:
1590
+ suffix = "Stylus";
1591
+ break;
1592
+ default:
1593
+ suffix = "UNKNOWN";
1594
+ break;
15851595 }
15861596
1587
- if (suffix) {
1588
- name = devm_kzalloc(&hi->input->dev,
1589
- strlen(hdev->name) + strlen(suffix) + 2,
1590
- GFP_KERNEL);
1591
- if (name) {
1592
- sprintf(name, "%s %s", hdev->name, suffix);
1593
- hi->input->name = name;
1594
- }
1595
- }
1597
+ if (suffix)
1598
+ hi->input->name = devm_kasprintf(&hdev->dev, GFP_KERNEL,
1599
+ "%s %s", hdev->name, suffix);
15961600
15971601 return 0;
15981602 }
....@@ -1639,9 +1643,7 @@
16391643 if (mt) {
16401644 for (i = 0; i < mt->num_slots; i++) {
16411645 input_mt_slot(input_dev, i);
1642
- input_mt_report_slot_state(input_dev,
1643
- MT_TOOL_FINGER,
1644
- false);
1646
+ input_mt_report_slot_inactive(input_dev);
16451647 }
16461648 input_mt_sync_frame(input_dev);
16471649 input_sync(input_dev);
....@@ -1662,11 +1664,11 @@
16621664 * An input report came in just before we release the sticky fingers,
16631665 * it will take care of the sticky fingers.
16641666 */
1665
- if (test_and_set_bit(MT_IO_FLAGS_RUNNING, &td->mt_io_flags))
1667
+ if (test_and_set_bit_lock(MT_IO_FLAGS_RUNNING, &td->mt_io_flags))
16661668 return;
16671669 if (test_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags))
16681670 mt_release_contacts(hdev);
1669
- clear_bit(MT_IO_FLAGS_RUNNING, &td->mt_io_flags);
1671
+ clear_bit_unlock(MT_IO_FLAGS_RUNNING, &td->mt_io_flags);
16701672 }
16711673
16721674 static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
....@@ -1712,6 +1714,11 @@
17121714
17131715 if (id->group != HID_GROUP_MULTITOUCH_WIN_8)
17141716 hdev->quirks |= HID_QUIRK_MULTI_INPUT;
1717
+
1718
+ if (mtclass->quirks & MT_QUIRK_FORCE_MULTI_INPUT) {
1719
+ hdev->quirks &= ~HID_QUIRK_INPUT_PER_APP;
1720
+ hdev->quirks |= HID_QUIRK_MULTI_INPUT;
1721
+ }
17151722
17161723 timer_setup(&td->release_timer, mt_expired_timeout, 0);
17171724
....@@ -1785,26 +1792,6 @@
17851792 MT_USB_DEVICE(USB_VENDOR_ID_3M,
17861793 USB_DEVICE_ID_3M3266) },
17871794
1788
- /* Alps devices */
1789
- { .driver_data = MT_CLS_WIN_8_DUAL,
1790
- HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
1791
- USB_VENDOR_ID_ALPS_JP,
1792
- HID_DEVICE_ID_ALPS_U1_DUAL_PTP) },
1793
- { .driver_data = MT_CLS_WIN_8_DUAL,
1794
- HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
1795
- USB_VENDOR_ID_ALPS_JP,
1796
- HID_DEVICE_ID_ALPS_U1_DUAL_3BTN_PTP) },
1797
- { .driver_data = MT_CLS_WIN_8_DUAL,
1798
- HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
1799
- USB_VENDOR_ID_ALPS_JP,
1800
- HID_DEVICE_ID_ALPS_1222) },
1801
-
1802
- /* Lenovo X1 TAB Gen 2 */
1803
- { .driver_data = MT_CLS_WIN_8_DUAL,
1804
- HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8,
1805
- USB_VENDOR_ID_LENOVO,
1806
- USB_DEVICE_ID_LENOVO_X1_TAB) },
1807
-
18081795 /* Anton devices */
18091796 { .driver_data = MT_CLS_EXPORT_ALL_INPUTS,
18101797 MT_USB_DEVICE(USB_VENDOR_ID_ANTON,
....@@ -1838,12 +1825,6 @@
18381825 { .driver_data = MT_CLS_NSMU,
18391826 MT_USB_DEVICE(USB_VENDOR_ID_CHUNGHWAT,
18401827 USB_DEVICE_ID_CHUNGHWAT_MULTITOUCH) },
1841
-
1842
- /* Cirque devices */
1843
- { .driver_data = MT_CLS_WIN_8_DUAL,
1844
- HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
1845
- I2C_VENDOR_ID_CIRQUE,
1846
- I2C_PRODUCT_ID_CIRQUE_121F) },
18471828
18481829 /* CJTouch panels */
18491830 { .driver_data = MT_CLS_NSMU,
....@@ -1919,6 +1900,15 @@
19191900 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
19201901 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_C002) },
19211902
1903
+ /* Elan devices */
1904
+ { .driver_data = MT_CLS_WIN_8_FORCE_MULTI_INPUT,
1905
+ HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
1906
+ USB_VENDOR_ID_ELAN, 0x313a) },
1907
+
1908
+ { .driver_data = MT_CLS_WIN_8_FORCE_MULTI_INPUT,
1909
+ HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
1910
+ USB_VENDOR_ID_ELAN, 0x3148) },
1911
+
19221912 /* Elitegroup panel */
19231913 { .driver_data = MT_CLS_SERIAL,
19241914 MT_USB_DEVICE(USB_VENDOR_ID_ELITEGROUP,
....@@ -1985,6 +1975,24 @@
19851975 HID_DEVICE(BUS_I2C, HID_GROUP_GENERIC,
19861976 USB_VENDOR_ID_LG, I2C_DEVICE_ID_LG_7010) },
19871977
1978
+ /* Lenovo X1 TAB Gen 2 */
1979
+ { .driver_data = MT_CLS_WIN_8_FORCE_MULTI_INPUT,
1980
+ HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8,
1981
+ USB_VENDOR_ID_LENOVO,
1982
+ USB_DEVICE_ID_LENOVO_X1_TAB) },
1983
+
1984
+ /* Lenovo X1 TAB Gen 3 */
1985
+ { .driver_data = MT_CLS_WIN_8_FORCE_MULTI_INPUT,
1986
+ HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8,
1987
+ USB_VENDOR_ID_LENOVO,
1988
+ USB_DEVICE_ID_LENOVO_X1_TAB3) },
1989
+
1990
+ /* Lenovo X12 TAB Gen 1 */
1991
+ { .driver_data = MT_CLS_WIN_8_FORCE_MULTI_INPUT,
1992
+ HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8,
1993
+ USB_VENDOR_ID_LENOVO,
1994
+ USB_DEVICE_ID_LENOVO_X12_TAB) },
1995
+
19881996 /* MosArt panels */
19891997 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
19901998 MT_USB_DEVICE(USB_VENDOR_ID_ASUS,
....@@ -2040,10 +2048,23 @@
20402048 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
20412049 USB_VENDOR_ID_SYNAPTICS, 0x8323) },
20422050
2051
+ /* Smart Tech panels */
2052
+ { .driver_data = MT_CLS_SMART_TECH,
2053
+ MT_USB_DEVICE(0x0b8c, 0x0092)},
2054
+
20432055 /* Stantum panels */
20442056 { .driver_data = MT_CLS_CONFIDENCE,
20452057 MT_USB_DEVICE(USB_VENDOR_ID_STANTUM_STM,
20462058 USB_DEVICE_ID_MTP_STM)},
2059
+
2060
+ /* Synaptics devices */
2061
+ { .driver_data = MT_CLS_WIN_8_FORCE_MULTI_INPUT,
2062
+ HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
2063
+ USB_VENDOR_ID_SYNAPTICS, 0xce08) },
2064
+
2065
+ { .driver_data = MT_CLS_WIN_8_FORCE_MULTI_INPUT,
2066
+ HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
2067
+ USB_VENDOR_ID_SYNAPTICS, 0xce09) },
20472068
20482069 /* TopSeed panels */
20492070 { .driver_data = MT_CLS_TOPSEED,
....@@ -2111,6 +2132,9 @@
21112132 { .driver_data = MT_CLS_GOOGLE,
21122133 HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY, USB_VENDOR_ID_GOOGLE,
21132134 USB_DEVICE_ID_GOOGLE_TOUCH_ROSE) },
2135
+ { .driver_data = MT_CLS_GOOGLE,
2136
+ HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8, USB_VENDOR_ID_GOOGLE,
2137
+ USB_DEVICE_ID_GOOGLE_WHISKERS) },
21142138
21152139 /* Generic MT device */
21162140 { HID_DEVICE(HID_BUS_ANY, HID_GROUP_MULTITOUCH, HID_ANY_ID, HID_ANY_ID) },