power: supply: Support VBAT-to-Ri lookup tables
authorLinus Walleij <linus.walleij@linaro.org>
Fri, 25 Feb 2022 23:27:58 +0000 (00:27 +0100)
committerSebastian Reichel <sebastian.reichel@collabora.com>
Mon, 28 Feb 2022 10:34:32 +0000 (11:34 +0100)
commite9e7d165b4b0413c5b7db74515e4981a226b78a0
tree4bb2a186091776db007d7d1d833bb52e3e7edf94
parent1f918e0fe43ec41d906e2cf96b80b15451fed7ba
power: supply: Support VBAT-to-Ri lookup tables

In Samsung devices, the method used to compensate for temperature,
age, load etc is by way of VBAT to Ri tables, which correlates the
battery voltage under load (VBAT) to an internal resistance (Ri).

Using this Ri and a measurement of the current out of the battery
(IBAT) the open circuit voltage (OCV) can be calculated as:

  OCV = VBAT - (Ri * IBAT)

The details are described in comments to struct
power_supply_battery_info in the commit.

Since not all batteries supply this VBAT-to-Ri data, the fallback
method to use the temperature-to-Ri lookup table can also be used
as a fallback.

Add two helper functions to check if we have the tables needed for
using power_supply_vbat2ri() or power_supply_temp2resist_simple()
respectively, so capacity estimation code can choose which one
to employ.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
drivers/power/supply/power_supply_core.c
include/linux/power_supply.h