hid-logitech-hidpp: read battery voltage from newer devices
authorPedro Vanzella <pedro@pedrovanzella.com>
Sat, 26 Oct 2019 22:25:06 +0000 (19:25 -0300)
committerBenjamin Tissoires <benjamin.tissoires@redhat.com>
Wed, 18 Dec 2019 14:36:15 +0000 (15:36 +0100)
commitbe281368f29797cf4b318ad890673ce96bb9251e
tree5a62aa6c007494ec2b514abe25065456a1c8a765
parent04bd68171e01843284accbcfaa4cd2c50d1707ed
hid-logitech-hidpp: read battery voltage from newer devices

Newer Logitech mice report their battery voltage through feature 0x1001
instead of the battery levels through feature 0x1000.

When the device is brought up and we try to query the battery, figure
out if it supports the old or the new feature. If it supports the new
feature, record the feature index and read the battery voltage and
its charge status. The device will respond with three bytes: the first
two are its voltage, and the last one is a bitset, reporting if the
battery is charging, fast or slow, in critical level or discharging.

If everything went correctly, record the fact that we're capable
of querying battery voltage.

Note that the protocol only gives us the current voltage in mV.
We store that as-is, but when queried, we report it in uV as
expected by sysfs.

Like we do for other ways of interacting with the battery for other
devices, refresh the battery status and notify the power supply
subsystem of the changes in voltage and status.

Since there are no known devices which implement both the old and the
new battery feature, we make sure to try the newer feature first and
only fall back to the old one if that fails.

Signed-off-by: Pedro Vanzella <pedro@pedrovanzella.com>
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
drivers/hid/hid-logitech-hidpp.c