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

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

From: Linus Walleij <hidden>
Date: 2021-11-18 02:02:40
Also in: linux-pm, lkml

On Tue, Nov 16, 2021 at 1:25 PM Matti Vaittinen
[off-list ref] wrote:
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.
+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)

Other than that it looks good to me!

Yours,
Linus Walleij
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help