hwmon: (nct6775) Only display fan speed tolerance conditionally
A fan speed tolerance only makes sense if a fan target speed has been configured in the first place. Otherwise we get odd output such as fan1_target:0 fan1_tolerance:337500 Only display values other than 0 if a fan target speed has been configured. Signed-off-by: Guenter Roeck <linux@roeck-us.net>
This commit is contained in:
parent
0665a1d623
commit
61b6c66a8f
|
@ -2847,6 +2847,8 @@ store_temp_tolerance(struct device *dev, struct device_attribute *attr,
|
||||||
* Fan speed tolerance is a tricky beast, since the associated register is
|
* Fan speed tolerance is a tricky beast, since the associated register is
|
||||||
* a tick counter, but the value is reported and configured as rpm.
|
* a tick counter, but the value is reported and configured as rpm.
|
||||||
* Compute resulting low and high rpm values and report the difference.
|
* Compute resulting low and high rpm values and report the difference.
|
||||||
|
* A fan speed tolerance only makes sense if a fan target speed has been
|
||||||
|
* configured, so only display values other than 0 if that is the case.
|
||||||
*/
|
*/
|
||||||
static ssize_t
|
static ssize_t
|
||||||
show_speed_tolerance(struct device *dev, struct device_attribute *attr,
|
show_speed_tolerance(struct device *dev, struct device_attribute *attr,
|
||||||
|
@ -2855,19 +2857,23 @@ show_speed_tolerance(struct device *dev, struct device_attribute *attr,
|
||||||
struct nct6775_data *data = nct6775_update_device(dev);
|
struct nct6775_data *data = nct6775_update_device(dev);
|
||||||
struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
|
struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
|
||||||
int nr = sattr->index;
|
int nr = sattr->index;
|
||||||
int low = data->target_speed[nr] - data->target_speed_tolerance[nr];
|
int target = data->target_speed[nr];
|
||||||
int high = data->target_speed[nr] + data->target_speed_tolerance[nr];
|
int tolerance = 0;
|
||||||
int tolerance;
|
|
||||||
|
|
||||||
if (low <= 0)
|
if (target) {
|
||||||
low = 1;
|
int low = target - data->target_speed_tolerance[nr];
|
||||||
if (high > 0xffff)
|
int high = target + data->target_speed_tolerance[nr];
|
||||||
high = 0xffff;
|
|
||||||
if (high < low)
|
|
||||||
high = low;
|
|
||||||
|
|
||||||
tolerance = (fan_from_reg16(low, data->fan_div[nr])
|
if (low <= 0)
|
||||||
- fan_from_reg16(high, data->fan_div[nr])) / 2;
|
low = 1;
|
||||||
|
if (high > 0xffff)
|
||||||
|
high = 0xffff;
|
||||||
|
if (high < low)
|
||||||
|
high = low;
|
||||||
|
|
||||||
|
tolerance = (fan_from_reg16(low, data->fan_div[nr])
|
||||||
|
- fan_from_reg16(high, data->fan_div[nr])) / 2;
|
||||||
|
}
|
||||||
|
|
||||||
return sprintf(buf, "%d\n", tolerance);
|
return sprintf(buf, "%d\n", tolerance);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue