hc
2024-01-05 071106ecf68c401173c58808b1cf5f68cc50d390
kernel/drivers/hid/wacom_wac.c
....@@ -11,6 +11,7 @@
1111 #include "wacom_wac.h"
1212 #include "wacom.h"
1313 #include <linux/input/mt.h>
14
+#include <linux/jiffies.h>
1415
1516 /* resolution for penabled devices */
1617 #define WACOM_PL_RES 20
....@@ -41,6 +42,43 @@
4142
4243 static void wacom_update_led(struct wacom *wacom, int button_count, int mask,
4344 int group);
45
+
46
+static void wacom_force_proxout(struct wacom_wac *wacom_wac)
47
+{
48
+ struct input_dev *input = wacom_wac->pen_input;
49
+
50
+ wacom_wac->shared->stylus_in_proximity = 0;
51
+
52
+ input_report_key(input, BTN_TOUCH, 0);
53
+ input_report_key(input, BTN_STYLUS, 0);
54
+ input_report_key(input, BTN_STYLUS2, 0);
55
+ input_report_key(input, BTN_STYLUS3, 0);
56
+ input_report_key(input, wacom_wac->tool[0], 0);
57
+ if (wacom_wac->serial[0]) {
58
+ input_report_abs(input, ABS_MISC, 0);
59
+ }
60
+ input_report_abs(input, ABS_PRESSURE, 0);
61
+
62
+ wacom_wac->tool[0] = 0;
63
+ wacom_wac->id[0] = 0;
64
+ wacom_wac->serial[0] = 0;
65
+
66
+ input_sync(input);
67
+}
68
+
69
+void wacom_idleprox_timeout(struct timer_list *list)
70
+{
71
+ struct wacom *wacom = from_timer(wacom, list, idleprox_timer);
72
+ struct wacom_wac *wacom_wac = &wacom->wacom_wac;
73
+
74
+ if (!wacom_wac->hid_data.sense_state) {
75
+ return;
76
+ }
77
+
78
+ hid_warn(wacom->hdev, "%s: tool appears to be hung in-prox. forcing it out.\n", __func__);
79
+ wacom_force_proxout(wacom_wac);
80
+}
81
+
4482 /*
4583 * Percent of battery capacity for Graphire.
4684 * 8th value means AC online and show 100% capacity.
....@@ -675,11 +713,14 @@
675713 case 0x802: /* Intuos4/5 13HD/24HD General Pen */
676714 case 0x8e2: /* IntuosHT2 pen */
677715 case 0x022:
716
+ case 0x200: /* Pro Pen 3 */
717
+ case 0x04200: /* Pro Pen 3 */
678718 case 0x10842: /* MobileStudio Pro Pro Pen slim */
679719 case 0x14802: /* Intuos4/5 13HD/24HD Classic Pen */
680720 case 0x16802: /* Cintiq 13HD Pro Pen */
681721 case 0x18802: /* DTH2242 Pen */
682722 case 0x10802: /* Intuos4/5 13HD/24HD General Pen */
723
+ case 0x80842: /* Intuos Pro and Cintiq Pro 3D Pen */
683724 tool_type = BTN_TOOL_PEN;
684725 break;
685726
....@@ -790,7 +831,7 @@
790831 /* Enter report */
791832 if ((data[1] & 0xfc) == 0xc0) {
792833 /* serial number of the tool */
793
- wacom->serial[idx] = ((data[3] & 0x0f) << 28) +
834
+ wacom->serial[idx] = ((__u64)(data[3] & 0x0f) << 28) +
794835 (data[4] << 20) + (data[5] << 12) +
795836 (data[6] << 4) + (data[7] >> 4);
796837
....@@ -1086,6 +1127,7 @@
10861127 if (index < 0 || !remote->remotes[index].registered)
10871128 goto out;
10881129
1130
+ remote->remotes[i].active_time = ktime_get();
10891131 input = remote->remotes[index].input;
10901132
10911133 input_report_key(input, BTN_0, (data[9] & 0x01));
....@@ -1265,6 +1307,9 @@
12651307
12661308 struct input_dev *pen_input = wacom->pen_input;
12671309 unsigned char *data = wacom->data;
1310
+ int number_of_valid_frames = 0;
1311
+ ktime_t time_interval = 15000000;
1312
+ ktime_t time_packet_received = ktime_get();
12681313 int i;
12691314
12701315 if (wacom->features.type == INTUOSP2_BT ||
....@@ -1285,12 +1330,30 @@
12851330 wacom->id[0] |= (wacom->serial[0] >> 32) & 0xFFFFF;
12861331 }
12871332
1333
+ /* number of valid frames */
12881334 for (i = 0; i < pen_frames; i++) {
1335
+ unsigned char *frame = &data[i*pen_frame_len + 1];
1336
+ bool valid = frame[0] & 0x80;
1337
+
1338
+ if (valid)
1339
+ number_of_valid_frames++;
1340
+ }
1341
+
1342
+ if (number_of_valid_frames) {
1343
+ if (wacom->hid_data.time_delayed)
1344
+ time_interval = ktime_get() - wacom->hid_data.time_delayed;
1345
+ time_interval = div_u64(time_interval, number_of_valid_frames);
1346
+ wacom->hid_data.time_delayed = time_packet_received;
1347
+ }
1348
+
1349
+ for (i = 0; i < number_of_valid_frames; i++) {
12891350 unsigned char *frame = &data[i*pen_frame_len + 1];
12901351 bool valid = frame[0] & 0x80;
12911352 bool prox = frame[0] & 0x40;
12921353 bool range = frame[0] & 0x20;
12931354 bool invert = frame[0] & 0x10;
1355
+ int frames_number_reversed = number_of_valid_frames - i - 1;
1356
+ ktime_t event_timestamp = time_packet_received - frames_number_reversed * time_interval;
12941357
12951358 if (!valid)
12961359 continue;
....@@ -1303,6 +1366,7 @@
13031366 wacom->tool[0] = 0;
13041367 wacom->id[0] = 0;
13051368 wacom->serial[0] = 0;
1369
+ wacom->hid_data.time_delayed = 0;
13061370 return;
13071371 }
13081372
....@@ -1339,6 +1403,7 @@
13391403 get_unaligned_le16(&frame[11]));
13401404 }
13411405 }
1406
+
13421407 if (wacom->tool[0]) {
13431408 input_report_abs(pen_input, ABS_PRESSURE, get_unaligned_le16(&frame[5]));
13441409 if (wacom->features.type == INTUOSP2_BT ||
....@@ -1361,6 +1426,9 @@
13611426 }
13621427
13631428 wacom->shared->stylus_in_proximity = prox;
1429
+
1430
+ /* add timestamp to unpack the frames */
1431
+ input_set_timestamp(pen_input, event_timestamp);
13641432
13651433 input_sync(pen_input);
13661434 }
....@@ -1853,6 +1921,7 @@
18531921 int fmax = field->logical_maximum;
18541922 unsigned int equivalent_usage = wacom_equivalent_usage(usage->hid);
18551923 int resolution_code = code;
1924
+ int resolution = hidinput_calc_abs_res(field, resolution_code);
18561925
18571926 if (equivalent_usage == HID_DG_TWIST) {
18581927 resolution_code = ABS_RZ;
....@@ -1875,8 +1944,15 @@
18751944 switch (type) {
18761945 case EV_ABS:
18771946 input_set_abs_params(input, code, fmin, fmax, fuzz, 0);
1878
- input_abs_set_res(input, code,
1879
- hidinput_calc_abs_res(field, resolution_code));
1947
+
1948
+ /* older tablet may miss physical usage */
1949
+ if ((code == ABS_X || code == ABS_Y) && !resolution) {
1950
+ resolution = WACOM_INTUOS_RES;
1951
+ hid_warn(input,
1952
+ "Wacom usage (%d) missing resolution \n",
1953
+ code);
1954
+ }
1955
+ input_abs_set_res(input, code, resolution);
18801956 break;
18811957 case EV_KEY:
18821958 input_set_capability(input, EV_KEY, code);
....@@ -1893,18 +1969,7 @@
18931969 static void wacom_wac_battery_usage_mapping(struct hid_device *hdev,
18941970 struct hid_field *field, struct hid_usage *usage)
18951971 {
1896
- struct wacom *wacom = hid_get_drvdata(hdev);
1897
- struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1898
- struct wacom_features *features = &wacom_wac->features;
1899
- unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
1900
-
1901
- switch (equivalent_usage) {
1902
- case HID_DG_BATTERYSTRENGTH:
1903
- case WACOM_HID_WD_BATTERY_LEVEL:
1904
- case WACOM_HID_WD_BATTERY_CHARGING:
1905
- features->quirks |= WACOM_QUIRK_BATTERY;
1906
- break;
1907
- }
1972
+ return;
19081973 }
19091974
19101975 static void wacom_wac_battery_event(struct hid_device *hdev, struct hid_field *field,
....@@ -1925,18 +1990,21 @@
19251990 wacom_wac->hid_data.bat_connected = 1;
19261991 wacom_wac->hid_data.bat_status = WACOM_POWER_SUPPLY_STATUS_AUTO;
19271992 }
1993
+ wacom_wac->features.quirks |= WACOM_QUIRK_BATTERY;
19281994 break;
19291995 case WACOM_HID_WD_BATTERY_LEVEL:
19301996 value = value * 100 / (field->logical_maximum - field->logical_minimum);
19311997 wacom_wac->hid_data.battery_capacity = value;
19321998 wacom_wac->hid_data.bat_connected = 1;
19331999 wacom_wac->hid_data.bat_status = WACOM_POWER_SUPPLY_STATUS_AUTO;
2000
+ wacom_wac->features.quirks |= WACOM_QUIRK_BATTERY;
19342001 break;
19352002 case WACOM_HID_WD_BATTERY_CHARGING:
19362003 wacom_wac->hid_data.bat_charging = value;
19372004 wacom_wac->hid_data.ps_connected = value;
19382005 wacom_wac->hid_data.bat_connected = 1;
19392006 wacom_wac->hid_data.bat_status = WACOM_POWER_SUPPLY_STATUS_AUTO;
2007
+ wacom_wac->features.quirks |= WACOM_QUIRK_BATTERY;
19402008 break;
19412009 }
19422010 }
....@@ -1952,18 +2020,15 @@
19522020 {
19532021 struct wacom *wacom = hid_get_drvdata(hdev);
19542022 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1955
- struct wacom_features *features = &wacom_wac->features;
19562023
1957
- if (features->quirks & WACOM_QUIRK_BATTERY) {
1958
- int status = wacom_wac->hid_data.bat_status;
1959
- int capacity = wacom_wac->hid_data.battery_capacity;
1960
- bool charging = wacom_wac->hid_data.bat_charging;
1961
- bool connected = wacom_wac->hid_data.bat_connected;
1962
- bool powered = wacom_wac->hid_data.ps_connected;
2024
+ int status = wacom_wac->hid_data.bat_status;
2025
+ int capacity = wacom_wac->hid_data.battery_capacity;
2026
+ bool charging = wacom_wac->hid_data.bat_charging;
2027
+ bool connected = wacom_wac->hid_data.bat_connected;
2028
+ bool powered = wacom_wac->hid_data.ps_connected;
19632029
1964
- wacom_notify_battery(wacom_wac, status, capacity, charging,
1965
- connected, powered);
1966
- }
2030
+ wacom_notify_battery(wacom_wac, status, capacity, charging,
2031
+ connected, powered);
19672032 }
19682033
19692034 static void wacom_wac_pad_usage_mapping(struct hid_device *hdev,
....@@ -2305,6 +2370,7 @@
23052370 value = field->logical_maximum - value;
23062371 break;
23072372 case HID_DG_INRANGE:
2373
+ mod_timer(&wacom->idleprox_timer, jiffies + msecs_to_jiffies(100));
23082374 wacom_wac->hid_data.inrange_state = value;
23092375 if (!(features->quirks & WACOM_QUIRK_SENSE))
23102376 wacom_wac->hid_data.sense_state = value;
....@@ -4778,9 +4844,16 @@
47784844 static const struct wacom_features wacom_features_0x3c8 =
47794845 { "Wacom Intuos BT M", 21600, 13500, 4095, 63,
47804846 INTUOSHT3_BT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 4 };
4847
+static const struct wacom_features wacom_features_0x3dd =
4848
+ { "Wacom Intuos Pro S", 31920, 19950, 8191, 63,
4849
+ INTUOSP2S_BT, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 7,
4850
+ .touch_max = 10 };
47814851
47824852 static const struct wacom_features wacom_features_HID_ANY_ID =
47834853 { "Wacom HID", .type = HID_GENERIC, .oVid = HID_ANY_ID, .oPid = HID_ANY_ID };
4854
+
4855
+static const struct wacom_features wacom_features_0x94 =
4856
+ { "Wacom Bootloader", .type = BOOTLOADER };
47844857
47854858 #define USB_DEVICE_WACOM(prod) \
47864859 HID_DEVICE(BUS_USB, HID_GROUP_WACOM, USB_VENDOR_ID_WACOM, prod),\
....@@ -4855,6 +4928,7 @@
48554928 { USB_DEVICE_WACOM(0x84) },
48564929 { USB_DEVICE_WACOM(0x90) },
48574930 { USB_DEVICE_WACOM(0x93) },
4931
+ { USB_DEVICE_WACOM(0x94) },
48584932 { USB_DEVICE_WACOM(0x97) },
48594933 { USB_DEVICE_WACOM(0x9A) },
48604934 { USB_DEVICE_WACOM(0x9F) },
....@@ -4953,6 +5027,7 @@
49535027 { BT_DEVICE_WACOM(0x393) },
49545028 { BT_DEVICE_WACOM(0x3c6) },
49555029 { BT_DEVICE_WACOM(0x3c8) },
5030
+ { BT_DEVICE_WACOM(0x3dd) },
49565031 { USB_DEVICE_WACOM(0x4001) },
49575032 { USB_DEVICE_WACOM(0x4004) },
49585033 { USB_DEVICE_WACOM(0x5000) },