]> git.baikalelectronics.ru Git - kernel.git/commit
HID: logitech-hidpp: BatteryVoltage: only read chargeStatus if extPower is active
authorFilipe Laíns <lains@archlinux.org>
Sat, 11 Jan 2020 19:24:19 +0000 (19:24 +0000)
committerBenjamin Tissoires <benjamin.tissoires@redhat.com>
Tue, 28 Jan 2020 14:51:19 +0000 (15:51 +0100)
commit102dece6c15a16da0ced9be9427bbbbbf8dae3eb
tree13ccddb2d36c666aa20c9e1dd22449907327ac8a
parent71e66e8e34432c416a2bd7353d0155086a7823c3
HID: logitech-hidpp: BatteryVoltage: only read chargeStatus if extPower is active

In the HID++ 2.0 function getBatteryInfo() from the BatteryVoltage
(0x1001) feature, chargeStatus is only valid if extPower is active.

Previously we were ignoring extPower, which resulted in wrong values.

Example:
    With an unplugged mouse

    $ cat /sys/class/power_supply/hidpp_battery_0/status
    Charging

This patch fixes that, it also renames charge_sts to flags as
charge_sts can be confused with chargeStatus from the spec.

Spec:
+--------+-------------------------------------------------------------------------+
|  byte  |                                    2                                    |
+--------+--------------+------------+------------+----------+----------+----------+
|   bit  |     0..2     |      3     |      4     |     5    |     6    |     7    |
+--------+--------------+------------+------------+----------+----------+----------+
| buffer | chargeStatus | fastCharge | slowCharge | critical | (unused) | extPower |
+--------+--------------+------------+------------+----------+----------+----------+
Table 1 - battery voltage (0x1001), getBatteryInfo() (ASE 0), 3rd byte

+-------+--------------------------------------+
| value |                meaning               |
+-------+--------------------------------------+
|   0   | Charging                             |
+-------+--------------------------------------+
|   1   | End of charge (100% charged)         |
+-------+--------------------------------------+
|   2   | Charge stopped (any "normal" reason) |
+-------+--------------------------------------+
|   7   | Hardware error                       |
+-------+--------------------------------------+
Table 2 - chargeStatus value

Signed-off-by: Filipe Laíns <lains@archlinux.org>
Tested-by: Pedro Vanzella <pedro@pedrovanzella.com>
Reviewed-by: Pedro Vanzella <pedro@pedrovanzella.com>
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
drivers/hid/hid-logitech-hidpp.c