Re: [PATCH v2] HID: uclogic: Add support for XP-PEN Deco LW

From: Bastien Nocera
Date: Sun Oct 30 2022 - 07:35:12 EST


On Sat, 2022-10-29 at 16:55 +0200, José Expósito wrote:
> Hi!
>
> On Sat, Oct 29, 2022 at 04:55:21PM +0300, Mia Kanashi wrote:
> > > > [1] Actually it should be set to discharging until this gets
> > > > merged:
> > > >   
> > > > https://lore.kernel.org/linux-input/20221028181849.23157-1-jose.exposito89@xxxxxxxxx/T/
> > >
> > > But i also currently applied this ^ patch, i will try testing
> > > without it and then report.
> >
> > Tested without it, same issue.
> > So yeah it seems that hid-input driver can set supply status to
> > discharging before setting a battery capacity?
>
> Very good catch. I managed to reproduce it using the USB dongle. I
> didn't notice it before because I was running upower after connecting
> the device, which isn't fast enough. However, using watch as you
> suggested makes the issue pretty noticeable.
>
> The problem is that the battery is fetched when the USB dongle is
> connected. However, the tablet might not be paired at that point.
>
> To explain it with the actual code:
>
>
>   if (dev->battery_status != HID_BATTERY_REPORTED &&
>       !dev->battery_avoid_query) {
>         value = hidinput_query_battery_capacity(dev);
>                 ^ Here the battery is fetched, but because the tabled
>                   is not paired and this function returns garbage
>         if (value < 0)
>                 return value;
>
>         dev->battery_capacity = value;
>         dev->battery_status = HID_BATTERY_QUERIED;
>                             ^ Now the battery is set as queried
>   }
>
>   if (dev->battery_status == HID_BATTERY_UNKNOWN)
>         val->intval = POWER_SUPPLY_STATUS_UNKNOWN;
>   else
>         val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
>                     ^ And therefore the battery is reported
>
>
> Thankfully, there is already a flag (battery_avoid_query) used to
> solve
> the same issue on stylus. The battery percentage is unknown until the
> stylus is in proximity.
>
> So I guess I could use the same flag to avoid this problem.
>
> I'll add a fix in a second revision of this patch.

UPower will also respect the POWER_SUPPLY_PROP_PRESENT property, if
that's useful.