Thread (31 messages) 31 messages, 4 authors, 2021-12-05

Re: [RFC PATCH v3 2/9] power: supply: add cap2ocv batinfo helper

From: Vaittinen, Matti <hidden>
Date: 2021-11-18 05:31:02
Also in: linux-pm, lkml

On 11/18/21 04:02, Linus Walleij wrote:
On Tue, Nov 16, 2021 at 1:25 PM Matti Vaittinen
[off-list ref] wrote:
quoted
The power-supply core supports concept of OCV (Open Circuit Voltage) =>
SOC (State Of Charge) conversion tables. Usually these tables are used
to estimate SOC based on OCV. Some systems use so called "Zero Adjust"
where at the near end-of-battery condition the SOC from coulomb counter
is used to retrieve the OCV - and OCV and VSYS difference is used to
re-estimate the battery capacity.

Add helper to do look-up the other-way around and also get the OCV
based on SOC

Signed-off-by: Matti Vaittinen <redacted>
It seems you will need this for your chargers indeed.
quoted
+int power_supply_dcap2ocv_simple(struct power_supply_battery_ocv_table *table,
+                               int table_len, int dcap)
+{
+       int i, ocv, tmp;
+
+       for (i = 0; i < table_len; i++)
+               if (dcap > table[i].capacity * 10)
+                       break;
+
+       if (i > 0 && i < table_len) {
+               tmp = (table[i - 1].ocv - table[i].ocv) *
+                     (dcap - table[i].capacity * 10);
+
+               tmp /= (table[i - 1].capacity - table[i].capacity) * 10;
+               ocv = tmp + table[i].ocv;
+       } else if (i == 0) {
+               ocv = table[0].ocv;
+       } else {
+               ocv = table[table_len - 1].ocv;
+       }
+
+       return ocv;
+}
+EXPORT_SYMBOL_GPL(power_supply_dcap2ocv_simple);
Rewrite this using the library fixpoint interpolation function but just
copypasting from my patch:
https://lore.kernel.org/linux-pm/20211116230233.2167104-1-linus.walleij@linaro.org/ (local)
Thanks :)
I actually saw this (yesterday?) but didn't revise my patches. Thanks 
for the head's up - it's always good to have this kind of helpers :)
Other than that it looks good to me!
Thanks!

Best Regards
     --Matti


-- 
The Linux Kernel guy at ROHM Semiconductors

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

~~ this year is the year of a signature writers block ~~
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help