mbox series

[0/1] power: supply: bq27xxx: expose battery data when CI=1

Message ID 20220419213647.1186284-1-absicsz@gmail.com (mailing list archive)
Headers show
Series power: supply: bq27xxx: expose battery data when CI=1 | expand

Message

Sicelo A. Mhlongo April 19, 2022, 9:36 p.m. UTC
We currently discard capacity information provided by the chip when the
Capacity Inaccurate flag is set. However, in many cases, having this
stale data is better than no information at all.

Even if the chip has been fully reset, the datasheet shows that capacity 
values (NAC specifically) can be seeded by using the WRTNAC facility of 
the Control and Mode registers. After seeding, CI remains set, but the
capacity values are as accurate as the NAC value provided to WRTNAC is.

On the Nokia N900, such seed value can be obtained from rx51_battery, 
which reads battery data directly from the battery's BSI pin. This can
be done in userspace via i2c access to the registers. With this patch,
once seeded, capacity values are available through the driver.

The patch was successfully tested on bq27200 on the Nokia N900.

Signed-off-by: Sicelo A. Mhlongo <absicsz@gmail.com>

Sicelo A. Mhlongo (1):
  power: supply: bq27xxx: expose battery data when CI=1

 drivers/power/supply/bq27xxx_battery.c | 58 +++++++++++++-------------
 1 file changed, 28 insertions(+), 30 deletions(-)

Comments

Pali Rohár April 19, 2022, 10:09 p.m. UTC | #1
On Tuesday 19 April 2022 23:36:46 Sicelo A. Mhlongo wrote:
> We currently discard capacity information provided by the chip when the
> Capacity Inaccurate flag is set. However, in many cases, having this
> stale data is better than no information at all.
> 
> Even if the chip has been fully reset, the datasheet shows that capacity 
> values (NAC specifically) can be seeded by using the WRTNAC facility of 
> the Control and Mode registers. After seeding, CI remains set, but the
> capacity values are as accurate as the NAC value provided to WRTNAC is.

NAC (Nominal Available Capacity) is exported via CHARGE_NOW property.

So what about implementing CHARGE_NOW property also writable and write
operation would do this WRTNAC seeding? So userspace would be able to do
'echo new_value > charge_now' and for Nokia N900 case just directly
'cat .../rx51_battery/charge_full_design > .../bq27200/charge_now'

> On the Nokia N900, such seed value can be obtained from rx51_battery, 
> which reads battery data directly from the battery's BSI pin. This can
> be done in userspace via i2c access to the registers. With this patch,
> once seeded, capacity values are available through the driver.
> 
> The patch was successfully tested on bq27200 on the Nokia N900.
> 
> Signed-off-by: Sicelo A. Mhlongo <absicsz@gmail.com>
> 
> Sicelo A. Mhlongo (1):
>   power: supply: bq27xxx: expose battery data when CI=1
> 
>  drivers/power/supply/bq27xxx_battery.c | 58 +++++++++++++-------------
>  1 file changed, 28 insertions(+), 30 deletions(-)
> 
> -- 
> 2.35.2
>
Sicelo A. Mhlongo April 19, 2022, 10:32 p.m. UTC | #2
On Wed, Apr 20, 2022 at 12:09:59AM +0200, Pali Rohár wrote:
> NAC (Nominal Available Capacity) is exported via CHARGE_NOW property.
> 
> So what about implementing CHARGE_NOW property also writable and write
> operation would do this WRTNAC seeding? So userspace would be able to do
> 'echo new_value > charge_now' and for Nokia N900 case just directly
> 'cat .../rx51_battery/charge_full_design > .../bq27200/charge_now'
Thank you for this suggestion. I'm afraid implementing it would be a bit
too involved for my current level of experience.  If someone beats me to
implementing WRTNAC ability, all the better.  Otherwise I will
definitely want to look into it in the future.

The challenge with seeding via rx51_battery is that it provides
CHARGE_FULL_DESIGN, so one must still calculate a NAC value from the
voltage. In my userspace script [1], I am currently using a linear
calculation, but obviously this is not really correct.

I might mention, in passing, that I also wish to later add the 
VOLTAGE_MIN_DESIGN property (which will be taken from EDVF). It may help
userspace (e.g. upower) know when to shutdown the device if CI is set,
as capacity cannot be trusted.

Regards
Sicelo

[1] https://gist.github.com/sicelo/0a0e895d81a6b73b26555d215dee296d#file-rx51_seed_bq27xxx-sh-L34-L42