[PATCH v3 14/14] HID: logitech-hidpp: expose charge_type property for battery voltage feature
From: Dmitry Torokhov
Date: Fri Nov 20 2026 - 03:42:43 EST
Commit be281368f297 ("hid-logitech-hidpp: read battery voltage from
newer devices") added support for the 0x1001 battery voltage feature,
populated battery->charge_type, and handled POWER_SUPPLY_PROP_CHARGE_TYPE
in hidpp_battery_get_property(). However, it did not add a placeholder
slot in hidpp_battery_props[] or register POWER_SUPPLY_PROP_CHARGE_TYPE
in hidpp_initialize_battery() when HIDPP_CAPABILITY_BATTERY_VOLTAGE is
set. Consequently, the charge_type attribute was never exposed via
sysfs. Furthermore, hidpp20_battery_voltage_event() only checked
whether voltage or status changed before updating cached battery values
and notifying user space, ignoring changes in level and charge_type.
Additionally, hidpp20_battery_map_status_voltage() unconditionally set
charge_type to standard (or fast/trickle) charging even when the device
was discharging, full, not charging, or in an unknown status, and
hidpp_connect_event() left charge_type stale on wireless disconnect.
Add a placeholder slot to hidpp_battery_props[], update the fixed
property count in hidpp_initialize_battery(), append
POWER_SUPPLY_PROP_CHARGE_TYPE when HIDPP_CAPABILITY_BATTERY_VOLTAGE is
set, and include level and charge_type in the change detection condition
in hidpp20_battery_voltage_event(). In
hidpp20_battery_map_status_voltage(), map charge_type to unknown when
status is unknown, to none when discharging, full, or not charging, and
to standard, fast, or trickle only when charging. Reset charge_type to
unknown on wireless disconnect in hidpp_connect_event().
Fixes: be281368f297 ("hid-logitech-hidpp: read battery voltage from newer devices")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@xxxxxxxxx>
---
drivers/hid/hid-logitech-hidpp.c | 30 ++++++++++++++++++++++--------
1 file changed, 22 insertions(+), 8 deletions(-)
diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c
index dbf8f15f5a5b..966c5932528d 100644
--- a/drivers/hid/hid-logitech-hidpp.c
+++ b/drivers/hid/hid-logitech-hidpp.c
@@ -1428,12 +1428,17 @@ static int hidpp20_battery_map_status_voltage(u8 data[3], int *voltage,
else
status = POWER_SUPPLY_STATUS_DISCHARGING;
- *charge_type = POWER_SUPPLY_CHARGE_TYPE_STANDARD;
- if (test_bit(3, &flags)) {
- *charge_type = POWER_SUPPLY_CHARGE_TYPE_FAST;
- }
- if (test_bit(4, &flags)) {
- *charge_type = POWER_SUPPLY_CHARGE_TYPE_TRICKLE;
+ if (status == POWER_SUPPLY_STATUS_CHARGING) {
+ if (test_bit(4, &flags))
+ *charge_type = POWER_SUPPLY_CHARGE_TYPE_TRICKLE;
+ else if (test_bit(3, &flags))
+ *charge_type = POWER_SUPPLY_CHARGE_TYPE_FAST;
+ else
+ *charge_type = POWER_SUPPLY_CHARGE_TYPE_STANDARD;
+ } else if (status == POWER_SUPPLY_STATUS_UNKNOWN) {
+ *charge_type = POWER_SUPPLY_CHARGE_TYPE_UNKNOWN;
+ } else {
+ *charge_type = POWER_SUPPLY_CHARGE_TYPE_NONE;
}
if (test_bit(5, &flags)) {
*level = POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL;
@@ -1553,7 +1558,10 @@ static int hidpp20_battery_voltage_event(struct hidpp_device *hidpp,
hidpp->battery.online = status != POWER_SUPPLY_STATUS_NOT_CHARGING;
- if (voltage != hidpp->battery.voltage || status != hidpp->battery.status) {
+ if (voltage != hidpp->battery.voltage ||
+ status != hidpp->battery.status ||
+ level != hidpp->battery.level ||
+ charge_type != hidpp->battery.charge_type) {
hidpp->battery.voltage = voltage;
hidpp->battery.capacity = hidpp20_map_battery_capacity(hidpp->hid_dev,
voltage);
@@ -1795,6 +1803,7 @@ static enum power_supply_property hidpp_battery_props[] = {
0, /* placeholder for POWER_SUPPLY_PROP_CAPACITY, */
0, /* placeholder for POWER_SUPPLY_PROP_CAPACITY_LEVEL, */
0, /* placeholder for POWER_SUPPLY_PROP_VOLTAGE_NOW, */
+ 0, /* placeholder for POWER_SUPPLY_PROP_CHARGE_TYPE, */
};
static int hidpp_battery_get_property(struct power_supply *psy,
@@ -4398,7 +4407,7 @@ static int hidpp_initialize_battery(struct hidpp_device *hidpp)
if (!battery_props)
return -ENOMEM;
- num_battery_props = ARRAY_SIZE(hidpp_battery_props) - 3;
+ num_battery_props = ARRAY_SIZE(hidpp_battery_props) - 4;
if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_MILEAGE ||
hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_PERCENTAGE ||
@@ -4416,6 +4425,10 @@ static int hidpp_initialize_battery(struct hidpp_device *hidpp)
battery_props[num_battery_props++] =
POWER_SUPPLY_PROP_VOLTAGE_NOW;
+ if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_VOLTAGE)
+ battery_props[num_battery_props++] =
+ POWER_SUPPLY_PROP_CHARGE_TYPE;
+
battery = &hidpp->battery;
n = atomic_inc_return(&battery_no) - 1;
@@ -4511,6 +4524,7 @@ static void hidpp_connect_event(struct work_struct *work)
hidpp->battery.online = false;
hidpp->battery.status = POWER_SUPPLY_STATUS_UNKNOWN;
hidpp->battery.level = POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN;
+ hidpp->battery.charge_type = POWER_SUPPLY_CHARGE_TYPE_UNKNOWN;
power_supply_changed(hidpp->battery.ps);
}
return;
--
2.56.1.750.gf70dc682cf-goog