Skip to content

Commit fd2a9b2

Browse files
flying-elephantBenjamin Tissoires
authored andcommitted
HID: wacom: Remove AES power_supply after extended inactivity
Even if a user does not use their AES pen for an extended period, the battery power supply attributes continue to exist. This results in the desktop showing battery status for a pen that is no longer in use and which may in fact be in a different state (e.g. the user may be charging the pen). To avoid confusion and ensure userspace has an accurate view of the battery state, this patch automatically removes the power_supply after 30 minutes of inactivity. Signed-off-by: Tatsunosuke Tobita <[email protected]> Reviewed-by: Jason Gerecke <[email protected]> Reviewed-by: Aaron Skomra <[email protected]> Reviewed-by: Josh Dickens <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Benjamin Tissoires <[email protected]>
1 parent 1f34279 commit fd2a9b2

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

drivers/hid/wacom.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ struct wacom {
164164
struct work_struct battery_work;
165165
struct work_struct remote_work;
166166
struct delayed_work init_work;
167+
struct delayed_work aes_battery_work;
167168
struct wacom_remote *remote;
168169
struct work_struct mode_change_work;
169170
struct timer_list idleprox_timer;

drivers/hid/wacom_sys.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,6 +1813,13 @@ static void wacom_destroy_battery(struct wacom *wacom)
18131813
}
18141814
}
18151815

1816+
static void wacom_aes_battery_handler(struct work_struct *work)
1817+
{
1818+
struct wacom *wacom = container_of(work, struct wacom, aes_battery_work.work);
1819+
1820+
wacom_destroy_battery(wacom);
1821+
}
1822+
18161823
static ssize_t wacom_show_speed(struct device *dev,
18171824
struct device_attribute
18181825
*attr, char *buf)
@@ -2794,6 +2801,7 @@ static int wacom_probe(struct hid_device *hdev,
27942801

27952802
mutex_init(&wacom->lock);
27962803
INIT_DELAYED_WORK(&wacom->init_work, wacom_init_work);
2804+
INIT_DELAYED_WORK(&wacom->aes_battery_work, wacom_aes_battery_handler);
27972805
INIT_WORK(&wacom->wireless_work, wacom_wireless_work);
27982806
INIT_WORK(&wacom->battery_work, wacom_battery_work);
27992807
INIT_WORK(&wacom->remote_work, wacom_remote_work);

drivers/hid/wacom_wac.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2528,11 +2528,12 @@ static void wacom_wac_pen_report(struct hid_device *hdev,
25282528
struct input_dev *input = wacom_wac->pen_input;
25292529
bool range = wacom_wac->hid_data.inrange_state;
25302530
bool sense = wacom_wac->hid_data.sense_state;
2531+
bool entering_range = !wacom_wac->tool[0] && range;
25312532

25322533
if (wacom_wac->is_invalid_bt_frame)
25332534
return;
25342535

2535-
if (!wacom_wac->tool[0] && range) { /* first in range */
2536+
if (entering_range) { /* first in range */
25362537
/* Going into range select tool */
25372538
if (wacom_wac->hid_data.invert_state)
25382539
wacom_wac->tool[0] = BTN_TOOL_RUBBER;
@@ -2583,6 +2584,15 @@ static void wacom_wac_pen_report(struct hid_device *hdev,
25832584
input_sync(input);
25842585
}
25852586

2587+
/* Handle AES battery timeout behavior */
2588+
if (wacom_wac->features.quirks & WACOM_QUIRK_AESPEN) {
2589+
if (entering_range)
2590+
cancel_delayed_work(&wacom->aes_battery_work);
2591+
if (!sense)
2592+
schedule_delayed_work(&wacom->aes_battery_work,
2593+
msecs_to_jiffies(WACOM_AES_BATTERY_TIMEOUT));
2594+
}
2595+
25862596
if (!sense) {
25872597
wacom_wac->tool[0] = 0;
25882598
wacom_wac->id[0] = 0;

drivers/hid/wacom_wac.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define WACOM_MAX_REMOTES 5
1515
#define WACOM_STATUS_UNKNOWN 255
1616
#define WACOM_REMOTE_BATTERY_TIMEOUT 21000000000ll
17+
#define WACOM_AES_BATTERY_TIMEOUT 1800000
1718

1819
/* packet length for individual models */
1920
#define WACOM_PKGLEN_BBFUN 9

0 commit comments

Comments
 (0)