All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: Jean Delvare <jdelvare@suse.com>,
	Guenter Roeck <linux@roeck-us.net>,
	linux-hwmon@vger.kernel.org, Peter Rosin <peda@axentia.se>,
	Chris Lesiak <chris.lesiak@licor.com>,
	linux-iio@vger.kernel.org
Subject: Re: [PATCH] hwmon: (ntc_thermistor): Use library interpolation
Date: Sun, 4 Jul 2021 17:14:06 +0100	[thread overview]
Message-ID: <20210704171406.61235987@jic23-huawei> (raw)
In-Reply-To: <20210703180131.4036589-1-linus.walleij@linaro.org>

On Sat,  3 Jul 2021 20:01:31 +0200
Linus Walleij <linus.walleij@linaro.org> wrote:

> The kernel has a helper function for linear interpolation so
> use it. It incidentally makes the code easier to read as well.
> 
> Cc: Peter Rosin <peda@axentia.se>
> Cc: Chris Lesiak <chris.lesiak@licor.com>
> Cc: linux-iio@vger.kernel.org
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

Potential precision problem because the multiplication by 1000 is now done
post division whereas before it was before it?

I'm only eyeballing the code so no idea if it makes a practical difference.

> ---
>  drivers/hwmon/ntc_thermistor.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/hwmon/ntc_thermistor.c b/drivers/hwmon/ntc_thermistor.c
> index 8587189c7f15..61bd0e074ec9 100644
> --- a/drivers/hwmon/ntc_thermistor.c
> +++ b/drivers/hwmon/ntc_thermistor.c
> @@ -14,6 +14,7 @@
>  #include <linux/err.h>
>  #include <linux/of.h>
>  #include <linux/of_device.h>
> +#include <linux/fixp-arith.h>
>  
>  #include <linux/platform_data/ntc_thermistor.h>
>  
> @@ -557,10 +558,12 @@ static int get_temp_mc(struct ntc_data *data, unsigned int ohm)
>  		/* Unable to use linear approximation */
>  		temp = data->comp[low].temp_c * 1000;
>  	} else {
> -		temp = data->comp[low].temp_c * 1000 +
> -			((data->comp[high].temp_c - data->comp[low].temp_c) *
> -			 1000 * ((int)ohm - (int)data->comp[low].ohm)) /
> -			((int)data->comp[high].ohm - (int)data->comp[low].ohm);
> +		temp = fixp_linear_interpolate(data->comp[low].ohm,
> +					       data->comp[low].temp_c,
> +					       data->comp[high].ohm,
> +					       data->comp[high].temp_c,
> +					       ohm);
> +		temp *= 1000;
>  	}
>  	return temp;
>  }


  reply	other threads:[~2021-07-04 16:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-03 18:01 [PATCH] hwmon: (ntc_thermistor): Use library interpolation Linus Walleij
2021-07-04 16:14 ` Jonathan Cameron [this message]
2021-07-04 17:50   ` Guenter Roeck

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=20210704171406.61235987@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=chris.lesiak@licor.com \
    --cc=jdelvare@suse.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=peda@axentia.se \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.