public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
From: Baolin Wang <baolin.wang@linux.alibaba.com>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: Sebastian Reichel <sre@kernel.org>,
	linux-pm@vger.kernel.org,
	Chunyan Zhang <chunyan.zhang@unisoc.com>
Subject: Re: [PATCH v2] power: supply: core: Use library interpolation
Date: Tue, 16 Nov 2021 22:36:28 +0800	[thread overview]
Message-ID: <f1d55a78-8910-cfc2-c086-41443ccfa225@linux.alibaba.com> (raw)
In-Reply-To: <CACRpkdbVdU0S+cOZfDczxW+pNVDgc54cB75itFi-V9tjHkq-zA@mail.gmail.com>



On 2021/11/16 21:34, Linus Walleij wrote:
> On Tue, Nov 16, 2021 at 3:28 AM Baolin Wang
> <baolin.wang@linux.alibaba.com> wrote:
> 
>> Thanks for your patch, and overall looks good to me. But I still think
>> we should not do interpolation if the temperature is larger than the
>> maximum value of the table, we can just return the maximum value of the
>> table instead. Something like below untested code, how do you think?
> 
> You are right, but if I understand correctly
> fixp_linear_interpolate() already does what you want,
> perhaps a bit unintuitively. See include/linux/fixp-arith.h:
> 
> static inline int fixp_linear_interpolate(int x0, int y0, int x1, int y1, int x)
> {
>          if (y0 == y1 || x == x0)
>                  return y0;
>          if (x1 == x0 || x == x1)
>                  return y1;
> 
>          return y0 + ((y1 - y0) * (x - x0) / (x1 - x0));
> }
> 

Sorry for confusing, let me try to make it clear. Suppose we have a 
temperature table as below, and try to get the resistance percent in the 
temp=-20 Celsius.

resistance-temp-table = <20 100>, <10 90>, <0 80>, <(-10) 60>;

With your patch, we will get i=table_len-1, which is 3. Then high=2 and 
low=3.

+	for (i = 0; i < table_len - 1; i++)
  		if (temp > table[i].temp)
  			break;

So in fixp_linear_interpolate(): x0=-10, y0=60, x1=0, y1=80, x=-20, then 
will return 60 + (80-60)*(-20-(-10))/(0-(-10)) = 40.

But actually the -20 Celsius is less than (-10), which is the last 
member in the array, we do not need the interpolation, return 60 
directly if I understand correctly. Which means for any other lower 
temperature points, the resistance of the baterry is always 60% of the 
battery internal resistence in normal temperature.

      reply	other threads:[~2021-11-16 14:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-16  0:38 [PATCH v2] power: supply: core: Use library interpolation Linus Walleij
2021-11-16  2:29 ` Baolin Wang
2021-11-16 13:34   ` Linus Walleij
2021-11-16 14:36     ` Baolin Wang [this message]

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=f1d55a78-8910-cfc2-c086-41443ccfa225@linux.alibaba.com \
    --to=baolin.wang@linux.alibaba.com \
    --cc=chunyan.zhang@unisoc.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=sre@kernel.org \
    /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