Commit 778ffd75 authored by Guenter Roeck's avatar Guenter Roeck Committed by Khalid Elmously

hwmon: (nct6775) Fix writing pwmX_mode

BugLink: https://bugs.launchpad.net/bugs/1775771

[ Upstream commit 415eb2a1 ]

pwmX_mode is defined in the ABI as 0=DC mode, 1=pwm mode. The chip
register bit is set to 1 for DC mode. This got mixed up, and writing
1 into pwmX_mode resulted in DC mode enabled. Fix it up by using
the ABI definition throughout the driver for consistency.

Fixes: 77eb5b37 ("hwmon: (nct6775) Add support for pwm, pwm_mode, ... ")
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarJuerg Haefliger <juergh@canonical.com>
Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
parent 531733a4
...@@ -1390,7 +1390,7 @@ static void nct6775_update_pwm(struct device *dev) ...@@ -1390,7 +1390,7 @@ static void nct6775_update_pwm(struct device *dev)
duty_is_dc = data->REG_PWM_MODE[i] && duty_is_dc = data->REG_PWM_MODE[i] &&
(nct6775_read_value(data, data->REG_PWM_MODE[i]) (nct6775_read_value(data, data->REG_PWM_MODE[i])
& data->PWM_MODE_MASK[i]); & data->PWM_MODE_MASK[i]);
data->pwm_mode[i] = duty_is_dc; data->pwm_mode[i] = !duty_is_dc;
fanmodecfg = nct6775_read_value(data, data->REG_FAN_MODE[i]); fanmodecfg = nct6775_read_value(data, data->REG_FAN_MODE[i]);
for (j = 0; j < ARRAY_SIZE(data->REG_PWM); j++) { for (j = 0; j < ARRAY_SIZE(data->REG_PWM); j++) {
...@@ -2267,7 +2267,7 @@ show_pwm_mode(struct device *dev, struct device_attribute *attr, char *buf) ...@@ -2267,7 +2267,7 @@ show_pwm_mode(struct device *dev, struct device_attribute *attr, char *buf)
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);
return sprintf(buf, "%d\n", !data->pwm_mode[sattr->index]); return sprintf(buf, "%d\n", data->pwm_mode[sattr->index]);
} }
static ssize_t static ssize_t
...@@ -2288,9 +2288,9 @@ store_pwm_mode(struct device *dev, struct device_attribute *attr, ...@@ -2288,9 +2288,9 @@ store_pwm_mode(struct device *dev, struct device_attribute *attr,
if (val > 1) if (val > 1)
return -EINVAL; return -EINVAL;
/* Setting DC mode is not supported for all chips/channels */ /* Setting DC mode (0) is not supported for all chips/channels */
if (data->REG_PWM_MODE[nr] == 0) { if (data->REG_PWM_MODE[nr] == 0) {
if (val) if (!val)
return -EINVAL; return -EINVAL;
return count; return count;
} }
...@@ -2299,7 +2299,7 @@ store_pwm_mode(struct device *dev, struct device_attribute *attr, ...@@ -2299,7 +2299,7 @@ store_pwm_mode(struct device *dev, struct device_attribute *attr,
data->pwm_mode[nr] = val; data->pwm_mode[nr] = val;
reg = nct6775_read_value(data, data->REG_PWM_MODE[nr]); reg = nct6775_read_value(data, data->REG_PWM_MODE[nr]);
reg &= ~data->PWM_MODE_MASK[nr]; reg &= ~data->PWM_MODE_MASK[nr];
if (val) if (!val)
reg |= data->PWM_MODE_MASK[nr]; reg |= data->PWM_MODE_MASK[nr];
nct6775_write_value(data, data->REG_PWM_MODE[nr], reg); nct6775_write_value(data, data->REG_PWM_MODE[nr], reg);
mutex_unlock(&data->update_lock); mutex_unlock(&data->update_lock);
......
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