power: supply: Add adc-battery-helper
authorHans de Goede <hansg@kernel.org>
Sun, 31 Aug 2025 12:29:37 +0000 (14:29 +0200)
committerSebastian Reichel <sebastian.reichel@collabora.com>
Fri, 5 Sep 2025 23:50:01 +0000 (01:50 +0200)
commit6a93f54333979c2948e9c1e71ea0b377b486a3f5
tree32097c29d084016e14e1462dbb746c580ddf5144
parent1b237f190eb3d36f52dffe07a40b5eb210280e00
power: supply: Add adc-battery-helper

The TI PMIC used on some Intel Bay/Cherry Trail systems has some builtin
fuel-gauge functionality which just like the UG3105 fuel-gauge is not
a full featured autonomous fuel-gauge.

These fuel-gauges offer accurate current and voltage measurements but
their coulomb-counters are intended to work together with an always on
micro-controller monitoring the fuel-gauge.

Add an adc-battery-helper offering open-circuit-voltage (ocv) and through
that capacity estimation for devices where such limited functionality
fuel-gauges are exposed directly to Linux.

This is a copy of the existing UG3105 estimating code, generalized so that
it can be re-used in other drivers.

The next commit will replace the UG3105 driver's version of this code with
using the adc-battery-helper.

The API has been designed for easy integration into existing power-supply
drivers. For example this functionality might also be a useful addition
to the generic-adc-battery driver.

The requirement of needing the adc_battery_helper struct to be the first
member of a battery driver's data struct is not ideal. This is a compromise
which is necessary to allow directly using the helper's get_property(),
external_power_changed() and suspend()/resume() functions as power-supply /
suspend-resume callbacks.

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Hans de Goede <hansg@kernel.org>
Link: https://lore.kernel.org/r/20250831122942.47875-2-hansg@kernel.org
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
drivers/power/supply/Kconfig
drivers/power/supply/Makefile
drivers/power/supply/adc-battery-helper.c [new file with mode: 0644]
drivers/power/supply/adc-battery-helper.h [new file with mode: 0644]