Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

HID: hid-input: occasionally report stylus battery even if not changed

There are styluses that only report their battery status when they are
touching the touchscreen; additionally we currently suppress battery
reports if capacity has not changed. To help userspace recognize how long
ago the device reported battery status, let's send the change event through
if either capacity has changed, or at least 30 seconds have passed since
last report we've let through.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>

authored by

dmitry.torokhov@gmail.com and committed by
Jiri Kosina
c6838eee bf36c6b9

+5 -1
+4 -1
drivers/hid/hid-input.c
··· 534 534 capacity = hidinput_scale_battery_capacity(dev, value); 535 535 536 536 if (dev->battery_status != HID_BATTERY_REPORTED || 537 - capacity != dev->battery_capacity) { 537 + capacity != dev->battery_capacity || 538 + ktime_after(ktime_get_coarse(), dev->battery_ratelimit_time)) { 538 539 dev->battery_capacity = capacity; 539 540 dev->battery_status = HID_BATTERY_REPORTED; 541 + dev->battery_ratelimit_time = 542 + ktime_add_ms(ktime_get_coarse(), 30 * 1000); 540 543 power_supply_changed(dev->battery); 541 544 } 542 545 }
+1
include/linux/hid.h
··· 585 585 __s32 battery_report_id; 586 586 enum hid_battery_status battery_status; 587 587 bool battery_avoid_query; 588 + ktime_t battery_ratelimit_time; 588 589 #endif 589 590 590 591 unsigned long status; /* see STAT flags above */