hwmon: (adm9240) handle temperature readings below 0
Unlike the temperature thresholds the temperature data is a 9-bit signed value. This allows and additional 0.5 degrees of precision on the reading but makes handling negative values slightly harder. In order to have sign-extension applied correctly the 9-bit value is stored in the upper bits of a signed 16-bit value. When presenting this in sysfs the value is shifted and scaled appropriately. Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
This commit is contained in:
parent
1001354ca3
commit
667f4bab81
|
@ -194,10 +194,10 @@ static struct adm9240_data *adm9240_update_device(struct device *dev)
|
||||||
* 0.5'C per two measurement cycles thus ignore possible
|
* 0.5'C per two measurement cycles thus ignore possible
|
||||||
* but unlikely aliasing error on lsb reading. --Grant
|
* but unlikely aliasing error on lsb reading. --Grant
|
||||||
*/
|
*/
|
||||||
data->temp = ((i2c_smbus_read_byte_data(client,
|
data->temp = (i2c_smbus_read_byte_data(client,
|
||||||
ADM9240_REG_TEMP) << 8) |
|
ADM9240_REG_TEMP) << 8) |
|
||||||
i2c_smbus_read_byte_data(client,
|
i2c_smbus_read_byte_data(client,
|
||||||
ADM9240_REG_TEMP_CONF)) / 128;
|
ADM9240_REG_TEMP_CONF);
|
||||||
|
|
||||||
for (i = 0; i < 2; i++) { /* read fans */
|
for (i = 0; i < 2; i++) { /* read fans */
|
||||||
data->fan[i] = i2c_smbus_read_byte_data(client,
|
data->fan[i] = i2c_smbus_read_byte_data(client,
|
||||||
|
@ -263,7 +263,7 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *dummy,
|
||||||
char *buf)
|
char *buf)
|
||||||
{
|
{
|
||||||
struct adm9240_data *data = adm9240_update_device(dev);
|
struct adm9240_data *data = adm9240_update_device(dev);
|
||||||
return sprintf(buf, "%d\n", data->temp * 500); /* 9-bit value */
|
return sprintf(buf, "%d\n", data->temp / 128 * 500); /* 9-bit value */
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t show_max(struct device *dev, struct device_attribute *devattr,
|
static ssize_t show_max(struct device *dev, struct device_attribute *devattr,
|
||||||
|
|
Loading…
Reference in New Issue