Skip to content

Commit c6c30f5

Browse files
committed
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]>
1 parent 235fcdb commit c6c30f5

File tree

2 files changed

+6
-17
lines changed

2 files changed

+6
-17
lines changed

4.5/wacom_sys.c

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

2435-
if (!(features->device_type & WACOM_DEVICETYPE_WL_MONITOR) &&
2436-
(features->quirks & WACOM_QUIRK_BATTERY)) {
2437-
error = wacom_initialize_battery(wacom);
2438-
if (error)
2439-
goto fail;
2440-
}
2441-
24422435
error = wacom_register_inputs(wacom);
24432436
if (error)
24442437
goto fail;
@@ -2569,9 +2562,6 @@ static void wacom_wireless_work(struct work_struct *work)
25692562

25702563
strscpy(wacom_wac->name, wacom_wac1->name,
25712564
sizeof(wacom_wac->name));
2572-
error = wacom_initialize_battery(wacom);
2573-
if (error)
2574-
goto fail;
25752565
}
25762566

25772567
return;

4.5/wacom_wac.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ static void wacom_notify_battery(struct wacom_wac *wacom_wac,
123123
bool bat_connected, bool ps_connected)
124124
{
125125
struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
126+
bool bat_initialized = wacom->battery.battery;
127+
bool has_quirk = wacom_wac->features.quirks & WACOM_QUIRK_BATTERY;
128+
129+
if (bat_initialized != has_quirk)
130+
wacom_schedule_work(wacom_wac, WACOM_WORKER_BATTERY);
126131

127132
__wacom_notify_battery(&wacom->battery, bat_status, bat_capacity,
128133
bat_charging, bat_connected, ps_connected);
@@ -3422,19 +3427,13 @@ static int wacom_status_irq(struct wacom_wac *wacom_wac, size_t len)
34223427
int battery = (data[8] & 0x3f) * 100 / 31;
34233428
bool charging = !!(data[8] & 0x80);
34243429

3430+
features->quirks |= WACOM_QUIRK_BATTERY;
34253431
wacom_notify_battery(wacom_wac, WACOM_POWER_SUPPLY_STATUS_AUTO,
34263432
battery, charging, battery || charging, 1);
3427-
3428-
if (!wacom->battery.battery &&
3429-
!(features->quirks & WACOM_QUIRK_BATTERY)) {
3430-
features->quirks |= WACOM_QUIRK_BATTERY;
3431-
wacom_schedule_work(wacom_wac, WACOM_WORKER_BATTERY);
3432-
}
34333433
}
34343434
else if ((features->quirks & WACOM_QUIRK_BATTERY) &&
34353435
wacom->battery.battery) {
34363436
features->quirks &= ~WACOM_QUIRK_BATTERY;
3437-
wacom_schedule_work(wacom_wac, WACOM_WORKER_BATTERY);
34383437
wacom_notify_battery(wacom_wac, POWER_SUPPLY_STATUS_UNKNOWN, 0, 0, 0, 0);
34393438
}
34403439
return 0;

0 commit comments

Comments
 (0)