]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
HID: wacom: remove the battery when the EKR is off
authorAaron Armstrong Skomra <aaron.skomra@wacom.com>
Tue, 25 Jul 2023 22:20:25 +0000 (15:20 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 23 Sep 2023 08:46:52 +0000 (10:46 +0200)
commit 9ac6678b95b0dd9458a7a6869f46e51cd55a1d84 upstream.

Currently the EKR battery remains even after we stop getting information
from the device. This can lead to a stale battery persisting indefinitely
in userspace.

The remote sends a heartbeat every 10 seconds. Delete the battery if we
miss two heartbeats (after 21 seconds). Restore the battery once we see
a heartbeat again.

Signed-off-by: Aaron Skomra <skomra@gmail.com>
Signed-off-by: Aaron Armstrong Skomra <aaron.skomra@wacom.com>
Reviewed-by: Jason Gerecke <jason.gerecke@wacom.com>
Fixes: 9f1015d45f62 ("HID: wacom: EKR: attach the power_supply on first connection")
CC: stable@vger.kernel.org
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/hid/wacom.h
drivers/hid/wacom_sys.c
drivers/hid/wacom_wac.c
drivers/hid/wacom_wac.h

index 9c0900c35b236b71b9b89ab5d33a922f2f15c7b9..3dc4a819b175826c3fd928f9e735519a3bea44ad 100644 (file)
@@ -155,6 +155,7 @@ struct wacom_remote {
                struct input_dev *input;
                bool registered;
                struct wacom_battery battery;
+               ktime_t active_time;
        } remotes[WACOM_MAX_REMOTES];
 };
 
index 28e7a4950b74a6622dff91e3591700f370969078..3ca50505c78c3debb72577c22f403d9141b782a8 100644 (file)
@@ -2361,6 +2361,18 @@ fail:
        return;
 }
 
+static void wacom_remote_destroy_battery(struct wacom *wacom, int index)
+{
+       struct wacom_remote *remote = wacom->remote;
+
+       if (remote->remotes[index].battery.battery) {
+               devres_release_group(&wacom->hdev->dev,
+                                    &remote->remotes[index].battery.bat_desc);
+               remote->remotes[index].battery.battery = NULL;
+               remote->remotes[index].active_time = 0;
+       }
+}
+
 static void wacom_remote_destroy_one(struct wacom *wacom, unsigned int index)
 {
        struct wacom_remote *remote = wacom->remote;
@@ -2375,9 +2387,7 @@ static void wacom_remote_destroy_one(struct wacom *wacom, unsigned int index)
                        remote->remotes[i].registered = false;
                        spin_unlock_irqrestore(&remote->remote_lock, flags);
 
-                       if (remote->remotes[i].battery.battery)
-                               devres_release_group(&wacom->hdev->dev,
-                                                    &remote->remotes[i].battery.bat_desc);
+                       wacom_remote_destroy_battery(wacom, i);
 
                        if (remote->remotes[i].group.name)
                                devres_release_group(&wacom->hdev->dev,
@@ -2385,7 +2395,6 @@ static void wacom_remote_destroy_one(struct wacom *wacom, unsigned int index)
 
                        remote->remotes[i].serial = 0;
                        remote->remotes[i].group.name = NULL;
-                       remote->remotes[i].battery.battery = NULL;
                        wacom->led.groups[i].select = WACOM_STATUS_UNKNOWN;
                }
        }
@@ -2470,6 +2479,9 @@ static int wacom_remote_attach_battery(struct wacom *wacom, int index)
        if (remote->remotes[index].battery.battery)
                return 0;
 
+       if (!remote->remotes[index].active_time)
+               return 0;
+
        if (wacom->led.groups[index].select == WACOM_STATUS_UNKNOWN)
                return 0;
 
@@ -2485,6 +2497,7 @@ static void wacom_remote_work(struct work_struct *work)
 {
        struct wacom *wacom = container_of(work, struct wacom, remote_work);
        struct wacom_remote *remote = wacom->remote;
+       ktime_t kt = ktime_get();
        struct wacom_remote_data data;
        unsigned long flags;
        unsigned int count;
@@ -2511,6 +2524,10 @@ static void wacom_remote_work(struct work_struct *work)
                serial = data.remote[i].serial;
                if (data.remote[i].connected) {
 
+                       if (kt - remote->remotes[i].active_time > WACOM_REMOTE_BATTERY_TIMEOUT
+                           && remote->remotes[i].active_time != 0)
+                               wacom_remote_destroy_battery(wacom, i);
+
                        if (remote->remotes[i].serial == serial) {
                                wacom_remote_attach_battery(wacom, i);
                                continue;
index be30fdbc37c515af9c2e140646017290dbe83890..19a798eb395c54b8cd21f9249bf0c322e0deca15 100644 (file)
@@ -1039,6 +1039,7 @@ static int wacom_remote_irq(struct wacom_wac *wacom_wac, size_t len)
        if (index < 0 || !remote->remotes[index].registered)
                goto out;
 
+       remote->remotes[i].active_time = ktime_get();
        input = remote->remotes[index].input;
 
        input_report_key(input, BTN_0, (data[9] & 0x01));
index a5c61096fa457d38e7730be46c1a4d2de478ba9d..899c6c7bfea444657bc2a712f3d820eadc96e911 100644 (file)
@@ -18,6 +18,7 @@
 #define WACOM_NAME_MAX         64
 #define WACOM_MAX_REMOTES      5
 #define WACOM_STATUS_UNKNOWN   255
+#define WACOM_REMOTE_BATTERY_TIMEOUT   21000000000ll
 
 /* packet length for individual models */
 #define WACOM_PKGLEN_BBFUN      9