From 10896b28d096109a703f430868ac330a33c16d7c Mon Sep 17 00:00:00 2001 From: Jiri Slaby Date: May 17 2023 19:15:57 +0000 Subject: HID: wacom: insert timestamp to packed Bluetooth (BT) events (bsc#1012628). --- diff --git a/patches.kernel.org/6.3.3-210-HID-wacom-insert-timestamp-to-packed-Bluetooth-.patch b/patches.kernel.org/6.3.3-210-HID-wacom-insert-timestamp-to-packed-Bluetooth-.patch new file mode 100644 index 0000000..a3a7bf7 --- /dev/null +++ b/patches.kernel.org/6.3.3-210-HID-wacom-insert-timestamp-to-packed-Bluetooth-.patch @@ -0,0 +1,117 @@ +From: Ping Cheng +Date: Fri, 24 Feb 2023 08:26:43 -0800 +Subject: [PATCH] HID: wacom: insert timestamp to packed Bluetooth (BT) events +References: bsc#1012628 +Patch-mainline: 6.3.3 +Git-commit: 17d793f3ed53080dab6bbeabfc82de890c901001 + +commit 17d793f3ed53080dab6bbeabfc82de890c901001 upstream. + +To fully utilize the BT polling/refresh rate, a few input events +are sent together to reduce event delay. This causes issue to the +timestamp generated by input_sync since all the events in the same +packet would pretty much have the same timestamp. This patch inserts +time interval to the events by averaging the total time used for +sending the packet. + +This decision was mainly based on observing the actual time interval +between each BT polling. The interval doesn't seem to be constant, +due to the network and system environment. So, using solutions other +than averaging doesn't end up with valid timestamps. + +Signed-off-by: Ping Cheng +Reviewed-by: Jason Gerecke +Signed-off-by: Jiri Kosina +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Jiri Slaby +--- + drivers/hid/wacom_wac.c | 26 ++++++++++++++++++++++++++ + drivers/hid/wacom_wac.h | 1 + + 2 files changed, 27 insertions(+) + +diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c +index e499b447..0c6a82c6 100644 +--- a/drivers/hid/wacom_wac.c ++++ b/drivers/hid/wacom_wac.c +@@ -1308,6 +1308,9 @@ static void wacom_intuos_pro2_bt_pen(struct wacom_wac *wacom) + + struct input_dev *pen_input = wacom->pen_input; + unsigned char *data = wacom->data; ++ int number_of_valid_frames = 0; ++ int time_interval = 15000000; ++ ktime_t time_packet_received = ktime_get(); + int i; + + if (wacom->features.type == INTUOSP2_BT || +@@ -1328,12 +1331,30 @@ static void wacom_intuos_pro2_bt_pen(struct wacom_wac *wacom) + wacom->id[0] |= (wacom->serial[0] >> 32) & 0xFFFFF; + } + ++ /* number of valid frames */ + for (i = 0; i < pen_frames; i++) { + unsigned char *frame = &data[i*pen_frame_len + 1]; + bool valid = frame[0] & 0x80; ++ ++ if (valid) ++ number_of_valid_frames++; ++ } ++ ++ if (number_of_valid_frames) { ++ if (wacom->hid_data.time_delayed) ++ time_interval = ktime_get() - wacom->hid_data.time_delayed; ++ time_interval /= number_of_valid_frames; ++ wacom->hid_data.time_delayed = time_packet_received; ++ } ++ ++ for (i = 0; i < number_of_valid_frames; i++) { ++ unsigned char *frame = &data[i*pen_frame_len + 1]; ++ bool valid = frame[0] & 0x80; + bool prox = frame[0] & 0x40; + bool range = frame[0] & 0x20; + bool invert = frame[0] & 0x10; ++ int frames_number_reversed = number_of_valid_frames - i - 1; ++ int event_timestamp = time_packet_received - frames_number_reversed * time_interval; + + if (!valid) + continue; +@@ -1346,6 +1367,7 @@ static void wacom_intuos_pro2_bt_pen(struct wacom_wac *wacom) + wacom->tool[0] = 0; + wacom->id[0] = 0; + wacom->serial[0] = 0; ++ wacom->hid_data.time_delayed = 0; + return; + } + +@@ -1382,6 +1404,7 @@ static void wacom_intuos_pro2_bt_pen(struct wacom_wac *wacom) + get_unaligned_le16(&frame[11])); + } + } ++ + if (wacom->tool[0]) { + input_report_abs(pen_input, ABS_PRESSURE, get_unaligned_le16(&frame[5])); + if (wacom->features.type == INTUOSP2_BT || +@@ -1405,6 +1428,9 @@ static void wacom_intuos_pro2_bt_pen(struct wacom_wac *wacom) + + wacom->shared->stylus_in_proximity = prox; + ++ /* add timestamp to unpack the frames */ ++ input_set_timestamp(pen_input, event_timestamp); ++ + input_sync(pen_input); + } + } +diff --git a/drivers/hid/wacom_wac.h b/drivers/hid/wacom_wac.h +index 16f22138..1a40bb8c 100644 +--- a/drivers/hid/wacom_wac.h ++++ b/drivers/hid/wacom_wac.h +@@ -324,6 +324,7 @@ struct hid_data { + int ps_connected; + bool pad_input_event_flag; + unsigned short sequence_number; ++ int time_delayed; + }; + + struct wacom_remote_data { +-- +2.35.3 + diff --git a/series.conf b/series.conf index 832de71..ae7905f 100644 --- a/series.conf +++ b/series.conf @@ -943,6 +943,7 @@ patches.kernel.org/6.3.3-207-drm-amd-pm-avoid-potential-UBSAN-issue-on-legac.patch patches.kernel.org/6.3.3-208-firewire-net-fix-unexpected-release-of-object-f.patch patches.kernel.org/6.3.3-209-HID-wacom-Set-a-default-resolution-for-older-ta.patch + patches.kernel.org/6.3.3-210-HID-wacom-insert-timestamp-to-packed-Bluetooth-.patch ######################################################## # Build fixes that apply to the vanilla kernel too.