summaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2010-03-05 22:17:21 +0100
committerJean Delvare <khali@linux-fr.org>2010-03-05 22:17:21 +0100
commitcccfc9c4bb3c7888f8249b36e08d6e115238c613 (patch)
treeacff09833d8e7fd1b87efb27394860ea398dcaa9 /drivers/hwmon
parent4f3f51bc21d434f8d91a79438a1957ec0baa9e30 (diff)
hwmon: (it87) Validate auto pwm settings
Before switching to automatic fan control mode, make sure that all the trip points make sense. Otherwise, the control loop could lead to weird fan behavior. Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/it87.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c
index bbb0c7443b9..1002befd87d 100644
--- a/drivers/hwmon/it87.c
+++ b/drivers/hwmon/it87.c
@@ -719,6 +719,32 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
mutex_unlock(&data->update_lock);
return count;
}
+
+/* Returns 0 if OK, -EINVAL otherwise */
+static int check_trip_points(struct device *dev, int nr)
+{
+ const struct it87_data *data = dev_get_drvdata(dev);
+ int i, err = 0;
+
+ if (has_old_autopwm(data)) {
+ for (i = 0; i < 3; i++) {
+ if (data->auto_temp[nr][i] > data->auto_temp[nr][i + 1])
+ err = -EINVAL;
+ }
+ for (i = 0; i < 2; i++) {
+ if (data->auto_pwm[nr][i] > data->auto_pwm[nr][i + 1])
+ err = -EINVAL;
+ }
+ }
+
+ if (err) {
+ dev_err(dev, "Inconsistent trip points, not switching to "
+ "automatic mode\n");
+ dev_err(dev, "Adjust the trip points and try again\n");
+ }
+ return err;
+}
+
static ssize_t set_pwm_enable(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
@@ -731,6 +757,12 @@ static ssize_t set_pwm_enable(struct device *dev,
if (strict_strtol(buf, 10, &val) < 0 || val < 0 || val > 2)
return -EINVAL;
+ /* Check trip points before switching to automatic mode */
+ if (val == 2) {
+ if (check_trip_points(dev, nr) < 0)
+ return -EINVAL;
+ }
+
mutex_lock(&data->update_lock);
if (val == 0) {