hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/drivers/hid/wacom_sys.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * drivers/input/tablet/wacom_sys.c
34 *
....@@ -5,10 +6,6 @@
56 */
67
78 /*
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License as published by
10
- * the Free Software Foundation; either version 2 of the License, or
11
- * (at your option) any later version.
129 */
1310
1411 #include "wacom_wac.h"
....@@ -163,6 +160,9 @@
163160 {
164161 struct wacom *wacom = hid_get_drvdata(hdev);
165162
163
+ if (wacom->wacom_wac.features.type == BOOTLOADER)
164
+ return 0;
165
+
166166 if (size > WACOM_PKGLEN_MAX)
167167 return 1;
168168
....@@ -250,6 +250,38 @@
250250 field->usage[i-1].hid == HID_DG_INVERT &&
251251 field->usage[i+1].hid == HID_DG_INRANGE) {
252252 usage->hid = HID_DG_BARRELSWITCH2;
253
+ }
254
+ }
255
+
256
+ /*
257
+ * Wacom's AES devices use different vendor-defined usages to
258
+ * report serial number information compared to their branded
259
+ * hardware. The usages are also sometimes ill-defined and do
260
+ * not have the correct logical min/max values set. Lets patch
261
+ * the descriptor to use the branded usage convention and fix
262
+ * the errors.
263
+ */
264
+ if (usage->hid == WACOM_HID_WT_SERIALNUMBER &&
265
+ field->report_size == 16 &&
266
+ field->index + 2 < field->report->maxfield) {
267
+ struct hid_field *a = field->report->field[field->index + 1];
268
+ struct hid_field *b = field->report->field[field->index + 2];
269
+
270
+ if (a->maxusage > 0 &&
271
+ a->usage[0].hid == HID_DG_TOOLSERIALNUMBER &&
272
+ a->report_size == 32 &&
273
+ b->maxusage > 0 &&
274
+ b->usage[0].hid == 0xFF000000 &&
275
+ b->report_size == 8) {
276
+ features->quirks |= WACOM_QUIRK_AESPEN;
277
+ usage->hid = WACOM_HID_WD_TOOLTYPE;
278
+ field->logical_minimum = S16_MIN;
279
+ field->logical_maximum = S16_MAX;
280
+ a->logical_minimum = S32_MIN;
281
+ a->logical_maximum = S32_MAX;
282
+ b->usage[0].hid = WACOM_HID_WD_SERIALHI;
283
+ b->logical_minimum = 0;
284
+ b->logical_maximum = U8_MAX;
253285 }
254286 }
255287
....@@ -2095,7 +2127,7 @@
20952127
20962128 error = wacom_setup_pad_input_capabilities(pad_input_dev, wacom_wac);
20972129 if (error) {
2098
- /* no pad in use on this interface */
2130
+ /* no pad events using this interface */
20992131 input_free_device(pad_input_dev);
21002132 wacom_wac->pad_input = NULL;
21012133 pad_input_dev = NULL;
....@@ -2387,8 +2419,13 @@
23872419 goto fail_quirks;
23882420 }
23892421
2390
- if (features->device_type & WACOM_DEVICETYPE_WL_MONITOR)
2422
+ if (features->device_type & WACOM_DEVICETYPE_WL_MONITOR) {
23912423 error = hid_hw_open(hdev);
2424
+ if (error) {
2425
+ hid_err(hdev, "hw open failed\n");
2426
+ goto fail_quirks;
2427
+ }
2428
+ }
23922429
23932430 wacom_set_shared_values(wacom_wac);
23942431 devres_close_group(&hdev->dev, wacom);
....@@ -2492,6 +2529,18 @@
24922529 return;
24932530 }
24942531
2532
+static void wacom_remote_destroy_battery(struct wacom *wacom, int index)
2533
+{
2534
+ struct wacom_remote *remote = wacom->remote;
2535
+
2536
+ if (remote->remotes[index].battery.battery) {
2537
+ devres_release_group(&wacom->hdev->dev,
2538
+ &remote->remotes[index].battery.bat_desc);
2539
+ remote->remotes[index].battery.battery = NULL;
2540
+ remote->remotes[index].active_time = 0;
2541
+ }
2542
+}
2543
+
24952544 static void wacom_remote_destroy_one(struct wacom *wacom, unsigned int index)
24962545 {
24972546 struct wacom_remote *remote = wacom->remote;
....@@ -2506,9 +2555,7 @@
25062555 remote->remotes[i].registered = false;
25072556 spin_unlock_irqrestore(&remote->remote_lock, flags);
25082557
2509
- if (remote->remotes[i].battery.battery)
2510
- devres_release_group(&wacom->hdev->dev,
2511
- &remote->remotes[i].battery.bat_desc);
2558
+ wacom_remote_destroy_battery(wacom, i);
25122559
25132560 if (remote->remotes[i].group.name)
25142561 devres_release_group(&wacom->hdev->dev,
....@@ -2516,7 +2563,6 @@
25162563
25172564 remote->remotes[i].serial = 0;
25182565 remote->remotes[i].group.name = NULL;
2519
- remote->remotes[i].battery.battery = NULL;
25202566 wacom->led.groups[i].select = WACOM_STATUS_UNKNOWN;
25212567 }
25222568 }
....@@ -2601,6 +2647,9 @@
26012647 if (remote->remotes[index].battery.battery)
26022648 return 0;
26032649
2650
+ if (!remote->remotes[index].active_time)
2651
+ return 0;
2652
+
26042653 if (wacom->led.groups[index].select == WACOM_STATUS_UNKNOWN)
26052654 return 0;
26062655
....@@ -2616,6 +2665,7 @@
26162665 {
26172666 struct wacom *wacom = container_of(work, struct wacom, remote_work);
26182667 struct wacom_remote *remote = wacom->remote;
2668
+ ktime_t kt = ktime_get();
26192669 struct wacom_remote_data data;
26202670 unsigned long flags;
26212671 unsigned int count;
....@@ -2641,6 +2691,10 @@
26412691 for (i = 0; i < WACOM_MAX_REMOTES; i++) {
26422692 serial = data.remote[i].serial;
26432693 if (data.remote[i].connected) {
2694
+
2695
+ if (kt - remote->remotes[i].active_time > WACOM_REMOTE_BATTERY_TIMEOUT
2696
+ && remote->remotes[i].active_time != 0)
2697
+ wacom_remote_destroy_battery(wacom, i);
26442698
26452699 if (remote->remotes[i].serial == serial) {
26462700 wacom_remote_attach_battery(wacom, i);
....@@ -2725,14 +2779,12 @@
27252779 wacom_wac->features = *((struct wacom_features *)id->driver_data);
27262780 features = &wacom_wac->features;
27272781
2728
- if (features->check_for_hid_type && features->hid_type != hdev->type) {
2729
- error = -ENODEV;
2730
- goto fail;
2731
- }
2782
+ if (features->check_for_hid_type && features->hid_type != hdev->type)
2783
+ return -ENODEV;
27322784
27332785 error = wacom_devm_kfifo_alloc(wacom);
27342786 if (error)
2735
- goto fail;
2787
+ return error;
27362788
27372789 wacom_wac->hid_data.inputmode = -1;
27382790 wacom_wac->mode_report = -1;
....@@ -2751,17 +2803,23 @@
27512803 INIT_WORK(&wacom->battery_work, wacom_battery_work);
27522804 INIT_WORK(&wacom->remote_work, wacom_remote_work);
27532805 INIT_WORK(&wacom->mode_change_work, wacom_mode_change_work);
2806
+ timer_setup(&wacom->idleprox_timer, &wacom_idleprox_timeout, TIMER_DEFERRABLE);
27542807
27552808 /* ask for the report descriptor to be loaded by HID */
27562809 error = hid_parse(hdev);
27572810 if (error) {
27582811 hid_err(hdev, "parse failed\n");
2759
- goto fail;
2812
+ return error;
2813
+ }
2814
+
2815
+ if (features->type == BOOTLOADER) {
2816
+ hid_warn(hdev, "Using device in hidraw-only mode");
2817
+ return hid_hw_start(hdev, HID_CONNECT_HIDRAW);
27602818 }
27612819
27622820 error = wacom_parse_and_register(wacom, false);
27632821 if (error)
2764
- goto fail;
2822
+ return error;
27652823
27662824 if (hdev->bus == BUS_BLUETOOTH) {
27672825 error = device_create_file(&hdev->dev, &dev_attr_speed);
....@@ -2772,10 +2830,6 @@
27722830 }
27732831
27742832 return 0;
2775
-
2776
-fail:
2777
- hid_set_drvdata(hdev, NULL);
2778
- return error;
27792833 }
27802834
27812835 static void wacom_remove(struct hid_device *hdev)
....@@ -2794,6 +2848,7 @@
27942848 cancel_work_sync(&wacom->battery_work);
27952849 cancel_work_sync(&wacom->remote_work);
27962850 cancel_work_sync(&wacom->mode_change_work);
2851
+ del_timer_sync(&wacom->idleprox_timer);
27972852 if (hdev->bus == BUS_BLUETOOTH)
27982853 device_remove_file(&hdev->dev, &dev_attr_speed);
27992854
....@@ -2802,8 +2857,6 @@
28022857
28032858 if (wacom->wacom_wac.features.type != REMOTE)
28042859 wacom_release_resources(wacom);
2805
-
2806
- hid_set_drvdata(hdev, NULL);
28072860 }
28082861
28092862 #ifdef CONFIG_PM