From 4b4d9e7405a1e9b30749c17773ba7879969784da Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Thu, 30 Jun 2011 02:09:37 -0700 Subject: [PATCH] --- yaml --- r: 254805 b: refs/heads/master c: 0c2a40e2fe4f4af0410f57e84b95b817ec15aa70 h: refs/heads/master i: 254803: 9c77f6a25cb7ef4a9936565bc31776eb6a5a02e0 v: v3 --- [refs] | 2 +- trunk/drivers/hwmon/lm95241.c | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/[refs] b/[refs] index 00550b943bb4..30100eec02c8 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 27739e694a3c34b5e371575d74e500d60111c689 +refs/heads/master: 0c2a40e2fe4f4af0410f57e84b95b817ec15aa70 diff --git a/trunk/drivers/hwmon/lm95241.c b/trunk/drivers/hwmon/lm95241.c index 01c638e31e07..d3b464b74ced 100644 --- a/trunk/drivers/hwmon/lm95241.c +++ b/trunk/drivers/hwmon/lm95241.c @@ -98,11 +98,16 @@ struct lm95241_data { }; /* Conversions */ -static int TempFromReg(u8 val_h, u8 val_l) +static int temp_from_reg_signed(u8 val_h, u8 val_l) { - if (val_h & 0x80) - return val_h - 0x100; - return val_h * 1000 + val_l * 1000 / 256; + s16 val_hl = (val_h << 8) | val_l; + return val_hl * 1000 / 256; +} + +static int temp_from_reg_unsigned(u8 val_h, u8 val_l) +{ + u16 val_hl = (val_h << 8) | val_l; + return val_hl * 1000 / 256; } static struct lm95241_data *lm95241_update_device(struct device *dev) @@ -135,10 +140,13 @@ static ssize_t show_input(struct device *dev, struct device_attribute *attr, char *buf) { struct lm95241_data *data = lm95241_update_device(dev); + int index = to_sensor_dev_attr(attr)->index; return snprintf(buf, PAGE_SIZE - 1, "%d\n", - TempFromReg(data->temp[to_sensor_dev_attr(attr)->index], - data->temp[to_sensor_dev_attr(attr)->index + 1])); + index == 0 || (data->config & (1 << (index / 2))) ? + temp_from_reg_signed(data->temp[index], data->temp[index + 1]) : + temp_from_reg_unsigned(data->temp[index], + data->temp[index + 1])); } static ssize_t show_type(struct device *dev, struct device_attribute *attr,