On Tue, Nov 16, 2021 at 1:28 PM Matti Vaittinen <matti.vaittinen@xxxxxxxxxxxxxxxxx> wrote: > Add generic 'simple gauge' helper for performing iterative SOC estimation > and coulomb counter correction for devices with a (drifting) coulomb > counter. This should allow few charger/fuel-gauge drivers to use generic > loop instead of implementing their own. > > Charger/fuel-gauge drivers can register 'simple-gauge' which does > periodically poll the driver and: > - get battery state > - adjust coulomb counter value (to fix drifting caused for example by ADC > offset) if: > - Battery is relaxed and OCV<=>SOC table is given > - Battery is full charged > - get battery age (cycles) from driver > - get battery temperature > - do battery capacity correction > - by battery temperature > - by battery age > - by computed Vbat/OCV difference at low-battery condition if > low-limit is set and OCV table given > - by IC specific low-battery correction if provided > - compute current State Of Charge (SOC) > - do periodical calibration if IC supports that. (Many ICs do calibration > of CC by shorting the ADC pins and getting the offset). > - provide the user-space a consistent interface for getting/setting the > battery-cycle information for ICs which can't store the battery aging > information. Uses POWER_SUPPLY_PROP_CYCLE_COUNT for this. > > The simple gauge provides the last computed SOC as > POWER_SUPPLY_PROP_CAPACITY to power_supply_class when requested. > > Things that should/could be added but are missing from this commit: > - Support starting calibration in HW when entering to suspend. This > is useful for ICs supporting delayed calibration to mitigate CC error > during suspend - and to make periodical wake-up less critical. > - periodical wake-up for performing SOC estimation computation (RTC > integration) > > Signed-off-by: Matti Vaittinen <matti.vaittinen@xxxxxxxxxxxxxxxxx> This is the right ambition, I haven't looked close at it but the way you use it seem to be what you need, so: Acked-by: Linus Walleij <linus.walleij@xxxxxxxxxx> (and the rest of the patches to the Rohm chips) Yours, Linus Walleij