Skip to content

Commit f0f55d7

Browse files
committed
backport: 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]> [[email protected]: Imported into input-wacom (7fc68653fc2e)] Signed-off-by: Jason Gerecke <[email protected]> [[email protected]: Backported form input-wacom (c6c30f5)] Signed-off-by: Jason Gerecke <[email protected]>
1 parent cffc2ec commit f0f55d7

File tree

2 files changed

+6
-18
lines changed

2 files changed

+6
-18
lines changed

3.17/wacom_sys.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2265,13 +2265,6 @@ static int wacom_parse_and_register(struct wacom *wacom, bool wireless)
22652265
if (error)
22662266
goto fail_shared_data;
22672267

2268-
if (!(features->device_type & WACOM_DEVICETYPE_WL_MONITOR) &&
2269-
(features->quirks & WACOM_QUIRK_BATTERY)) {
2270-
error = wacom_initialize_battery(wacom);
2271-
if (error)
2272-
goto fail_battery;
2273-
}
2274-
22752268
error = wacom_register_inputs(wacom);
22762269
if (error)
22772270
goto fail_register_inputs;
@@ -2331,7 +2324,6 @@ static int wacom_parse_and_register(struct wacom *wacom, bool wireless)
23312324
#ifndef WACOM_POWERSUPPLY_41
23322325
wacom_destroy_battery(wacom);
23332326
#endif
2334-
fail_battery:
23352327
fail_shared_data:
23362328
fail_parsed:
23372329
fail_allocate_inputs:
@@ -2417,9 +2409,6 @@ static void wacom_wireless_work(struct work_struct *work)
24172409

24182410
strlcpy(wacom_wac->name, wacom_wac1->name,
24192411
sizeof(wacom_wac->name));
2420-
error = wacom_initialize_battery(wacom);
2421-
if (error)
2422-
goto fail;
24232412
}
24242413

24252414
return;

3.17/wacom_wac.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ static void wacom_notify_battery(struct wacom_wac *wacom_wac,
126126
bool bat_connected, bool ps_connected)
127127
{
128128
struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
129+
bool bat_initialized = WACOM_POWERSUPPLY_DEVICE(wacom->battery.battery);
130+
bool has_quirk = wacom_wac->features.quirks & WACOM_QUIRK_BATTERY;
131+
132+
if (bat_initialized != has_quirk)
133+
wacom_schedule_work(wacom_wac, WACOM_WORKER_BATTERY);
129134

130135
__wacom_notify_battery(&wacom->battery, bat_status, bat_capacity,
131136
bat_charging, bat_connected, ps_connected);
@@ -3389,19 +3394,13 @@ static int wacom_status_irq(struct wacom_wac *wacom_wac, size_t len)
33893394
int battery = (data[8] & 0x3f) * 100 / 31;
33903395
bool charging = !!(data[8] & 0x80);
33913396

3397+
features->quirks |= WACOM_QUIRK_BATTERY;
33923398
wacom_notify_battery(wacom_wac, WACOM_POWER_SUPPLY_STATUS_AUTO,
33933399
battery, charging, battery || charging, 1);
3394-
3395-
if (!WACOM_POWERSUPPLY_DEVICE(wacom->battery.battery) &&
3396-
!(features->quirks & WACOM_QUIRK_BATTERY)) {
3397-
features->quirks |= WACOM_QUIRK_BATTERY;
3398-
wacom_schedule_work(wacom_wac, WACOM_WORKER_BATTERY);
3399-
}
34003400
}
34013401
else if ((features->quirks & WACOM_QUIRK_BATTERY) &&
34023402
WACOM_POWERSUPPLY_DEVICE(wacom->battery.battery)) {
34033403
features->quirks &= ~WACOM_QUIRK_BATTERY;
3404-
wacom_schedule_work(wacom_wac, WACOM_WORKER_BATTERY);
34053404
wacom_notify_battery(wacom_wac, POWER_SUPPLY_STATUS_UNKNOWN, 0, 0, 0, 0);
34063405
}
34073406
return 0;

0 commit comments

Comments
 (0)