[Letux-kernel] [PATCH v2] power: supply: bq27xxx: do not report incorrect zero values

Sicelo absicsz at gmail.com
Mon Mar 24 16:42:27 CET 2025


Hi

> > 
> > +static bool bq27xxx_value_is_valid(struct bq27xxx_device_info *di, int value)
> > +{
> > + /*
> > + * On bq27xxx_0_zero, consider zero values invalid if EDVF is not set
> > + */
> > + return value || !(di->opts & BQ27XXX_O_ZERO) ||
> > +       (di->cache.flags & BQ27000_FLAG_EDVF);
> 
> Hm. This still can return -EINVAL for a valid and successful readout of value == 0 which
> could happen for a fully drained HF08 in the GTA04 with bq27000.
> 
> Here is an excerpt from running a battery until depletion:
> 
> root at letux:~# echo off >/sys/class/power_supply/twl4030_usb/mode
> root at letux:~# while true; do echo $(date) $(cat /sys/class/power_supply/bq27000-battery/capacity)%; sleep 1; done
> 
> Mon Mar 24 14:37:11 UTC 2025 1%
> Mon Mar 24 14:37:12 UTC 2025 1%
> Mon Mar 24 14:37:13 UTC 2025 1%
> ...
> 
> Mon Mar 24 14:38:24 UTC 2025 1%
> Mon Mar 24 14:38:25 UTC 2025 1%
> Mon Mar 24 14:38:26 UTC 2025 1%
> Mon Mar 24 14:38:27 UTC 2025 1%
> cat: /sys/class/power_supply/bq27000-battery/capacity: Invalid argument
> Mon Mar 24 14:38:28 UTC 2025 %
> cat: /sys/class/power_supply/bq27000-battery/capacity: Invalid argument
> Mon Mar 24 14:38:29 UTC 2025 %
> cat: /sys/class/power_supply/bq27000-battery/capacity: Invalid argument
> Mon Mar 24 14:38:30 UTC 2025 %
> cat: /sys/class/power_supply/bq27000-battery/capacity: Invalid argument
> Mon Mar 24 14:38:32 UTC 2025 %
> ...
> cat: /sys/class/power_supply/bq27000-battery/capacity: Invalid argument
> Mon Mar 24 14:53:39 UTC 2025 %
> cat: /sys/class/power_supply/bq27000-battery/capacity: Invalid argument
> Mon Mar 24 14:53:40 UTC 2025 %
> cat: /sys/class/power_supply/bq27000-battery/capacity: Invalid argument
> Mon Mar 24 14:53:41 UTC 2025 %
> cat: /sys/class/power_supply/bq27000-battery/capacity: Invalid argument
> Mon Mar 24 14:53:42 UTC 2025 %
> Mon Mar 24 14:53:43 UTC 2025 0%
> Mon Mar 24 14:53:44 UTC 2025 0%
> Mon Mar 24 14:53:45 UTC 2025 0%
> Mon Mar 24 14:53:46 UTC 2025 0%
> Mon Mar 24 14:53:47 UTC 2025 0%
> Mon Mar 24 14:53:48 UTC 2025 0%
> Mon Mar 24 14:53:49 UTC 2025 0%
> Mon Mar 24 14:53:50 UTC 2025 0%
> Mon Mar 24 14:53:51 UTC 2025 0%
> Mon Mar 24 14:53:53 UTC 2025 0%
> 
> ...
> 
> Mon Mar 24 15:10:12 UTC 2025 0%
> Mon Mar 24 15:10:14 UTC 2025 0%
> Mon Mar 24 15:10:15 UTC 2025 0%
> --- here device did shut down ---
> 
> This means that the capacity can go to 0% for approx. 15 minutes before
> the BQ27000_FLAG_EDVF becomes set and 0% is reported. I would prefer not
> to see the EINVAL in between.
> 
> This all may end that we have to add another DT property to tell the driver
> if the bq27xxx is inside a battery or the battery is removeable and only check
> for value=0 in the latter case?
> 
> Or can you limit this logic to the bq27200 because it is unlikely that the
> i2c variant is used inside a battery pack and the HF08 battery uses the hdq
> variant?

I can see the problem. Thanks for testing. Let us retract this patch. I
think we can solve the issue in userspace.

Sincerely
Sicelo


More information about the Letux-kernel mailing list