Re: [PATCH 1/2] HID: logitech-hidpp: add battery support for HID++ 2.0 devices
From: Bastien Nocera
Date: Fri Jul 08 2016 - 13:38:27 EST
On Fri, 2016-07-08 at 16:35 +0200, Bastien Nocera wrote:
> On Wed, 2016-06-29 at 19:28 +1000, Peter Hutterer wrote:
> > +static int hidpp_battery_get_property(struct power_supply *psy,
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ enum power_supply_property
> > psp,
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ union power_supply_propval
> > *val)
> > +{
> > +ÂÂÂÂÂÂÂstruct hidpp_device *hidpp = power_supply_get_drvdata(psy);
> > +ÂÂÂÂÂÂÂint ret = 0;
> > +
> > +ÂÂÂÂÂÂÂswitch(psp) {
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂcase POWER_SUPPLY_PROP_STATUS:
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂval->intval = hidpp->battery.status;
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂbreak;
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂcase POWER_SUPPLY_PROP_CAPACITY:
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂval->intval = hidpp->battery.level;
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂbreak;
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂdefault:
>
> You forgot to handle POWER_SUPPLY_PROP_SCOPE. This means that UPower
> thinks it's supplying power to the computer to which it is connected.
>
> Should be set to "POWER_SUPPLY_SCOPE_DEVICE". This should fix it.
I've also noticed that my keyboard appears 4 times:
$ cat /sys/class/power_supply/*/device/input/input*/name
Logitech K750
Logitech K750
Logitech Rechargeable Touchpad T650
Logitech K750
Logitech K750
By the way, instead of giving fake values when starting up, you should
use the ONLINE property instead. That way, when the property changes to
1, UPower can start taking the capacity value into account. In the
meanwhile, it would be ignored.
Finally, things like the serial number and model name and manufacturer
should be replicated in the power_supply, so that UPower can use them
too.
Fixing UPower to not do its user-space poking when a device appears
would be quite complicated. First, the unifier device will show up,
then as a child, the power_supply subsystem device, so we cannot just
probe when devices appear, as it would be in the wrong order for us.
Would it be possible to add a sysfs file that's there in those newer
versions of the kernel with this patch included? That way, I'd change
the lines in:
http://cgit.freedesktop.org/upower/tree/rules/95-upower-csr.rules
From:
ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c52b", DRIVER=="logitech-
hidpp-device", ENV{UPOWER_BATTERY_TYPE}="unifying"
to:
ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c52b", DRIVER=="logitech-
hidpp-device", TEST!="builtin_power_supply",
ENV{UPOWER_BATTERY_TYPE}="unifying"
For example.
Sorry about not being able to test this before it was merged for
inclusion.
Cheers