aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/adt7473.c
diff options
context:
space:
mode:
authorMark M. Hoffman <mhoffman@lightlink.com>2008-03-06 08:41:09 -0500
committerMark M. Hoffman <mhoffman@lightlink.com>2008-04-27 09:23:12 -0400
commit1852448652fd526d56099256dadc4ef32cb1b10e (patch)
tree1f3e51d0f3ce3f267df962a85275b993fbd9d7f0 /drivers/hwmon/adt7473.c
parent5d822e9bd9d866672984c6a6b613f0c11ca2543b (diff)
hwmon: (adt7473) minor cleanup / refactoring
Acked-by: Darrick J. Wong <djwong@us.ibm.com> Signed-off-by: Mark M. Hoffman <mhoffman@lightlink.com>
Diffstat (limited to 'drivers/hwmon/adt7473.c')
-rw-r--r--drivers/hwmon/adt7473.c45
1 files changed, 23 insertions, 22 deletions
diff --git a/drivers/hwmon/adt7473.c b/drivers/hwmon/adt7473.c
index 9587869bdba0..c1009d6f9796 100644
--- a/drivers/hwmon/adt7473.c
+++ b/drivers/hwmon/adt7473.c
@@ -422,18 +422,14 @@ static ssize_t show_volt(struct device *dev, struct device_attribute *devattr,
422 * number in the range -128 to 127, or as an unsigned number that must 422 * number in the range -128 to 127, or as an unsigned number that must
423 * be offset by 64. 423 * be offset by 64.
424 */ 424 */
425static int decode_temp(struct adt7473_data *data, u8 raw) 425static int decode_temp(u8 twos_complement, u8 raw)
426{ 426{
427 if (data->temp_twos_complement) 427 return twos_complement ? (s8)raw : raw - 64;
428 return (s8)raw;
429 return raw - 64;
430} 428}
431 429
432static u8 encode_temp(struct adt7473_data *data, int cooked) 430static u8 encode_temp(u8 twos_complement, int cooked)
433{ 431{
434 if (data->temp_twos_complement) 432 return twos_complement ? cooked & 0xFF : cooked + 64;
435 return (cooked & 0xFF);
436 return cooked + 64;
437} 433}
438 434
439static ssize_t show_temp_min(struct device *dev, 435static ssize_t show_temp_min(struct device *dev,
@@ -442,8 +438,9 @@ static ssize_t show_temp_min(struct device *dev,
442{ 438{
443 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 439 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
444 struct adt7473_data *data = adt7473_update_device(dev); 440 struct adt7473_data *data = adt7473_update_device(dev);
445 return sprintf(buf, "%d\n", 441 return sprintf(buf, "%d\n", 1000 * decode_temp(
446 1000 * decode_temp(data, data->temp_min[attr->index])); 442 data->temp_twos_complement,
443 data->temp_min[attr->index]));
447} 444}
448 445
449static ssize_t set_temp_min(struct device *dev, 446static ssize_t set_temp_min(struct device *dev,
@@ -455,7 +452,7 @@ static ssize_t set_temp_min(struct device *dev,
455 struct i2c_client *client = to_i2c_client(dev); 452 struct i2c_client *client = to_i2c_client(dev);
456 struct adt7473_data *data = i2c_get_clientdata(client); 453 struct adt7473_data *data = i2c_get_clientdata(client);
457 int temp = simple_strtol(buf, NULL, 10) / 1000; 454 int temp = simple_strtol(buf, NULL, 10) / 1000;
458 temp = encode_temp(data, temp); 455 temp = encode_temp(data->temp_twos_complement, temp);
459 456
460 mutex_lock(&data->lock); 457 mutex_lock(&data->lock);
461 data->temp_min[attr->index] = temp; 458 data->temp_min[attr->index] = temp;
@@ -472,8 +469,9 @@ static ssize_t show_temp_max(struct device *dev,
472{ 469{
473 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 470 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
474 struct adt7473_data *data = adt7473_update_device(dev); 471 struct adt7473_data *data = adt7473_update_device(dev);
475 return sprintf(buf, "%d\n", 472 return sprintf(buf, "%d\n", 1000 * decode_temp(
476 1000 * decode_temp(data, data->temp_max[attr->index])); 473 data->temp_twos_complement,
474 data->temp_max[attr->index]));
477} 475}
478 476
479static ssize_t set_temp_max(struct device *dev, 477static ssize_t set_temp_max(struct device *dev,
@@ -485,7 +483,7 @@ static ssize_t set_temp_max(struct device *dev,
485 struct i2c_client *client = to_i2c_client(dev); 483 struct i2c_client *client = to_i2c_client(dev);
486 struct adt7473_data *data = i2c_get_clientdata(client); 484 struct adt7473_data *data = i2c_get_clientdata(client);
487 int temp = simple_strtol(buf, NULL, 10) / 1000; 485 int temp = simple_strtol(buf, NULL, 10) / 1000;
488 temp = encode_temp(data, temp); 486 temp = encode_temp(data->temp_twos_complement, temp);
489 487
490 mutex_lock(&data->lock); 488 mutex_lock(&data->lock);
491 data->temp_max[attr->index] = temp; 489 data->temp_max[attr->index] = temp;
@@ -501,8 +499,9 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
501{ 499{
502 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 500 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
503 struct adt7473_data *data = adt7473_update_device(dev); 501 struct adt7473_data *data = adt7473_update_device(dev);
504 return sprintf(buf, "%d\n", 502 return sprintf(buf, "%d\n", 1000 * decode_temp(
505 1000 * decode_temp(data, data->temp[attr->index])); 503 data->temp_twos_complement,
504 data->temp[attr->index]));
506} 505}
507 506
508static ssize_t show_fan_min(struct device *dev, 507static ssize_t show_fan_min(struct device *dev,
@@ -671,8 +670,9 @@ static ssize_t show_temp_tmax(struct device *dev,
671{ 670{
672 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 671 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
673 struct adt7473_data *data = adt7473_update_device(dev); 672 struct adt7473_data *data = adt7473_update_device(dev);
674 return sprintf(buf, "%d\n", 673 return sprintf(buf, "%d\n", 1000 * decode_temp(
675 1000 * decode_temp(data, data->temp_tmax[attr->index])); 674 data->temp_twos_complement,
675 data->temp_tmax[attr->index]));
676} 676}
677 677
678static ssize_t set_temp_tmax(struct device *dev, 678static ssize_t set_temp_tmax(struct device *dev,
@@ -684,7 +684,7 @@ static ssize_t set_temp_tmax(struct device *dev,
684 struct i2c_client *client = to_i2c_client(dev); 684 struct i2c_client *client = to_i2c_client(dev);
685 struct adt7473_data *data = i2c_get_clientdata(client); 685 struct adt7473_data *data = i2c_get_clientdata(client);
686 int temp = simple_strtol(buf, NULL, 10) / 1000; 686 int temp = simple_strtol(buf, NULL, 10) / 1000;
687 temp = encode_temp(data, temp); 687 temp = encode_temp(data->temp_twos_complement, temp);
688 688
689 mutex_lock(&data->lock); 689 mutex_lock(&data->lock);
690 data->temp_tmax[attr->index] = temp; 690 data->temp_tmax[attr->index] = temp;
@@ -701,8 +701,9 @@ static ssize_t show_temp_tmin(struct device *dev,
701{ 701{
702 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 702 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
703 struct adt7473_data *data = adt7473_update_device(dev); 703 struct adt7473_data *data = adt7473_update_device(dev);
704 return sprintf(buf, "%d\n", 704 return sprintf(buf, "%d\n", 1000 * decode_temp(
705 1000 * decode_temp(data, data->temp_tmin[attr->index])); 705 data->temp_twos_complement,
706 data->temp_tmin[attr->index]));
706} 707}
707 708
708static ssize_t set_temp_tmin(struct device *dev, 709static ssize_t set_temp_tmin(struct device *dev,
@@ -714,7 +715,7 @@ static ssize_t set_temp_tmin(struct device *dev,
714 struct i2c_client *client = to_i2c_client(dev); 715 struct i2c_client *client = to_i2c_client(dev);
715 struct adt7473_data *data = i2c_get_clientdata(client); 716 struct adt7473_data *data = i2c_get_clientdata(client);
716 int temp = simple_strtol(buf, NULL, 10) / 1000; 717 int temp = simple_strtol(buf, NULL, 10) / 1000;
717 temp = encode_temp(data, temp); 718 temp = encode_temp(data->temp_twos_complement, temp);
718 719
719 mutex_lock(&data->lock); 720 mutex_lock(&data->lock);
720 data->temp_tmin[attr->index] = temp; 721 data->temp_tmin[attr->index] = temp;