aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/lm95241.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/lm95241.c')
-rw-r--r--drivers/hwmon/lm95241.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/drivers/hwmon/lm95241.c b/drivers/hwmon/lm95241.c
index 1a6dfb6df1e7..d3b464b74ced 100644
--- a/drivers/hwmon/lm95241.c
+++ b/drivers/hwmon/lm95241.c
@@ -98,11 +98,16 @@ struct lm95241_data {
98}; 98};
99 99
100/* Conversions */ 100/* Conversions */
101static int TempFromReg(u8 val_h, u8 val_l) 101static int temp_from_reg_signed(u8 val_h, u8 val_l)
102{ 102{
103 if (val_h & 0x80) 103 s16 val_hl = (val_h << 8) | val_l;
104 return val_h - 0x100; 104 return val_hl * 1000 / 256;
105 return val_h * 1000 + val_l * 1000 / 256; 105}
106
107static int temp_from_reg_unsigned(u8 val_h, u8 val_l)
108{
109 u16 val_hl = (val_h << 8) | val_l;
110 return val_hl * 1000 / 256;
106} 111}
107 112
108static struct lm95241_data *lm95241_update_device(struct device *dev) 113static 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,
135 char *buf) 140 char *buf)
136{ 141{
137 struct lm95241_data *data = lm95241_update_device(dev); 142 struct lm95241_data *data = lm95241_update_device(dev);
143 int index = to_sensor_dev_attr(attr)->index;
138 144
139 return snprintf(buf, PAGE_SIZE - 1, "%d\n", 145 return snprintf(buf, PAGE_SIZE - 1, "%d\n",
140 TempFromReg(data->temp[to_sensor_dev_attr(attr)->index], 146 index == 0 || (data->config & (1 << (index / 2))) ?
141 data->temp[to_sensor_dev_attr(attr)->index + 1])); 147 temp_from_reg_signed(data->temp[index], data->temp[index + 1]) :
148 temp_from_reg_unsigned(data->temp[index],
149 data->temp[index + 1]));
142} 150}
143 151
144static ssize_t show_type(struct device *dev, struct device_attribute *attr, 152static ssize_t show_type(struct device *dev, struct device_attribute *attr,
@@ -339,7 +347,7 @@ static int lm95241_detect(struct i2c_client *new_client,
339 if ((i2c_smbus_read_byte_data(new_client, LM95241_REG_R_MAN_ID) 347 if ((i2c_smbus_read_byte_data(new_client, LM95241_REG_R_MAN_ID)
340 == MANUFACTURER_ID) 348 == MANUFACTURER_ID)
341 && (i2c_smbus_read_byte_data(new_client, LM95241_REG_R_CHIP_ID) 349 && (i2c_smbus_read_byte_data(new_client, LM95241_REG_R_CHIP_ID)
342 >= DEFAULT_REVISION)) { 350 == DEFAULT_REVISION)) {
343 name = DEVNAME; 351 name = DEVNAME;
344 } else { 352 } else {
345 dev_dbg(&adapter->dev, "LM95241 detection failed at 0x%02x\n", 353 dev_dbg(&adapter->dev, "LM95241 detection failed at 0x%02x\n",