Skip to contentSkip to conversation

HID: input: do not report stylus battery state as "full"

PATCH In review Dmitry Torokhov 4 participants 5 messages Jun 29, 2021 – Jul 15, 2021 HID

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 HID: input: do not report stylus battery state as "full"

The power supply states of discharging, charging, full, etc, represent state of charging, not the capacity level of the battery (for which we have a separate property). Current HID usage tables to not allow for expressing charging state of the batteries found in generic styli, so we should simply assume that the battery is discharging even if current capacity is at 100% when battery strength reporting is done via HID interface. In fact, we were doing just that before commit 581c4484769e.

This change helps UIs to not mis-represent fully charged batteries in styli as being charging/topping-off.

Fixes 581c4484769e ("HID: input: map digitizer battery usage")
---
 drivers/hid/hid-input.c | 2 --
 1 file changed, 2 deletions(-)
drivers/hid/hid-input.c +0 -2
index e982d8173c9c..e85a1a34ff39 100644
@@ -417,8 +417,6 @@ static int hidinput_get_battery_property(struct power_supply *psy,
 
 		if (dev->battery_status == HID_BATTERY_UNKNOWN)
 			val->intval = POWER_SUPPLY_STATUS_UNKNOWN;
-		else if (dev->battery_capacity == 100)
-			val->intval = POWER_SUPPLY_STATUS_FULL;
 		else
 			val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
 		break;
Signature · 4 lines
2.32.0.93.g670b81a890-goog

-- 
Dmitry
#1 lore raw

I've tested it on a 5.4 derivative, and that works as expected. Looks good to me.

- Kenneth Albanowski

- Kenneth

Quoted 38 lines · Dmitry Torokhov

The power supply states of discharging, charging, full, etc, represent state of charging, not the capacity level of the battery (for which we have a separate property). Current HID usage tables to not allow for expressing charging state of the batteries found in generic styli, so we should simply assume that the battery is discharging even if current capacity is at 100% when battery strength reporting is done via HID interface. In fact, we were doing just that before commit 581c4484769e.

This change helps UIs to not mis-represent fully charged batteries in styli as being charging/topping-off.

Fixes 581c4484769e ("HID: input: map digitizer battery usage")
---
 drivers/hid/hid-input.c | 2 --
 1 file changed, 2 deletions(-)
drivers/hid/hid-input.c +0 -3
index e982d8173c9c..e85a1a34ff39 100644
@@ -417,8 +417,6 @@ static int hidinput_get_battery_property(struct power_supply *psy,
 
                if (dev->battery_status == HID_BATTERY_UNKNOWN)
                        val->intval = POWER_SUPPLY_STATUS_UNKNOWN;
-               else if (dev->battery_capacity == 100)
-                       val->intval = POWER_SUPPLY_STATUS_FULL;
                else
                        val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
                break;
--

2.32.0.93.g670b81a890-goog

--
Dmitry

#2 lore raw
In reply to Dmitry Torokhov

Hi Dmitry,

Quoted 9 lines · Dmitry Torokhov

The power supply states of discharging, charging, full, etc, represent state of charging, not the capacity level of the battery (for which we have a separate property). Current HID usage tables to not allow for expressing charging state of the batteries found in generic styli, so we should simply assume that the battery is discharging even if current capacity is at 100% when battery strength reporting is done via HID interface. In fact, we were doing just that before commit 581c4484769e.

This commit is 4 year old already, so I'd like to have the opinion of Bastien on the matter for the upower side (or at least notify him).

Quoted 16 lines

This change helps UIs to not mis-represent fully charged batteries in styli as being charging/topping-off.

Fixes 581c4484769e ("HID: input: map digitizer battery usage")
---
 drivers/hid/hid-input.c | 2 --
 1 file changed, 2 deletions(-)
drivers/hid/hid-input.c +0 -0
index e982d8173c9c..e85a1a34ff39 100644

drivers/hid/hid-input.c static int hidinput_get_battery_property(struct power_supply *psy, · line 419

Quoted 3 lines
drivers/hid/hid-input.c +0 -0
@@ -417,8 +417,6 @@ static int hidinput_get_battery_property(struct power_supply *psy,
 
                if (dev->battery_status == HID_BATTERY_UNKNOWN)
                        val->intval = POWER_SUPPLY_STATUS_UNKNOWN;

What's the point of keeping the HID_BATTERY_UNKNOWN code path? AFAICT, before 581c4484769e, we were just returning POWER_SUPPLY_STATUS_DISCHARGING. If we don't need to check for the capacity, I think we could also drop the hunk just before where we do the query of the capacity.

Cheers,
Benjamin

Quoted 11 lines
drivers/hid/hid-input.c +0 -3
-               else if (dev->battery_capacity == 100)
-                       val->intval = POWER_SUPPLY_STATUS_FULL;
                else
                        val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
                break;
--

2.32.0.93.g670b81a890-goog

--
Dmitry

#3 lore raw

Hi Benjamin,

Quoted 34 lines · Benjamin Tissoires

Hi Dmitry,

Quoted 9 lines · Dmitry Torokhov

The power supply states of discharging, charging, full, etc, represent state of charging, not the capacity level of the battery (for which we have a separate property). Current HID usage tables to not allow for expressing charging state of the batteries found in generic styli, so we should simply assume that the battery is discharging even if current capacity is at 100% when battery strength reporting is done via HID interface. In fact, we were doing just that before commit 581c4484769e.

This commit is 4 year old already, so I'd like to have the opinion of Bastien on the matter for the upower side (or at least notify him).

Quoted 17 lines

This change helps UIs to not mis-represent fully charged batteries in styli as being charging/topping-off.

Fixes 581c4484769e ("HID: input: map digitizer battery usage")
---
 drivers/hid/hid-input.c | 2 --
 1 file changed, 2 deletions(-)
drivers/hid/hid-input.c +0 -0
index e982d8173c9c..e85a1a34ff39 100644
@@ -417,8 +417,6 @@ static int hidinput_get_battery_property(struct power_supply *psy,
 
Quoted 8 lines

drivers/hid/hid-input.c static int hidinput_get_battery_property(struct power_supply *psy, · line 419

Quoted 2 lines
drivers/hid/hid-input.c +0 -0
                if (dev->battery_status == HID_BATTERY_UNKNOWN)
                        val->intval = POWER_SUPPLY_STATUS_UNKNOWN;

What's the point of keeping the HID_BATTERY_UNKNOWN code path? AFAICT, before 581c4484769e, we were just returning POWER_SUPPLY_STATUS_DISCHARGING. If we don't need to check for the capacity, I think we could also drop the hunk just before where we do the query of the capacity.

I believe it is beneficial to keep this check: prior to 581c4484769e we were only handling batteries reported via generic device control - HID_DC_BATTERYSTRENGTH - essentially UPS batteries that normally can be queried at will. Stylus batteries are typically only reported when stylus is in contact with the digitzer, so until user actually engages stylus we do not have idea about its level/capacity. For this reason I think we should keep reporting POWER_SUPPLY_STATUS_UNKNOWN.

Thanks.

Signature · 1 line
Dmitry
maintainer
#4 lore raw
In reply to Dmitry Torokhov
Quoted 9 lines · Dmitry Torokhov

The power supply states of discharging, charging, full, etc, represent state of charging, not the capacity level of the battery (for which we have a separate property). Current HID usage tables to not allow for expressing charging state of the batteries found in generic styli, so we should simply assume that the battery is discharging even if current capacity is at 100% when battery strength reporting is done via HID interface. In fact, we were doing just that before commit 581c4484769e.

Quoted 6 lines

This change helps UIs to not mis-represent fully charged batteries in styli as being charging/topping-off.

Fixes 581c4484769e ("HID: input: map digitizer battery usage")

As there was no pushback from Bastien, I am queuing this for 5.15. Thanks,

Signature · 2 lines
Jiri Kosina
SUSE Labs