diff options
author | Chris Lesiak <chris.lesiak@licor.com> | 2015-06-01 19:27:37 +0300 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2015-06-02 16:53:50 +0300 |
commit | 0315253b19bbc63eedad2f6125c21e280c76e29b (patch) | |
tree | 67997e9f452d6db148be106e492df5aaff165c8c | |
parent | e892b75ff579a0c07b633f2e234aeecf78a93a37 (diff) | |
download | linux-0315253b19bbc63eedad2f6125c21e280c76e29b.tar.xz |
hwmon: (ntc_thermistor) fix iio raw to microvolts conversion
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>
-rw-r--r-- | drivers/hwmon/ntc_thermistor.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/drivers/hwmon/ntc_thermistor.c b/drivers/hwmon/ntc_thermistor.c index fca92912269e..3a2484aba57e 100644 --- a/drivers/hwmon/ntc_thermistor.c +++ b/drivers/hwmon/ntc_thermistor.c @@ -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[] = { |