* HID: wacom: insert timestamp to packed Bluetooth (BT) events
@ 2023-05-11 20:23 Ping Cheng
2023-05-13 7:51 ` Greg KH
0 siblings, 1 reply; 2+ messages in thread
From: Ping Cheng @ 2023-05-11 20:23 UTC (permalink / raw)
To: stable # v4 . 10
[-- Attachment #1: Type: text/plain, Size: 290 bytes --]
Hi Stable maintainers,
This patch, ID 17d793f3ed53, inserts timestamps to Wacom bluetooth
device events. The upstream patch applies to kernels 6.1 and later as
is.
The attached patch applies to kernel 5.4 to 5.15 stable versions. Let
me know if you have other questions.
Thank you,
Ping
[-- Attachment #2: 0001-HID-wacom-insert-timestamp-to-packed-Bluetooth-BT-ev.patch --]
[-- Type: text/x-patch, Size: 3756 bytes --]
From 45ca620f5fec1fbe7daf4e1f9d36e30aa5e15fbb Mon Sep 17 00:00:00 2001
From: Ping Cheng <ping.cheng@wacom.com>
Date: Wed, 10 May 2023 17:31:09 -0700
Subject: [PATCH for longterm 5.4-5.15] HID: wacom: insert timestamp to packed Bluetooth (BT) events
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 <ping.cheng@wacom.com>
Reviewed-by: Jason Gerecke <jason.gerecke@wacom.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
---
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 aa477a43a312..ec0ceb9babc7 100644
--- a/drivers/hid/wacom_wac.c
+++ b/drivers/hid/wacom_wac.c
@@ -1265,6 +1265,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 ||
@@ -1285,12 +1288,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;
@@ -1303,6 +1324,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;
}
@@ -1339,6 +1361,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 ||
@@ -1362,6 +1385,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 ca172efcf072..88badfbae999 100644
--- a/drivers/hid/wacom_wac.h
+++ b/drivers/hid/wacom_wac.h
@@ -320,6 +320,7 @@ struct hid_data {
int bat_connected;
int ps_connected;
bool pad_input_event_flag;
+ int time_delayed;
};
struct wacom_remote_data {
--
2.40.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: HID: wacom: insert timestamp to packed Bluetooth (BT) events
2023-05-11 20:23 HID: wacom: insert timestamp to packed Bluetooth (BT) events Ping Cheng
@ 2023-05-13 7:51 ` Greg KH
0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2023-05-13 7:51 UTC (permalink / raw)
To: Ping Cheng; +Cc: stable # v4 . 10
On Thu, May 11, 2023 at 01:23:14PM -0700, Ping Cheng wrote:
> Hi Stable maintainers,
>
> This patch, ID 17d793f3ed53, inserts timestamps to Wacom bluetooth
> device events. The upstream patch applies to kernels 6.1 and later as
> is.
>
> The attached patch applies to kernel 5.4 to 5.15 stable versions. Let
> me know if you have other questions.
All now queued up, thanks.
greg k-h
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-05-13 8:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-11 20:23 HID: wacom: insert timestamp to packed Bluetooth (BT) events Ping Cheng
2023-05-13 7:51 ` Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox