diff options
author | Guenter Roeck <linux@roeck-us.net> | 2012-12-19 16:17:00 -0500 |
---|---|---|
committer | Jean Delvare <khali@endymion.delvare> | 2012-12-19 16:17:00 -0500 |
commit | 60ca385a530405ab501773ef4c9e222825a6cd40 (patch) | |
tree | 4c6e3d327ce8e38bcfccc20ae12358d9b7f38dd3 /drivers/hwmon/it87.c | |
parent | 45633fb370fdd16608756d587245459bf8983a26 (diff) |
hwmon: (it87) Save temperature registers in 2-dimensional array
Cleaner code, fewer checkpatch errors, and reduced code size
(saves more than 500 bytes on x86-64).
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers/hwmon/it87.c')
-rw-r--r-- | drivers/hwmon/it87.c | 98 |
1 files changed, 35 insertions, 63 deletions
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c index d32aa354cbdf..76ab1d0e42d0 100644 --- a/drivers/hwmon/it87.c +++ b/drivers/hwmon/it87.c | |||
@@ -265,9 +265,7 @@ struct it87_data { | |||
265 | u16 fan[5]; /* Register values, possibly combined */ | 265 | u16 fan[5]; /* Register values, possibly combined */ |
266 | u16 fan_min[5]; /* Register values, possibly combined */ | 266 | u16 fan_min[5]; /* Register values, possibly combined */ |
267 | u8 has_temp; /* Bitfield, temp sensors enabled */ | 267 | u8 has_temp; /* Bitfield, temp sensors enabled */ |
268 | s8 temp[3]; /* Register value */ | 268 | s8 temp[3][3]; /* [nr][0]=temp, [1]=min, [2]=max */ |
269 | s8 temp_high[3]; /* Register value */ | ||
270 | s8 temp_low[3]; /* Register value */ | ||
271 | u8 sensor; /* Register value */ | 269 | u8 sensor; /* Register value */ |
272 | u8 fan_div[3]; /* Register encoding, shifted right */ | 270 | u8 fan_div[3]; /* Register encoding, shifted right */ |
273 | u8 vid; /* Register encoding, combined */ | 271 | u8 vid; /* Register encoding, combined */ |
@@ -545,56 +543,22 @@ show_in_offset(8); | |||
545 | 543 | ||
546 | /* 3 temperatures */ | 544 | /* 3 temperatures */ |
547 | static ssize_t show_temp(struct device *dev, struct device_attribute *attr, | 545 | static ssize_t show_temp(struct device *dev, struct device_attribute *attr, |
548 | char *buf) | 546 | char *buf) |
549 | { | 547 | { |
550 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 548 | struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); |
551 | int nr = sensor_attr->index; | 549 | int nr = sattr->nr; |
552 | 550 | int index = sattr->index; | |
553 | struct it87_data *data = it87_update_device(dev); | 551 | struct it87_data *data = it87_update_device(dev); |
554 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr])); | ||
555 | } | ||
556 | static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr, | ||
557 | char *buf) | ||
558 | { | ||
559 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | ||
560 | int nr = sensor_attr->index; | ||
561 | 552 | ||
562 | struct it87_data *data = it87_update_device(dev); | 553 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr][index])); |
563 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_high[nr])); | ||
564 | } | 554 | } |
565 | static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr, | ||
566 | char *buf) | ||
567 | { | ||
568 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | ||
569 | int nr = sensor_attr->index; | ||
570 | 555 | ||
571 | struct it87_data *data = it87_update_device(dev); | 556 | static ssize_t set_temp(struct device *dev, struct device_attribute *attr, |
572 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_low[nr])); | 557 | const char *buf, size_t count) |
573 | } | ||
574 | static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, | ||
575 | const char *buf, size_t count) | ||
576 | { | 558 | { |
577 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 559 | struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); |
578 | int nr = sensor_attr->index; | 560 | int nr = sattr->nr; |
579 | 561 | int index = sattr->index; | |
580 | struct it87_data *data = dev_get_drvdata(dev); | ||
581 | long val; | ||
582 | |||
583 | if (kstrtol(buf, 10, &val) < 0) | ||
584 | return -EINVAL; | ||
585 | |||
586 | mutex_lock(&data->update_lock); | ||
587 | data->temp_high[nr] = TEMP_TO_REG(val); | ||
588 | it87_write_value(data, IT87_REG_TEMP_HIGH(nr), data->temp_high[nr]); | ||
589 | mutex_unlock(&data->update_lock); | ||
590 | return count; | ||
591 | } | ||
592 | static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, | ||
593 | const char *buf, size_t count) | ||
594 | { | ||
595 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | ||
596 | int nr = sensor_attr->index; | ||
597 | |||
598 | struct it87_data *data = dev_get_drvdata(dev); | 562 | struct it87_data *data = dev_get_drvdata(dev); |
599 | long val; | 563 | long val; |
600 | 564 | ||
@@ -602,22 +566,30 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, | |||
602 | return -EINVAL; | 566 | return -EINVAL; |
603 | 567 | ||
604 | mutex_lock(&data->update_lock); | 568 | mutex_lock(&data->update_lock); |
605 | data->temp_low[nr] = TEMP_TO_REG(val); | 569 | data->temp[nr][index] = TEMP_TO_REG(val); |
606 | it87_write_value(data, IT87_REG_TEMP_LOW(nr), data->temp_low[nr]); | 570 | it87_write_value(data, |
571 | index == 1 ? IT87_REG_TEMP_LOW(nr) | ||
572 | : IT87_REG_TEMP_HIGH(nr), | ||
573 | data->temp[nr][index]); | ||
607 | mutex_unlock(&data->update_lock); | 574 | mutex_unlock(&data->update_lock); |
608 | return count; | 575 | return count; |
609 | } | 576 | } |
610 | #define show_temp_offset(offset) \ | ||
611 | static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \ | ||
612 | show_temp, NULL, offset - 1); \ | ||
613 | static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \ | ||
614 | show_temp_max, set_temp_max, offset - 1); \ | ||
615 | static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \ | ||
616 | show_temp_min, set_temp_min, offset - 1); | ||
617 | 577 | ||
618 | show_temp_offset(1); | 578 | static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0); |
619 | show_temp_offset(2); | 579 | static SENSOR_DEVICE_ATTR_2(temp1_min, S_IRUGO | S_IWUSR, show_temp, set_temp, |
620 | show_temp_offset(3); | 580 | 0, 1); |
581 | static SENSOR_DEVICE_ATTR_2(temp1_max, S_IRUGO | S_IWUSR, show_temp, set_temp, | ||
582 | 0, 2); | ||
583 | static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 1, 0); | ||
584 | static SENSOR_DEVICE_ATTR_2(temp2_min, S_IRUGO | S_IWUSR, show_temp, set_temp, | ||
585 | 1, 1); | ||
586 | static SENSOR_DEVICE_ATTR_2(temp2_max, S_IRUGO | S_IWUSR, show_temp, set_temp, | ||
587 | 1, 2); | ||
588 | static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 2, 0); | ||
589 | static SENSOR_DEVICE_ATTR_2(temp3_min, S_IRUGO | S_IWUSR, show_temp, set_temp, | ||
590 | 2, 1); | ||
591 | static SENSOR_DEVICE_ATTR_2(temp3_max, S_IRUGO | S_IWUSR, show_temp, set_temp, | ||
592 | 2, 2); | ||
621 | 593 | ||
622 | static ssize_t show_sensor(struct device *dev, struct device_attribute *attr, | 594 | static ssize_t show_sensor(struct device *dev, struct device_attribute *attr, |
623 | char *buf) | 595 | char *buf) |
@@ -2419,12 +2391,12 @@ static struct it87_data *it87_update_device(struct device *dev) | |||
2419 | for (i = 0; i < 3; i++) { | 2391 | for (i = 0; i < 3; i++) { |
2420 | if (!(data->has_temp & (1 << i))) | 2392 | if (!(data->has_temp & (1 << i))) |
2421 | continue; | 2393 | continue; |
2422 | data->temp[i] = | 2394 | data->temp[i][0] = |
2423 | it87_read_value(data, IT87_REG_TEMP(i)); | 2395 | it87_read_value(data, IT87_REG_TEMP(i)); |
2424 | data->temp_high[i] = | 2396 | data->temp[i][1] = |
2425 | it87_read_value(data, IT87_REG_TEMP_HIGH(i)); | ||
2426 | data->temp_low[i] = | ||
2427 | it87_read_value(data, IT87_REG_TEMP_LOW(i)); | 2397 | it87_read_value(data, IT87_REG_TEMP_LOW(i)); |
2398 | data->temp[i][2] = | ||
2399 | it87_read_value(data, IT87_REG_TEMP_HIGH(i)); | ||
2428 | } | 2400 | } |
2429 | 2401 | ||
2430 | /* Newer chips don't have clock dividers */ | 2402 | /* Newer chips don't have clock dividers */ |