]> git.baikalelectronics.ru Git - kernel.git/commitdiff
HID: wacom: generic: Set battery quirk only when we see battery data
authorJason Gerecke <killertofu@gmail.com>
Thu, 13 Apr 2023 18:17:43 +0000 (11:17 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 30 May 2023 11:44:04 +0000 (12:44 +0100)
[ Upstream commit bea407a427baa019758f29f4d31b26f008bb8cc6 ]

Some devices will include battery status usages in the HID descriptor
but we won't see that battery data for one reason or another. For example,
AES sensors won't send battery data unless an AES pen is in proximity.
If a user does not have an AES pen but instead only interacts with the
AES touchscreen with their fingers then there is no need for us to create
a battery object. Similarly, if a family of peripherals shares the same
HID descriptor between wired-only and wireless-capable SKUs, users of the
former may never see a battery event and will not want a power_supply
object created.

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 <jason.gerecke@wacom.com>
Tested-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/hid/wacom_wac.c

index 339bc7f1fcedb7a0e794fd8e317d13fc3b62fb73..819e6d2ca2f3e249ce89779733ab79f02d03d202 100644 (file)
@@ -1927,18 +1927,7 @@ static void wacom_map_usage(struct input_dev *input, struct hid_usage *usage,
 static void wacom_wac_battery_usage_mapping(struct hid_device *hdev,
                struct hid_field *field, struct hid_usage *usage)
 {
-       struct wacom *wacom = hid_get_drvdata(hdev);
-       struct wacom_wac *wacom_wac = &wacom->wacom_wac;
-       struct wacom_features *features = &wacom_wac->features;
-       unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
-
-       switch (equivalent_usage) {
-       case HID_DG_BATTERYSTRENGTH:
-       case WACOM_HID_WD_BATTERY_LEVEL:
-       case WACOM_HID_WD_BATTERY_CHARGING:
-               features->quirks |= WACOM_QUIRK_BATTERY;
-               break;
-       }
+       return;
 }
 
 static void wacom_wac_battery_event(struct hid_device *hdev, struct hid_field *field,
@@ -1959,18 +1948,21 @@ static void wacom_wac_battery_event(struct hid_device *hdev, struct hid_field *f
                        wacom_wac->hid_data.bat_connected = 1;
                        wacom_wac->hid_data.bat_status = WACOM_POWER_SUPPLY_STATUS_AUTO;
                }
+               wacom_wac->features.quirks |= WACOM_QUIRK_BATTERY;
                break;
        case WACOM_HID_WD_BATTERY_LEVEL:
                value = value * 100 / (field->logical_maximum - field->logical_minimum);
                wacom_wac->hid_data.battery_capacity = value;
                wacom_wac->hid_data.bat_connected = 1;
                wacom_wac->hid_data.bat_status = WACOM_POWER_SUPPLY_STATUS_AUTO;
+               wacom_wac->features.quirks |= WACOM_QUIRK_BATTERY;
                break;
        case WACOM_HID_WD_BATTERY_CHARGING:
                wacom_wac->hid_data.bat_charging = value;
                wacom_wac->hid_data.ps_connected = value;
                wacom_wac->hid_data.bat_connected = 1;
                wacom_wac->hid_data.bat_status = WACOM_POWER_SUPPLY_STATUS_AUTO;
+               wacom_wac->features.quirks |= WACOM_QUIRK_BATTERY;
                break;
        }
 }
@@ -1986,18 +1978,15 @@ static void wacom_wac_battery_report(struct hid_device *hdev,
 {
        struct wacom *wacom = hid_get_drvdata(hdev);
        struct wacom_wac *wacom_wac = &wacom->wacom_wac;
-       struct wacom_features *features = &wacom_wac->features;
 
-       if (features->quirks & WACOM_QUIRK_BATTERY) {
-               int status = wacom_wac->hid_data.bat_status;
-               int capacity = wacom_wac->hid_data.battery_capacity;
-               bool charging = wacom_wac->hid_data.bat_charging;
-               bool connected = wacom_wac->hid_data.bat_connected;
-               bool powered = wacom_wac->hid_data.ps_connected;
+       int status = wacom_wac->hid_data.bat_status;
+       int capacity = wacom_wac->hid_data.battery_capacity;
+       bool charging = wacom_wac->hid_data.bat_charging;
+       bool connected = wacom_wac->hid_data.bat_connected;
+       bool powered = wacom_wac->hid_data.ps_connected;
 
-               wacom_notify_battery(wacom_wac, status, capacity, charging,
-                                    connected, powered);
-       }
+       wacom_notify_battery(wacom_wac, status, capacity, charging,
+                            connected, powered);
 }
 
 static void wacom_wac_pad_usage_mapping(struct hid_device *hdev,