aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/lm90.c
diff options
context:
space:
mode:
authorBen Hutchings <bhutchings@solarflare.com>2008-10-17 11:51:10 -0400
committerJean Delvare <khali@mahadeva.delvare>2008-10-17 11:51:10 -0400
commit9d4d3834229e9949c066c2d0f73ed5d4b4965761 (patch)
tree38b640053bb8fc5d2057a3614684d67703e7a408 /drivers/hwmon/lm90.c
parent23b2d4778ad33ee6bfe60439fb73c16580f204f2 (diff)
hwmon: (lm90) Rename temperature conversion functions to match usage
The encoding of temperatures varies between chips and modes. So do not use "temp1" or "temp2" in the names of the conversion functions, but specify the encoding. Signed-off-by: Ben Hutchings <bhutchings@solarflare.com> Signed-off-by: Jean Delvare <khali@linux-fr.org> Tested-by: Martyn Welch <martyn.welch@gefanuc.com>
Diffstat (limited to 'drivers/hwmon/lm90.c')
-rw-r--r--drivers/hwmon/lm90.c46
1 files changed, 23 insertions, 23 deletions
diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c
index fe5d860fc838..85ba2c4feb46 100644
--- a/drivers/hwmon/lm90.c
+++ b/drivers/hwmon/lm90.c
@@ -219,17 +219,17 @@ struct lm90_data {
219 * LSB = 0.125 degree Celsius, left-justified in 16-bit registers. 219 * LSB = 0.125 degree Celsius, left-justified in 16-bit registers.
220 */ 220 */
221 221
222static inline int temp1_from_reg(s8 val) 222static inline int temp_from_s8(s8 val)
223{ 223{
224 return val * 1000; 224 return val * 1000;
225} 225}
226 226
227static inline int temp2_from_reg(s16 val) 227static inline int temp_from_s16(s16 val)
228{ 228{
229 return val / 32 * 125; 229 return val / 32 * 125;
230} 230}
231 231
232static s8 temp1_to_reg(long val) 232static s8 temp_to_s8(long val)
233{ 233{
234 if (val <= -128000) 234 if (val <= -128000)
235 return -128; 235 return -128;
@@ -240,7 +240,7 @@ static s8 temp1_to_reg(long val)
240 return (val + 500) / 1000; 240 return (val + 500) / 1000;
241} 241}
242 242
243static s16 temp2_to_reg(long val) 243static s16 temp_to_s16(long val)
244{ 244{
245 if (val <= -128000) 245 if (val <= -128000)
246 return 0x8000; 246 return 0x8000;
@@ -268,23 +268,23 @@ static u8 hyst_to_reg(long val)
268 * ADT7461 in "extended mode" operation uses unsigned integers offset by 268 * ADT7461 in "extended mode" operation uses unsigned integers offset by
269 * 64 (e.g., 0 -> -64 degC). The range is restricted to -64..191 degC. 269 * 64 (e.g., 0 -> -64 degC). The range is restricted to -64..191 degC.
270 */ 270 */
271static inline int temp1_from_reg_adt7461(struct lm90_data *data, u8 val) 271static inline int temp_from_u8_adt7461(struct lm90_data *data, u8 val)
272{ 272{
273 if (data->flags & LM90_FLAG_ADT7461_EXT) 273 if (data->flags & LM90_FLAG_ADT7461_EXT)
274 return (val - 64) * 1000; 274 return (val - 64) * 1000;
275 else 275 else
276 return temp1_from_reg(val); 276 return temp_from_s8(val);
277} 277}
278 278
279static inline int temp2_from_reg_adt7461(struct lm90_data *data, u16 val) 279static inline int temp_from_u16_adt7461(struct lm90_data *data, u16 val)
280{ 280{
281 if (data->flags & LM90_FLAG_ADT7461_EXT) 281 if (data->flags & LM90_FLAG_ADT7461_EXT)
282 return (val - 0x4000) / 64 * 250; 282 return (val - 0x4000) / 64 * 250;
283 else 283 else
284 return temp2_from_reg(val); 284 return temp_from_s16(val);
285} 285}
286 286
287static u8 temp1_to_reg_adt7461(struct lm90_data *data, long val) 287static u8 temp_to_u8_adt7461(struct lm90_data *data, long val)
288{ 288{
289 if (data->flags & LM90_FLAG_ADT7461_EXT) { 289 if (data->flags & LM90_FLAG_ADT7461_EXT) {
290 if (val <= -64000) 290 if (val <= -64000)
@@ -301,7 +301,7 @@ static u8 temp1_to_reg_adt7461(struct lm90_data *data, long val)
301 } 301 }
302} 302}
303 303
304static u16 temp2_to_reg_adt7461(struct lm90_data *data, long val) 304static u16 temp_to_u16_adt7461(struct lm90_data *data, long val)
305{ 305{
306 if (data->flags & LM90_FLAG_ADT7461_EXT) { 306 if (data->flags & LM90_FLAG_ADT7461_EXT) {
307 if (val <= -64000) 307 if (val <= -64000)
@@ -330,9 +330,9 @@ static ssize_t show_temp8(struct device *dev, struct device_attribute *devattr,
330 int temp; 330 int temp;
331 331
332 if (data->kind == adt7461) 332 if (data->kind == adt7461)
333 temp = temp1_from_reg_adt7461(data, data->temp8[attr->index]); 333 temp = temp_from_u8_adt7461(data, data->temp8[attr->index]);
334 else 334 else
335 temp = temp1_from_reg(data->temp8[attr->index]); 335 temp = temp_from_s8(data->temp8[attr->index]);
336 336
337 return sprintf(buf, "%d\n", temp); 337 return sprintf(buf, "%d\n", temp);
338} 338}
@@ -355,9 +355,9 @@ static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
355 355
356 mutex_lock(&data->update_lock); 356 mutex_lock(&data->update_lock);
357 if (data->kind == adt7461) 357 if (data->kind == adt7461)
358 data->temp8[nr] = temp1_to_reg_adt7461(data, val); 358 data->temp8[nr] = temp_to_u8_adt7461(data, val);
359 else 359 else
360 data->temp8[nr] = temp1_to_reg(val); 360 data->temp8[nr] = temp_to_s8(val);
361 i2c_smbus_write_byte_data(client, reg[nr], data->temp8[nr]); 361 i2c_smbus_write_byte_data(client, reg[nr], data->temp8[nr]);
362 mutex_unlock(&data->update_lock); 362 mutex_unlock(&data->update_lock);
363 return count; 363 return count;
@@ -371,9 +371,9 @@ static ssize_t show_temp11(struct device *dev, struct device_attribute *devattr,
371 int temp; 371 int temp;
372 372
373 if (data->kind == adt7461) 373 if (data->kind == adt7461)
374 temp = temp2_from_reg_adt7461(data, data->temp11[attr->index]); 374 temp = temp_from_u16_adt7461(data, data->temp11[attr->index]);
375 else 375 else
376 temp = temp2_from_reg(data->temp11[attr->index]); 376 temp = temp_from_s16(data->temp11[attr->index]);
377 377
378 return sprintf(buf, "%d\n", temp); 378 return sprintf(buf, "%d\n", temp);
379} 379}
@@ -398,11 +398,11 @@ static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
398 398
399 mutex_lock(&data->update_lock); 399 mutex_lock(&data->update_lock);
400 if (data->kind == adt7461) 400 if (data->kind == adt7461)
401 data->temp11[nr] = temp2_to_reg_adt7461(data, val); 401 data->temp11[nr] = temp_to_u16_adt7461(data, val);
402 else if (data->kind == max6657 || data->kind == max6680) 402 else if (data->kind == max6657 || data->kind == max6680)
403 data->temp11[nr] = temp1_to_reg(val) << 8; 403 data->temp11[nr] = temp_to_s8(val) << 8;
404 else 404 else
405 data->temp11[nr] = temp2_to_reg(val); 405 data->temp11[nr] = temp_to_s16(val);
406 406
407 i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2], 407 i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2],
408 data->temp11[nr] >> 8); 408 data->temp11[nr] >> 8);
@@ -421,11 +421,11 @@ static ssize_t show_temphyst(struct device *dev, struct device_attribute *devatt
421 int temp; 421 int temp;
422 422
423 if (data->kind == adt7461) 423 if (data->kind == adt7461)
424 temp = temp1_from_reg_adt7461(data, data->temp8[attr->index]); 424 temp = temp_from_u8_adt7461(data, data->temp8[attr->index]);
425 else 425 else
426 temp = temp1_from_reg(data->temp8[attr->index]); 426 temp = temp_from_s8(data->temp8[attr->index]);
427 427
428 return sprintf(buf, "%d\n", temp - temp1_from_reg(data->temp_hyst)); 428 return sprintf(buf, "%d\n", temp - temp_from_s8(data->temp_hyst));
429} 429}
430 430
431static ssize_t set_temphyst(struct device *dev, struct device_attribute *dummy, 431static ssize_t set_temphyst(struct device *dev, struct device_attribute *dummy,
@@ -437,7 +437,7 @@ static ssize_t set_temphyst(struct device *dev, struct device_attribute *dummy,
437 long hyst; 437 long hyst;
438 438
439 mutex_lock(&data->update_lock); 439 mutex_lock(&data->update_lock);
440 hyst = temp1_from_reg(data->temp8[2]) - val; 440 hyst = temp_from_s8(data->temp8[2]) - val;
441 i2c_smbus_write_byte_data(client, LM90_REG_W_TCRIT_HYST, 441 i2c_smbus_write_byte_data(client, LM90_REG_W_TCRIT_HYST,
442 hyst_to_reg(hyst)); 442 hyst_to_reg(hyst));
443 mutex_unlock(&data->update_lock); 443 mutex_unlock(&data->update_lock);