[RFC PATCH 0/2] power: supply: Add some fuel-gauge logic

From: Matti Vaittinen
Date: Thu Nov 26 2020 - 05:09:14 EST


Sorry folks - I picked you as recipients just because I saw
your name in few recent commits to power-supply (well,
obviously Sebastian would have been picked anyways). I assumed
you could have something to say in here. Please let me know if you
wish to be dropped from CC if this gets any further.



power: supply: add sw-gauge for SOC estimation and CC correction

I have couple of ROHM PMIC drivers for devices with battery charger
and coulomb counter in device. Some users have asked me if these
drivers could be added upstream - and I actually think it would help
people. While evaluating these drivers I saw they do implement
some fuel-gauging/CC correcting logic - which might be useful for
other similar ICs. Hence I am wondering if I should try pulling the
logic out of IC drivers to power-supply core while leaving just IC
specific code in drivers. This RFC is first result for pulling the
logic out of drivers.

The goal of this RFC is really to clarify if I should just abandon
this idea and keep this logic in charger-driver(s) - or if there
already is some "de-facto" way of achieving the same (in which
case I should again abandon this and get new direction).

In other words, this is an early state RFC for adding some
fuel-gauge logic to power-supply core. I would highly appreciate if
the idea of adding _something_ like this was first discussed and
evaluated. This RFC has only been compile-tested this far so no
accurate reviewing or "acceptance" for this version is requested.
The code may still have few issues here and there... So instead of
asking for proper code review here, I am overall asking if this
kind of functionality would be welcome in power-supply core, and if
yes - then I would like to get some overall direction for this.
I am for example wondering if this should be added as a own entity
which uses power-supply class underneath (in a way this RFC
introduces it) - or if it should be meld in existing power-supply
class. But there's no point in pondering this if this kind of
functionality has no chance being accepted :)

Is seen as potentially useful feature which should be
in-kernel? (I think this has it's place in-kernel as HW details
like coulomb-counter adjustment should really not be something
user-space should care. Another reason is that few low-power
embedded devices actually do periodical wake-up from suspend/
other low-power states just to do CC adjustment - even though
the wake-up costs some power. If this is ever to be supported
by mainline kernel - then waking up the whole user-space just
to do this CC adjustment iteration is not preferable. But that
wake-up is not covered by this RFC, it is just one motvation
behind putting this in-kernel - where it in my opinion would be
better to be generic and available for all ICs than written in
each IC specific driver).

Oh, please let me know if you wish to see some more documentation,
I can try adding something in Documentation folder too.

Anyways, enough of babbling for now - thanks for reading all the
way here:)


Matti Vaittinen (2):
power: supply: add cap2ocv batinfo helper
power: supply: add sw-gauge for SOC estimation and CC correction

drivers/power/supply/Kconfig | 8 +
drivers/power/supply/Makefile | 1 +
drivers/power/supply/power_supply_core.c | 51 ++
drivers/power/supply/power_supply_swgauge.c | 808 ++++++++++++++++++++
include/linux/power/sw_gauge.h | 203 +++++
include/linux/power_supply.h | 11 +
6 files changed, 1082 insertions(+)
create mode 100644 drivers/power/supply/power_supply_swgauge.c
create mode 100644 include/linux/power/sw_gauge.h


base-commit: 09162bc32c880a791c6c0668ce0745cf7958f576
--
2.25.4


--
Matti Vaittinen, Linux device drivers
ROHM Semiconductors, Finland SWDC
Kiviharjunlenkki 1E
90220 OULU
FINLAND

~~~ "I don't think so," said Rene Descartes. Just then he vanished ~~~
Simon says - in Latin please.
~~~ "non cogito me" dixit Rene Descarte, deinde evanescavit ~~~
Thanks to Simon Glass for the translation =]