Skip to content

Commit 667f4ba

Browse files
cpackham-atlnzgroeck
authored andcommitted
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>
1 parent 1001354 commit 667f4ba

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

drivers/hwmon/adm9240.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,10 @@ static struct adm9240_data *adm9240_update_device(struct device *dev)
194194
* 0.5'C per two measurement cycles thus ignore possible
195195
* but unlikely aliasing error on lsb reading. --Grant
196196
*/
197-
data->temp = ((i2c_smbus_read_byte_data(client,
197+
data->temp = (i2c_smbus_read_byte_data(client,
198198
ADM9240_REG_TEMP) << 8) |
199199
i2c_smbus_read_byte_data(client,
200-
ADM9240_REG_TEMP_CONF)) / 128;
200+
ADM9240_REG_TEMP_CONF);
201201

202202
for (i = 0; i < 2; i++) { /* read fans */
203203
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,
263263
char *buf)
264264
{
265265
struct adm9240_data *data = adm9240_update_device(dev);
266-
return sprintf(buf, "%d\n", data->temp * 500); /* 9-bit value */
266+
return sprintf(buf, "%d\n", data->temp / 128 * 500); /* 9-bit value */
267267
}
268268

269269
static ssize_t show_max(struct device *dev, struct device_attribute *devattr,

0 commit comments

Comments
 (0)