linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Linus Walleij <linus.walleij@linaro.org>
To: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
Cc: Matti Vaittinen <mazziesaccount@gmail.com>,
	Sebastian Reichel <sebastian.reichel@collabora.com>,
	Krzysztof Kozlowski <krzk@kernel.org>,
	Dmitry Osipenko <digetx@gmail.com>,
	Cong Pham <cpham2403@gmail.com>,
	rostokus@gmail.com, fan.chen@mediatek.com,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Linux PM list <linux-pm@vger.kernel.org>
Subject: Re: [RFC PATCH v2 1/6] power: supply: add cap2ocv batinfo helper
Date: Tue, 8 Dec 2020 09:54:59 +0100	[thread overview]
Message-ID: <CACRpkdYjVJ9_6L2hthkoZ-G51aazxcyeHtu4EmeT8Eoo=0e=8w@mail.gmail.com> (raw)
In-Reply-To: <f2866a9052bbeaa4b3795907f91974e1d18ef68e.1607085199.git.matti.vaittinen@fi.rohmeurope.com>

On Fri, Dec 4, 2020 at 1:41 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>

Overall a good idea!

> +/**
> + * power_supply_cap2ocv_simple() - find the battery OCV by capacity
> + * @table: Pointer to battery OCV/CAP lookup table
> + * @table_len: OCV/CAP table length
> + * @cap: Current cap value
> + *
> + * This helper function is used to look up battery OCV according to
> + * current capacity value from one OCV table, and the OCV table must be ordered
> + * descending.
> + *
> + * Return: the battery OCV.
> + */

Spell out the abbreviations in the kerneldoc and not just the commit.
These will be read much more than the commit message so I would
move all the excellent info in the commit message into the kerneldoc and
diet the commit message instead.

> +int power_supply_cap2ocv_simple(struct power_supply_battery_ocv_table *table,
> +                               int table_len, int cap)
> +{
> +       int i, ocv, tmp;
> +
> +       for (i = 0; i < table_len; i++)
> +               if (cap > table[i].capacity)
> +                       break;
> +
> +       if (i > 0 && i < table_len) {
> +               tmp = (table[i - 1].ocv - table[i].ocv) *
> +                     (cap - table[i].capacity);
> +
> +               tmp /= table[i - 1].capacity - table[i].capacity;
> +               ocv = tmp + table[i].ocv;

This is some linear interpolation right? It's not immediately evident so insert
some comment about what is going on.

>  /**
>   * power_supply_ocv2cap_simple() - find the battery capacity
>   * @table: Pointer to battery OCV lookup table
> @@ -847,6 +884,20 @@ power_supply_find_ocv2cap_table(struct power_supply_battery_info *info,

I suspect this kerneldoc could be improved in the process as well.

Yours,
Linus Walleij

  reply	other threads:[~2020-12-08  8:56 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-04 12:39 [RFC PATCH v2 0/6] power: supply: Add some fuel-gauge logic Matti Vaittinen
2020-12-04 12:41 ` [RFC PATCH v2 1/6] power: supply: add cap2ocv batinfo helper Matti Vaittinen
2020-12-08  8:54   ` Linus Walleij [this message]
2020-12-08  9:30     ` Vaittinen, Matti
2020-12-04 12:43 ` [RFC PATCH v2 2/6] power: supply: add sw-gauge for SOC estimation and CC correction Matti Vaittinen
2020-12-04 12:47 ` [RFC PATCH v2 3/6] mfd: prepare to support BD718xx-charger Matti Vaittinen
2020-12-16  8:49   ` Lee Jones
2020-12-04 12:49 ` [RFC PATCH v2 4/6] mfd: add BD71827 header Matti Vaittinen
2020-12-16  8:53   ` Lee Jones
2020-12-17  9:40     ` Vaittinen, Matti
2020-12-04 12:53 ` [RFC PATCH v2 5/6] power: supply: Add bd718(27/28/78) charger driver Matti Vaittinen
2020-12-04 12:54 ` [RFC PATCH v2 6/6] MFD: bd71828: differentiate bd71828 and bd71827 chargers Matti Vaittinen
2020-12-16  8:55   ` Lee Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CACRpkdYjVJ9_6L2hthkoZ-G51aazxcyeHtu4EmeT8Eoo=0e=8w@mail.gmail.com' \
    --to=linus.walleij@linaro.org \
    --cc=cpham2403@gmail.com \
    --cc=digetx@gmail.com \
    --cc=fan.chen@mediatek.com \
    --cc=krzk@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=matti.vaittinen@fi.rohmeurope.com \
    --cc=mazziesaccount@gmail.com \
    --cc=rostokus@gmail.com \
    --cc=sebastian.reichel@collabora.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).