Skip to content

Commit

Permalink
hwmon: (ntc_thermistor) fix iio raw to microvolts conversion
Browse files Browse the repository at this point in the history
The function ntc_adc_iio_read was assuming both a 12 bit ADC and that
pullup_uv is the same as the ADC reference voltage.  If either
assumption is false, then the result is incorrect.

Attempt to use iio_convert_raw_to_processed to convert the raw value to
microvolts.  It will fail for iio channels that don't support support
IIO_CHAN_INFO_SCALE; in that case fall back to the assumptions.

Signed-off-by: Chris Lesiak <chris.lesiak@licor.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
  • Loading branch information
Chris Lesiak authored and Guenter Roeck committed Jun 2, 2015
1 parent e892b75 commit 0315253
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions drivers/hwmon/ntc_thermistor.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,20 +228,21 @@ struct ntc_data {
static int ntc_adc_iio_read(struct ntc_thermistor_platform_data *pdata)
{
struct iio_channel *channel = pdata->chan;
s64 result;
int val, ret;
int raw, uv, ret;

ret = iio_read_channel_raw(channel, &val);
ret = iio_read_channel_raw(channel, &raw);
if (ret < 0) {
pr_err("read channel() error: %d\n", ret);
return ret;
}

/* unit: mV */
result = pdata->pullup_uv * (s64) val;
result >>= 12;
ret = iio_convert_raw_to_processed(channel, raw, &uv, 1000);
if (ret < 0) {
/* Assume 12 bit ADC with vref at pullup_uv */
uv = (pdata->pullup_uv * (s64)raw) >> 12;
}

return (int)result;
return uv;
}

static const struct of_device_id ntc_match[] = {
Expand Down

0 comments on commit 0315253

Please sign in to comment.