mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-27 11:19:37 +00:00
staging iio adt7410: fix 13bit mode
The driver assumes that in 13bit mode the 16bit value has to be shifted to the right by 3 bits. This is not true, in both 16bit and 13bit mode the MSB is at the same position. Currently the driver returns a temperature of 194 degrees Celsius in 13bit mode and 24 degrees Celsius in 16bit mode. Fix this by using the same algorithm for 16bit and 13bit mode and by just masking out the lower three bits in 13bit mode. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Acked-by: Sonic Zhang <sonic.zhang@analog.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
This commit is contained in:
parent
3a427d184f
commit
1764eff7d5
1 changed files with 10 additions and 19 deletions
|
@ -293,26 +293,17 @@ static ssize_t adt7410_convert_temperature(struct adt7410_chip_info *chip,
|
|||
{
|
||||
char sign = ' ';
|
||||
|
||||
if (chip->config & ADT7410_RESOLUTION) {
|
||||
if (data & ADT7410_T16_VALUE_SIGN) {
|
||||
/* convert supplement to positive value */
|
||||
data = (u16)((ADT7410_T16_VALUE_SIGN << 1) - (u32)data);
|
||||
sign = '-';
|
||||
}
|
||||
return sprintf(buf, "%c%d.%.7d\n", sign,
|
||||
(data >> ADT7410_T16_VALUE_FLOAT_OFFSET),
|
||||
(data & ADT7410_T16_VALUE_FLOAT_MASK) * 78125);
|
||||
} else {
|
||||
if (data & ADT7410_T13_VALUE_SIGN) {
|
||||
/* convert supplement to positive value */
|
||||
data >>= ADT7410_T13_VALUE_OFFSET;
|
||||
data = (ADT7410_T13_VALUE_SIGN << 1) - data;
|
||||
sign = '-';
|
||||
}
|
||||
return sprintf(buf, "%c%d.%.4d\n", sign,
|
||||
(data >> ADT7410_T13_VALUE_FLOAT_OFFSET),
|
||||
(data & ADT7410_T13_VALUE_FLOAT_MASK) * 625);
|
||||
if (!(chip->config & ADT7410_RESOLUTION))
|
||||
data &= ~0x7;
|
||||
|
||||
if (data & ADT7410_T16_VALUE_SIGN) {
|
||||
/* convert supplement to positive value */
|
||||
data = (u16)((ADT7410_T16_VALUE_SIGN << 1) - (u32)data);
|
||||
sign = '-';
|
||||
}
|
||||
return sprintf(buf, "%c%d.%.7d\n", sign,
|
||||
(data >> ADT7410_T16_VALUE_FLOAT_OFFSET),
|
||||
(data & ADT7410_T16_VALUE_FLOAT_MASK) * 78125);
|
||||
}
|
||||
|
||||
static ssize_t adt7410_show_value(struct device *dev,
|
||||
|
|
Loading…
Reference in a new issue