public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Lars-Peter Clausen <lars@metafoo.de>
To: "Kim, Milo" <Milo.Kim@ti.com>
Cc: "cbou@mail.ru" <cbou@mail.ru>,
	Anton Vorontsov <anton.vorontsov@linaro.org>,
	Jonathan Cameron <jic23@kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 3/3] lp8788-charger: fix wrong ADC conversion
Date: Fri, 19 Oct 2012 14:45:30 +0200	[thread overview]
Message-ID: <50814B6A.6010000@metafoo.de> (raw)
In-Reply-To: <A874F61F95741C4A9BA573A70FE3998F64179109@DQHE02.ent.ti.com>

On 10/19/2012 02:12 AM, Kim, Milo wrote:
>  To get the battery voltage and temperature, IIO ADC functions are used.
>  LP8788 ADC driver provides RAW and SCALE channel information.
>  This patch fixes wrong ADC result.
> 
>  Patch v2.
>  Use simple iio_read_channel_processed() function rather than
>  iio_read_channel_raw() and _scale().
> 
>  Fix the result type of ADC function as a signed integer.
>  Because power_supply_propval.intval and the return value of
>  iio_read_channel_processed() are a signed integer,
>  'unsigned int' are replaced with 'int'.
> 
>  Patch v1.
>  Fix wrong ADC results using iio_read_channel_raw() and _scale().
> 
> Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com>

Looks good to me, fwiw:

Reviewed-by Lars-Peter Clausen <lars@metafoo.de>

But there is one issue, but this is not necessarily related to this patch,
more inline.

> ---
>  drivers/power/lp8788-charger.c |   26 +++++++-------------------
>  1 file changed, 7 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/power/lp8788-charger.c b/drivers/power/lp8788-charger.c
> index 02fc9ab..f18ec8f 100644
> --- a/drivers/power/lp8788-charger.c
> +++ b/drivers/power/lp8788-charger.c
> @@ -235,25 +235,14 @@ static int lp8788_get_battery_present(struct lp8788_charger *pchg,
>  	return 0;
>  }
>  
[...]
>  static int lp8788_get_battery_voltage(struct lp8788_charger *pchg,
> @@ -268,7 +257,7 @@ static int lp8788_get_battery_capacity(struct lp8788_charger *pchg,
>  	struct lp8788 *lp = pchg->lp;
>  	struct lp8788_charger_platform_data *pdata = pchg->pdata;
>  	unsigned int max_vbatt;
> -	unsigned int vbatt;
> +	int vbatt;
>  	enum lp8788_charging_state state;
>  	u8 data;
>  	int ret;
> @@ -304,19 +293,18 @@ static int lp8788_get_battery_temperature(struct lp8788_charger *pchg,
>  				union power_supply_propval *val)
>  {
>  	struct iio_channel *channel = pchg->chan[LP8788_BATT_TEMP];
> -	int scaleint;
> -	int scalepart;
> +	int result;
>  	int ret;
>  
>  	if (!channel)
>  		return -EINVAL;
>  
> -	ret = iio_read_channel_scale(channel, &scaleint, &scalepart);
> -	if (ret != IIO_VAL_INT_PLUS_MICRO)
> +	ret = iio_read_channel_processed(channel, &result);
> +	if (ret < 0)
>  		return -EINVAL;
>  
>  	/* unit: 0.1 'C */
> -	val->intval = (scaleint + scalepart * 1000000) / 100;
> +	val->intval = result * 10;

IIO reports temperatures in milli degree Celsius. So it should be multiplied
by 100 to get tenth degree like the power supply framework expects it. But
this might be a issue in your IIO driver reporting the wrong scale.

- Lars

>  
>  	return 0;
>  }


  reply	other threads:[~2012-10-19 12:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-19  0:12 [PATCH v2 3/3] lp8788-charger: fix wrong ADC conversion Kim, Milo
2012-10-19 12:45 ` Lars-Peter Clausen [this message]
2012-11-02 10:09   ` Jonathan Cameron
2012-11-18  4:46     ` Anton Vorontsov

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=50814B6A.6010000@metafoo.de \
    --to=lars@metafoo.de \
    --cc=Milo.Kim@ti.com \
    --cc=anton.vorontsov@linaro.org \
    --cc=cbou@mail.ru \
    --cc=jic23@kernel.org \
    --cc=linux-kernel@vger.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