diff options
author | Guenter Roeck <guenter.roeck@ericsson.com> | 2011-02-13 16:08:23 -0500 |
---|---|---|
committer | Guenter Roeck <guenter.roeck@ericsson.com> | 2011-03-15 01:39:18 -0400 |
commit | 3382a918da968318a4284a14b3dee4a38f8a6749 (patch) | |
tree | 4fce52cfcf9632362714fc03a5bcfd2785494759 /drivers/hwmon/w83627ehf.c | |
parent | 26bc440e3f14df5daff4d1ff0f37de5e260cea18 (diff) |
hwmon: (w83627ehf) Store rpm instead of raw fan speed data
Since the fan speed value can be above 0xff, we can no longer use
that value to determine if the fan speed reading is valid. This
makes it difficult to manipulate the stored fan speed register value.
If we store rpm instead of the fan speed register value, we do not
need to correct it if the fan divisor value is changed, and the above
mentioned problem no longer exists.
Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>
Acked-by: Ian Dobson <i.dobson@planet-ian.com>
Diffstat (limited to 'drivers/hwmon/w83627ehf.c')
-rw-r--r-- | drivers/hwmon/w83627ehf.c | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c index df6e50260e01..460292bad74a 100644 --- a/drivers/hwmon/w83627ehf.c +++ b/drivers/hwmon/w83627ehf.c | |||
@@ -452,7 +452,7 @@ struct w83627ehf_data { | |||
452 | u8 in[10]; /* Register value */ | 452 | u8 in[10]; /* Register value */ |
453 | u8 in_max[10]; /* Register value */ | 453 | u8 in_max[10]; /* Register value */ |
454 | u8 in_min[10]; /* Register value */ | 454 | u8 in_min[10]; /* Register value */ |
455 | u16 fan[5]; | 455 | unsigned int rpm[5]; |
456 | u16 fan_min[5]; | 456 | u16 fan_min[5]; |
457 | u8 fan_div[5]; | 457 | u8 fan_div[5]; |
458 | u8 has_fan; /* some fan inputs can be disabled */ | 458 | u8 has_fan; /* some fan inputs can be disabled */ |
@@ -775,11 +775,14 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev) | |||
775 | 775 | ||
776 | /* Measured fan speeds and limits */ | 776 | /* Measured fan speeds and limits */ |
777 | for (i = 0; i < 5; i++) { | 777 | for (i = 0; i < 5; i++) { |
778 | u16 reg; | ||
779 | |||
778 | if (!(data->has_fan & (1 << i))) | 780 | if (!(data->has_fan & (1 << i))) |
779 | continue; | 781 | continue; |
780 | 782 | ||
781 | data->fan[i] = w83627ehf_read_value(data, | 783 | reg = w83627ehf_read_value(data, data->REG_FAN[i]); |
782 | data->REG_FAN[i]); | 784 | data->rpm[i] = data->fan_from_reg(reg, |
785 | data->fan_div[i]); | ||
783 | 786 | ||
784 | if (data->has_fan_min & (1 << i)) | 787 | if (data->has_fan_min & (1 << i)) |
785 | data->fan_min[i] = w83627ehf_read_value(data, | 788 | data->fan_min[i] = w83627ehf_read_value(data, |
@@ -789,9 +792,8 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev) | |||
789 | divider can be increased, let's try that for next | 792 | divider can be increased, let's try that for next |
790 | time */ | 793 | time */ |
791 | if (data->has_fan_div | 794 | if (data->has_fan_div |
792 | && (data->fan[i] >= 0xff | 795 | && (reg >= 0xff || (sio_data->kind == nct6775 |
793 | || (sio_data->kind == nct6775 | 796 | && reg == 0x00)) |
794 | && data->fan[i] == 0x00)) | ||
795 | && data->fan_div[i] < 0x07) { | 797 | && data->fan_div[i] < 0x07) { |
796 | dev_dbg(dev, "Increasing fan%d " | 798 | dev_dbg(dev, "Increasing fan%d " |
797 | "clock divider from %u to %u\n", | 799 | "clock divider from %u to %u\n", |
@@ -984,8 +986,7 @@ show_fan(struct device *dev, struct device_attribute *attr, char *buf) | |||
984 | struct w83627ehf_data *data = w83627ehf_update_device(dev); | 986 | struct w83627ehf_data *data = w83627ehf_update_device(dev); |
985 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 987 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
986 | int nr = sensor_attr->index; | 988 | int nr = sensor_attr->index; |
987 | return sprintf(buf, "%d\n", | 989 | return sprintf(buf, "%d\n", data->rpm[nr]); |
988 | data->fan_from_reg(data->fan[nr], data->fan_div[nr])); | ||
989 | } | 990 | } |
990 | 991 | ||
991 | static ssize_t | 992 | static ssize_t |
@@ -1078,16 +1079,6 @@ store_fan_min(struct device *dev, struct device_attribute *attr, | |||
1078 | /* Write both the fan clock divider (if it changed) and the new | 1079 | /* Write both the fan clock divider (if it changed) and the new |
1079 | fan min (unconditionally) */ | 1080 | fan min (unconditionally) */ |
1080 | if (new_div != data->fan_div[nr]) { | 1081 | if (new_div != data->fan_div[nr]) { |
1081 | /* Preserve the fan speed reading */ | ||
1082 | if (data->fan[nr] != 0xff) { | ||
1083 | if (new_div > data->fan_div[nr]) | ||
1084 | data->fan[nr] >>= new_div - data->fan_div[nr]; | ||
1085 | else if (data->fan[nr] & 0x80) | ||
1086 | data->fan[nr] = 0xff; | ||
1087 | else | ||
1088 | data->fan[nr] <<= data->fan_div[nr] - new_div; | ||
1089 | } | ||
1090 | |||
1091 | dev_dbg(dev, "fan%u clock divider changed from %u to %u\n", | 1082 | dev_dbg(dev, "fan%u clock divider changed from %u to %u\n", |
1092 | nr + 1, div_from_reg(data->fan_div[nr]), | 1083 | nr + 1, div_from_reg(data->fan_div[nr]), |
1093 | div_from_reg(new_div)); | 1084 | div_from_reg(new_div)); |