Commit 62d222b8 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging

hhwmon fixes for 3.3-rc6 from Guenter Roeck:

These patches are necessary for correct operation and management of
F75387.

* tag 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging:
  hwmon: (f75375s) Catch some attempts to write to r/o registers
  hwmon: (f75375s) Properly map the F75387 automatic modes to pwm_enable
  hwmon: (f75375s) Make pwm*_mode writable for the F75387
  hwmon: (f75375s) Fix writes to the pwm* attribute for the F75387
parents d085a09c 15d1ad0c
...@@ -178,6 +178,16 @@ static inline void f75375_write16(struct i2c_client *client, u8 reg, ...@@ -178,6 +178,16 @@ static inline void f75375_write16(struct i2c_client *client, u8 reg,
i2c_smbus_write_byte_data(client, reg + 1, (value & 0xFF)); i2c_smbus_write_byte_data(client, reg + 1, (value & 0xFF));
} }
static void f75375_write_pwm(struct i2c_client *client, int nr)
{
struct f75375_data *data = i2c_get_clientdata(client);
if (data->kind == f75387)
f75375_write16(client, F75375_REG_FAN_EXP(nr), data->pwm[nr]);
else
f75375_write8(client, F75375_REG_FAN_PWM_DUTY(nr),
data->pwm[nr]);
}
static struct f75375_data *f75375_update_device(struct device *dev) static struct f75375_data *f75375_update_device(struct device *dev)
{ {
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
...@@ -254,6 +264,36 @@ static inline u16 rpm_to_reg(int rpm) ...@@ -254,6 +264,36 @@ static inline u16 rpm_to_reg(int rpm)
return 1500000 / rpm; return 1500000 / rpm;
} }
static bool duty_mode_enabled(u8 pwm_enable)
{
switch (pwm_enable) {
case 0: /* Manual, duty mode (full speed) */
case 1: /* Manual, duty mode */
case 4: /* Auto, duty mode */
return true;
case 2: /* Auto, speed mode */
case 3: /* Manual, speed mode */
return false;
default:
BUG();
}
}
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, static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
...@@ -287,6 +327,11 @@ static ssize_t set_fan_target(struct device *dev, struct device_attribute *attr, ...@@ -287,6 +327,11 @@ static ssize_t set_fan_target(struct device *dev, struct device_attribute *attr,
if (err < 0) if (err < 0)
return err; 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); mutex_lock(&data->update_lock);
data->fan_target[nr] = rpm_to_reg(val); data->fan_target[nr] = rpm_to_reg(val);
f75375_write16(client, F75375_REG_FAN_EXP(nr), data->fan_target[nr]); f75375_write16(client, F75375_REG_FAN_EXP(nr), data->fan_target[nr]);
...@@ -307,9 +352,13 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, ...@@ -307,9 +352,13 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
if (err < 0) if (err < 0)
return err; return err;
if (auto_mode_enabled(data->pwm_enable[nr]) ||
!duty_mode_enabled(data->pwm_enable[nr]))
return -EINVAL;
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
data->pwm[nr] = SENSORS_LIMIT(val, 0, 255); data->pwm[nr] = SENSORS_LIMIT(val, 0, 255);
f75375_write8(client, F75375_REG_FAN_PWM_DUTY(nr), data->pwm[nr]); f75375_write_pwm(client, nr);
mutex_unlock(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -327,11 +376,15 @@ static int set_pwm_enable_direct(struct i2c_client *client, int nr, int val) ...@@ -327,11 +376,15 @@ static int set_pwm_enable_direct(struct i2c_client *client, int nr, int val)
struct f75375_data *data = i2c_get_clientdata(client); struct f75375_data *data = i2c_get_clientdata(client);
u8 fanmode; u8 fanmode;
if (val < 0 || val > 3) if (val < 0 || val > 4)
return -EINVAL; return -EINVAL;
fanmode = f75375_read8(client, F75375_REG_FAN_TIMER); fanmode = f75375_read8(client, F75375_REG_FAN_TIMER);
if (data->kind == f75387) { if (data->kind == f75387) {
/* For now, deny dangerous toggling of duty mode */
if (duty_mode_enabled(data->pwm_enable[nr]) !=
duty_mode_enabled(val))
return -EOPNOTSUPP;
/* clear each fanX_mode bit before setting them properly */ /* clear each fanX_mode bit before setting them properly */
fanmode &= ~(1 << F75387_FAN_DUTY_MODE(nr)); fanmode &= ~(1 << F75387_FAN_DUTY_MODE(nr));
fanmode &= ~(1 << F75387_FAN_MANU_MODE(nr)); fanmode &= ~(1 << F75387_FAN_MANU_MODE(nr));
...@@ -345,12 +398,14 @@ static int set_pwm_enable_direct(struct i2c_client *client, int nr, int val) ...@@ -345,12 +398,14 @@ static int set_pwm_enable_direct(struct i2c_client *client, int nr, int val)
fanmode |= (1 << F75387_FAN_MANU_MODE(nr)); fanmode |= (1 << F75387_FAN_MANU_MODE(nr));
fanmode |= (1 << F75387_FAN_DUTY_MODE(nr)); fanmode |= (1 << F75387_FAN_DUTY_MODE(nr));
break; break;
case 2: /* AUTOMATIC*/ case 2: /* Automatic, speed mode */
fanmode |= (1 << F75387_FAN_DUTY_MODE(nr));
break; break;
case 3: /* fan speed */ case 3: /* fan speed */
fanmode |= (1 << F75387_FAN_MANU_MODE(nr)); fanmode |= (1 << F75387_FAN_MANU_MODE(nr));
break; break;
case 4: /* Automatic, pwm */
fanmode |= (1 << F75387_FAN_DUTY_MODE(nr));
break;
} }
} else { } else {
/* clear each fanX_mode bit before setting them properly */ /* clear each fanX_mode bit before setting them properly */
...@@ -368,14 +423,15 @@ static int set_pwm_enable_direct(struct i2c_client *client, int nr, int val) ...@@ -368,14 +423,15 @@ static int set_pwm_enable_direct(struct i2c_client *client, int nr, int val)
break; break;
case 3: /* fan speed */ case 3: /* fan speed */
break; break;
case 4: /* Automatic pwm */
return -EINVAL;
} }
} }
f75375_write8(client, F75375_REG_FAN_TIMER, fanmode); f75375_write8(client, F75375_REG_FAN_TIMER, fanmode);
data->pwm_enable[nr] = val; data->pwm_enable[nr] = val;
if (val == 0) if (val == 0)
f75375_write8(client, F75375_REG_FAN_PWM_DUTY(nr), f75375_write_pwm(client, nr);
data->pwm[nr]);
return 0; return 0;
} }
...@@ -726,14 +782,17 @@ static void f75375_init(struct i2c_client *client, struct f75375_data *data, ...@@ -726,14 +782,17 @@ static void f75375_init(struct i2c_client *client, struct f75375_data *data,
manu = ((mode >> F75387_FAN_MANU_MODE(nr)) & 1); manu = ((mode >> F75387_FAN_MANU_MODE(nr)) & 1);
duty = ((mode >> F75387_FAN_DUTY_MODE(nr)) & 1); duty = ((mode >> F75387_FAN_DUTY_MODE(nr)) & 1);
if (manu && duty) if (!manu && duty)
/* speed */ /* auto, pwm */
data->pwm_enable[nr] = 4;
else if (manu && !duty)
/* manual, speed */
data->pwm_enable[nr] = 3; data->pwm_enable[nr] = 3;
else if (!manu && duty) else if (!manu && !duty)
/* automatic */ /* automatic, speed */
data->pwm_enable[nr] = 2; data->pwm_enable[nr] = 2;
else else
/* manual */ /* manual, pwm */
data->pwm_enable[nr] = 1; data->pwm_enable[nr] = 1;
} else { } else {
if (!(conf & (1 << F75375_FAN_CTRL_LINEAR(nr)))) if (!(conf & (1 << F75375_FAN_CTRL_LINEAR(nr))))
...@@ -758,9 +817,11 @@ static void f75375_init(struct i2c_client *client, struct f75375_data *data, ...@@ -758,9 +817,11 @@ 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, 0, f75375s_pdata->pwm_enable[0]);
set_pwm_enable_direct(client, 1, f75375s_pdata->pwm_enable[1]); set_pwm_enable_direct(client, 1, f75375s_pdata->pwm_enable[1]);
for (nr = 0; nr < 2; nr++) { 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); data->pwm[nr] = SENSORS_LIMIT(f75375s_pdata->pwm[nr], 0, 255);
f75375_write8(client, F75375_REG_FAN_PWM_DUTY(nr), f75375_write_pwm(client, nr);
data->pwm[nr]);
} }
} }
...@@ -787,7 +848,7 @@ static int f75375_probe(struct i2c_client *client, ...@@ -787,7 +848,7 @@ static int f75375_probe(struct i2c_client *client,
if (err) if (err)
goto exit_free; goto exit_free;
if (data->kind == f75375) { if (data->kind != f75373) {
err = sysfs_chmod_file(&client->dev.kobj, err = sysfs_chmod_file(&client->dev.kobj,
&sensor_dev_attr_pwm1_mode.dev_attr.attr, &sensor_dev_attr_pwm1_mode.dev_attr.attr,
S_IRUGO | S_IWUSR); S_IRUGO | S_IWUSR);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment