lkml.org 
[lkml]   [2021]   [Nov]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [RFC PATCH v3 2/9] power: supply: add cap2ocv batinfo helper
Date
On 11/18/21 04:02, Linus Walleij wrote:
> On Tue, Nov 16, 2021 at 1:25 PM Matti Vaittinen
> <matti.vaittinen@fi.rohmeurope.com> 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 <matti.vaittinen@fi.rohmeurope.com>
>
> 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/

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 ~~
\
 
 \ /
  Last update: 2021-11-18 06:31    [W:0.298 / U:0.308 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site