Re: [PATCH v2 13/16] power: supply: axp288_fuel_gauge: Rework get_status()
From: Chen-Yu Tsai <hidden>
Date: 2017-12-27 03:15:26
On Tue, Dec 26, 2017 at 8:59 PM, Hans de Goede [off-list ref] wrote:
Relying on the (dis)charge current reporting for reporting FULL back to userspace does not work really well and often leads to the reported status getting stuck at e.g. 98/99% (the fuelgauge is not perfect) for hours. What happens is that when the battery is full the axp288 keeps charging it with a very low current. Until it is really really full and once really really full, some inaccuracies in the adc lead to it then sometimes reporting a small discharging rate, even though an external pwr source is used. So we end up with a status of "charging" for hours after the battery is actually already full and sometimes this then flip-flops to discharging. This commit fixes this by first checking if a valid Vbus is present and if it is present using the fuel-gauge's reported percentage to check for a full battery. This commit also changes how get_status() determines if the battery is charging or discharging when not reporting it as full. We still use the current direction for this, but instead of reading 4 extra registers for this (2 16 bit regs), simplify things by using the current-direction bit in the power-status register, which already gets read anyways. This also reduces the amount of i2c reads to 1 when on battery and 2 when a valid Vbus is present. Signed-off-by: Hans de Goede <redacted>
This looks better. Thanks. Reviewed-by: Chen-Yu Tsai <redacted> I do have one minor question though: What should the status be if there was no battery connected? Or is that not an issue? ChenYu