Commit c8469441 authored by Linus Torvalds's avatar Linus Torvalds

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

Pull hwmon fixes from Jean Delvare.

* 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jdelvare/staging:
  hwmon: Prevent some divide by zeros in FAN_TO_REG()
  hwmon: (w83l768ng) Fix fan speed control range
  hwmon: (w83l786ng) Fix fan speed control mode setting and reporting
  hwmon: (lm90) Unregister hwmon device if interrupt setup fails
parents 11ec50ca 3806b45b
...@@ -94,6 +94,8 @@ static inline u8 FAN_TO_REG(long rpm, int div) ...@@ -94,6 +94,8 @@ static inline u8 FAN_TO_REG(long rpm, int div)
{ {
if (rpm <= 0) if (rpm <= 0)
return 255; return 255;
if (rpm > 1350000)
return 1;
return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254); return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
} }
......
...@@ -1610,12 +1610,14 @@ static int lm90_probe(struct i2c_client *client, ...@@ -1610,12 +1610,14 @@ static int lm90_probe(struct i2c_client *client,
"lm90", client); "lm90", client);
if (err < 0) { if (err < 0) {
dev_err(dev, "cannot request IRQ %d\n", client->irq); dev_err(dev, "cannot request IRQ %d\n", client->irq);
goto exit_remove_files; goto exit_unregister;
} }
} }
return 0; return 0;
exit_unregister:
hwmon_device_unregister(data->hwmon_dev);
exit_remove_files: exit_remove_files:
lm90_remove_files(client, data); lm90_remove_files(client, data);
exit_restore: exit_restore:
......
...@@ -141,6 +141,8 @@ static inline u8 FAN_TO_REG(long rpm, int div) ...@@ -141,6 +141,8 @@ static inline u8 FAN_TO_REG(long rpm, int div)
{ {
if (rpm <= 0) if (rpm <= 0)
return 255; return 255;
if (rpm > 1350000)
return 1;
return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254); return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
} }
......
...@@ -145,7 +145,7 @@ static const u8 regtempmin[] = { 0x3a, 0x3e, 0x2c, 0x2e, 0x30, 0x32 }; ...@@ -145,7 +145,7 @@ static const u8 regtempmin[] = { 0x3a, 0x3e, 0x2c, 0x2e, 0x30, 0x32 };
*/ */
static inline u8 FAN_TO_REG(long rpm, int div) static inline u8 FAN_TO_REG(long rpm, int div)
{ {
if (rpm == 0) if (rpm <= 0 || rpm > 1310720)
return 0; return 0;
return clamp_val(1310720 / (rpm * div), 1, 255); return clamp_val(1310720 / (rpm * div), 1, 255);
} }
......
...@@ -481,9 +481,11 @@ store_pwm(struct device *dev, struct device_attribute *attr, ...@@ -481,9 +481,11 @@ store_pwm(struct device *dev, struct device_attribute *attr,
if (err) if (err)
return err; return err;
val = clamp_val(val, 0, 255); val = clamp_val(val, 0, 255);
val = DIV_ROUND_CLOSEST(val, 0x11);
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
data->pwm[nr] = val; data->pwm[nr] = val * 0x11;
val |= w83l786ng_read_value(client, W83L786NG_REG_PWM[nr]) & 0xf0;
w83l786ng_write_value(client, W83L786NG_REG_PWM[nr], val); w83l786ng_write_value(client, W83L786NG_REG_PWM[nr], val);
mutex_unlock(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
...@@ -510,7 +512,7 @@ store_pwm_enable(struct device *dev, struct device_attribute *attr, ...@@ -510,7 +512,7 @@ store_pwm_enable(struct device *dev, struct device_attribute *attr,
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
reg = w83l786ng_read_value(client, W83L786NG_REG_FAN_CFG); reg = w83l786ng_read_value(client, W83L786NG_REG_FAN_CFG);
data->pwm_enable[nr] = val; data->pwm_enable[nr] = val;
reg &= ~(0x02 << W83L786NG_PWM_ENABLE_SHIFT[nr]); reg &= ~(0x03 << W83L786NG_PWM_ENABLE_SHIFT[nr]);
reg |= (val - 1) << W83L786NG_PWM_ENABLE_SHIFT[nr]; reg |= (val - 1) << W83L786NG_PWM_ENABLE_SHIFT[nr];
w83l786ng_write_value(client, W83L786NG_REG_FAN_CFG, reg); w83l786ng_write_value(client, W83L786NG_REG_FAN_CFG, reg);
mutex_unlock(&data->update_lock); mutex_unlock(&data->update_lock);
...@@ -776,9 +778,10 @@ static struct w83l786ng_data *w83l786ng_update_device(struct device *dev) ...@@ -776,9 +778,10 @@ static struct w83l786ng_data *w83l786ng_update_device(struct device *dev)
((pwmcfg >> W83L786NG_PWM_MODE_SHIFT[i]) & 1) ((pwmcfg >> W83L786NG_PWM_MODE_SHIFT[i]) & 1)
? 0 : 1; ? 0 : 1;
data->pwm_enable[i] = data->pwm_enable[i] =
((pwmcfg >> W83L786NG_PWM_ENABLE_SHIFT[i]) & 2) + 1; ((pwmcfg >> W83L786NG_PWM_ENABLE_SHIFT[i]) & 3) + 1;
data->pwm[i] = w83l786ng_read_value(client, data->pwm[i] =
W83L786NG_REG_PWM[i]); (w83l786ng_read_value(client, W83L786NG_REG_PWM[i])
& 0x0f) * 0x11;
} }
......
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