summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikolaus Schulz <mail@microschulz.de>2012-02-28 16:15:54 -0500
committerGuenter Roeck <guenter.roeck@ericsson.com>2012-03-02 12:02:23 -0800
commit15d1ad0cc9d2d3f549afddbcdbc9c3637f0d1331 (patch)
treeba695785e271b487c591b86c518f32449258497a
parentb17d6561acc16265b65b1e0d27b649829b61a7e3 (diff)
hwmon: (f75375s) Catch some attempts to write to r/o registers
It makes no sense to attempt to manually configure the fan in auto mode, or set the duty cycle directly in closed loop mode. The corresponding registers are then read-only. If the user tries it nonetheless, error out with EINVAL instead of silently doing nothing. Signed-off-by: Nikolaus Schulz <mail@microschulz.de> [guenter.roeck@ericsson.com: Minor formatting cleanup] Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>
-rw-r--r--drivers/hwmon/f75375s.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/drivers/hwmon/f75375s.c b/drivers/hwmon/f75375s.c
index 9ab034a1b4c..6aa5a9fad87 100644
--- a/drivers/hwmon/f75375s.c
+++ b/drivers/hwmon/f75375s.c
@@ -279,6 +279,21 @@ static bool duty_mode_enabled(u8 pwm_enable)
}
}
+static bool auto_mode_enabled(u8 pwm_enable)
+{
+ switch (pwm_enable) {
+ case 0: /* Manual, duty mode (full speed) */
+ case 1: /* Manual, duty mode */
+ case 3: /* Manual, speed mode */
+ return false;
+ case 2: /* Auto, speed mode */
+ case 4: /* Auto, duty mode */
+ return true;
+ default:
+ BUG();
+ }
+}
+
static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
@@ -312,6 +327,11 @@ static ssize_t set_fan_target(struct device *dev, struct device_attribute *attr,
if (err < 0)
return err;
+ if (auto_mode_enabled(data->pwm_enable[nr]))
+ return -EINVAL;
+ if (data->kind == f75387 && duty_mode_enabled(data->pwm_enable[nr]))
+ return -EINVAL;
+
mutex_lock(&data->update_lock);
data->fan_target[nr] = rpm_to_reg(val);
f75375_write16(client, F75375_REG_FAN_EXP(nr), data->fan_target[nr]);
@@ -332,6 +352,10 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
if (err < 0)
return err;
+ if (auto_mode_enabled(data->pwm_enable[nr]) ||
+ !duty_mode_enabled(data->pwm_enable[nr]))
+ return -EINVAL;
+
mutex_lock(&data->update_lock);
data->pwm[nr] = SENSORS_LIMIT(val, 0, 255);
f75375_write_pwm(client, nr);
@@ -793,6 +817,9 @@ static void f75375_init(struct i2c_client *client, struct f75375_data *data,
set_pwm_enable_direct(client, 0, f75375s_pdata->pwm_enable[0]);
set_pwm_enable_direct(client, 1, f75375s_pdata->pwm_enable[1]);
for (nr = 0; nr < 2; nr++) {
+ if (auto_mode_enabled(f75375s_pdata->pwm_enable[nr]) ||
+ !duty_mode_enabled(f75375s_pdata->pwm_enable[nr]))
+ continue;
data->pwm[nr] = SENSORS_LIMIT(f75375s_pdata->pwm[nr], 0, 255);
f75375_write_pwm(client, nr);
}