Skip to content

Commit

Permalink
HID: hid-input: occasionally report stylus battery even if not changed
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
dmitry.torokhov@gmail.com authored and Jiri Kosina committed Oct 29, 2020
1 parent bf36c6b commit c6838ee
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion drivers/hid/hid-input.c
Original file line number Diff line number Diff line change
Expand Up @@ -534,9 +534,12 @@ static void hidinput_update_battery(struct hid_device *dev, int value)
capacity = hidinput_scale_battery_capacity(dev, value);

if (dev->battery_status != HID_BATTERY_REPORTED ||
capacity != dev->battery_capacity) {
capacity != dev->battery_capacity ||
ktime_after(ktime_get_coarse(), dev->battery_ratelimit_time)) {
dev->battery_capacity = capacity;
dev->battery_status = HID_BATTERY_REPORTED;
dev->battery_ratelimit_time =
ktime_add_ms(ktime_get_coarse(), 30 * 1000);
power_supply_changed(dev->battery);
}
}
Expand Down
1 change: 1 addition & 0 deletions include/linux/hid.h
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ struct hid_device { /* device report descriptor */
__s32 battery_report_id;
enum hid_battery_status battery_status;
bool battery_avoid_query;
ktime_t battery_ratelimit_time;
#endif

unsigned long status; /* see STAT flags above */
Expand Down

0 comments on commit c6838ee

Please sign in to comment.