All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: "Ivan T. Ivanov" <ivan.ivanov@linaro.org>
Cc: Stanimir Varbanov <svarbanov@mm-sol.com>,
	Hartmut Knaack <knaack.h@gmx.de>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Peter Meerwald <pmeerw@pmeerw.net>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-msm@vger.kernel.org
Subject: Re: [PATCH] iio: adc: spmi-vadc: Fix overflow in output value normalization
Date: Sat, 18 Apr 2015 17:41:10 +0100	[thread overview]
Message-ID: <55328926.20509@kernel.org> (raw)
In-Reply-To: <1429282268-30501-1-git-send-email-ivan.ivanov@linaro.org>

On 17/04/15 15:51, Ivan T. Ivanov wrote:
> With 'dx' equal to 0.625V and 15 bit ADC, calculations overflow
> when difference against GND is ~20% of the ADC range. Fix this.
> 
> Signed-off-by: Ivan T. Ivanov <ivan.ivanov@linaro.org>
Applied to the fixes-togreg branch of iio.git and marked for stable.

Thanks,

Jonathan
>
> ---
>  drivers/iio/adc/qcom-spmi-vadc.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/iio/adc/qcom-spmi-vadc.c b/drivers/iio/adc/qcom-spmi-vadc.c
> index 3211729..0c4618b 100644
> --- a/drivers/iio/adc/qcom-spmi-vadc.c
> +++ b/drivers/iio/adc/qcom-spmi-vadc.c
> @@ -18,6 +18,7 @@
>  #include <linux/iio/iio.h>
>  #include <linux/interrupt.h>
>  #include <linux/kernel.h>
> +#include <linux/math64.h>
>  #include <linux/module.h>
>  #include <linux/of.h>
>  #include <linux/platform_device.h>
> @@ -471,11 +472,11 @@ static s32 vadc_calibrate(struct vadc_priv *vadc,
>  			  const struct vadc_channel_prop *prop, u16 adc_code)
>  {
>  	const struct vadc_prescale_ratio *prescale;
> -	s32 voltage;
> +	s64 voltage;
> 
>  	voltage = adc_code - vadc->graph[prop->calibration].gnd;
>  	voltage *= vadc->graph[prop->calibration].dx;
> -	voltage = voltage / vadc->graph[prop->calibration].dy;
> +	voltage = div64_s64(voltage, vadc->graph[prop->calibration].dy);
> 
>  	if (prop->calibration == VADC_CALIB_ABSOLUTE)
>  		voltage += vadc->graph[prop->calibration].dx;
> @@ -487,7 +488,7 @@ static s32 vadc_calibrate(struct vadc_priv *vadc,
> 
>  	voltage = voltage * prescale->den;
> 
> -	return voltage / prescale->num;
> +	return div64_s64(voltage, prescale->num);
>  }
> 
>  static int vadc_decimation_from_dt(u32 value)
> --
> 1.9.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

      reply	other threads:[~2015-04-18 16:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-17 14:51 [PATCH] iio: adc: spmi-vadc: Fix overflow in output value normalization Ivan T. Ivanov
2015-04-18 16:41 ` Jonathan Cameron [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=55328926.20509@kernel.org \
    --to=jic23@kernel.org \
    --cc=ivan.ivanov@linaro.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmeerw@pmeerw.net \
    --cc=svarbanov@mm-sol.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 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.