From: dmitry.torokhov@gmail.com
To: Jiri Kosina <jikos@kernel.org>, Sebastian Reichel <sre@kernel.org>
Cc: Benjamin Tissoires <benjamin.tissoires@redhat.com>,
Johan Korsnes <jkorsnes@cisco.com>,
linux-input@vger.kernel.org,
Kenneth Albanowski <kenalba@google.com>
Subject: [PATCH] HID: hid-input: occasionally report stylus battery even if not changed
Date: Wed, 30 Sep 2020 15:47:13 -0700 [thread overview]
Message-ID: <20200930224713.GA88246@dtor-ws> (raw)
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>
---
This is a bit of RFC. Another option would be to mark the power supply
as either offline or not present when stylus leaves the surface instead
of saying it is online... Sebastian, any ideas/suggestions?
drivers/hid/hid-input.c | 5 ++++-
include/linux/hid.h | 1 +
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
index 5da631d2ec9b..92b4c9bb6619 100644
--- a/drivers/hid/hid-input.c
+++ b/drivers/hid/hid-input.c
@@ -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);
}
}
diff --git a/include/linux/hid.h b/include/linux/hid.h
index 875f71132b14..c76a18f88262 100644
--- a/include/linux/hid.h
+++ b/include/linux/hid.h
@@ -583,6 +583,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 */
--
2.28.0.709.gb0816b6eb0-goog
--
Dmitry
next reply other threads:[~2020-09-30 22:47 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-30 22:47 dmitry.torokhov [this message]
2020-10-07 22:05 ` [PATCH] HID: hid-input: occasionally report stylus battery even if not changed Kenneth Albanowski
2020-10-27 17:38 ` Dmitry Torokhov
2020-10-29 15:15 ` Jiri Kosina
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200930224713.GA88246@dtor-ws \
--to=dmitry.torokhov@gmail.com \
--cc=benjamin.tissoires@redhat.com \
--cc=jikos@kernel.org \
--cc=jkorsnes@cisco.com \
--cc=kenalba@google.com \
--cc=linux-input@vger.kernel.org \
--cc=sre@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).