Skip to content

Commit 7fc6865

Browse files
jigpuJiri Kosina
authored andcommitted
HID: wacom: Lazy-init batteries
Rather than creating batteries as part of the initial device probe, let's make the process lazy. This gives us the opportunity to prevent batteries from being created in situations where they are unnecessary. There are two cases in particular where batteries are being unnecessarily created at initialization. These are AES sensors (for which we don't know any battery status information until a battery-powered pen actually comes into prox) peripheral tablets which share HID descriptors between the wired-only and wireless-capable SKUs of a family of devices. This patch will delay battery initialization of the former until a pen actually comes into prox. It will delay battery initialization of the latter until either a pen comes into prox or a "heartbeat" packet is processed. Link: https://bugzilla.kernel.org/show_bug.cgi?id=217062 Link: https://gitlab.gnome.org/GNOME/gnome-control-center/-/issues/2354 Signed-off-by: Jason Gerecke <[email protected]> Tested-by: Mario Limonciello <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 08a46b4 commit 7fc6865

File tree

2 files changed

+6
-17
lines changed

2 files changed

+6
-17
lines changed

drivers/hid/wacom_sys.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2372,13 +2372,6 @@ static int wacom_parse_and_register(struct wacom *wacom, bool wireless)
23722372
if (error)
23732373
goto fail;
23742374

2375-
if (!(features->device_type & WACOM_DEVICETYPE_WL_MONITOR) &&
2376-
(features->quirks & WACOM_QUIRK_BATTERY)) {
2377-
error = wacom_initialize_battery(wacom);
2378-
if (error)
2379-
goto fail;
2380-
}
2381-
23822375
error = wacom_register_inputs(wacom);
23832376
if (error)
23842377
goto fail;
@@ -2509,9 +2502,6 @@ static void wacom_wireless_work(struct work_struct *work)
25092502

25102503
strscpy(wacom_wac->name, wacom_wac1->name,
25112504
sizeof(wacom_wac->name));
2512-
error = wacom_initialize_battery(wacom);
2513-
if (error)
2514-
goto fail;
25152505
}
25162506

25172507
return;

drivers/hid/wacom_wac.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ static void wacom_notify_battery(struct wacom_wac *wacom_wac,
113113
bool bat_connected, bool ps_connected)
114114
{
115115
struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
116+
bool bat_initialized = wacom->battery.battery;
117+
bool has_quirk = wacom_wac->features.quirks & WACOM_QUIRK_BATTERY;
118+
119+
if (bat_initialized != has_quirk)
120+
wacom_schedule_work(wacom_wac, WACOM_WORKER_BATTERY);
116121

117122
__wacom_notify_battery(&wacom->battery, bat_status, bat_capacity,
118123
bat_charging, bat_connected, ps_connected);
@@ -3399,19 +3404,13 @@ static int wacom_status_irq(struct wacom_wac *wacom_wac, size_t len)
33993404
int battery = (data[8] & 0x3f) * 100 / 31;
34003405
bool charging = !!(data[8] & 0x80);
34013406

3407+
features->quirks |= WACOM_QUIRK_BATTERY;
34023408
wacom_notify_battery(wacom_wac, WACOM_POWER_SUPPLY_STATUS_AUTO,
34033409
battery, charging, battery || charging, 1);
3404-
3405-
if (!wacom->battery.battery &&
3406-
!(features->quirks & WACOM_QUIRK_BATTERY)) {
3407-
features->quirks |= WACOM_QUIRK_BATTERY;
3408-
wacom_schedule_work(wacom_wac, WACOM_WORKER_BATTERY);
3409-
}
34103410
}
34113411
else if ((features->quirks & WACOM_QUIRK_BATTERY) &&
34123412
wacom->battery.battery) {
34133413
features->quirks &= ~WACOM_QUIRK_BATTERY;
3414-
wacom_schedule_work(wacom_wac, WACOM_WORKER_BATTERY);
34153414
wacom_notify_battery(wacom_wac, POWER_SUPPLY_STATUS_UNKNOWN, 0, 0, 0, 0);
34163415
}
34173416
return 0;

0 commit comments

Comments
 (0)