hwmon: (w83795) Fix fan control mode
Subsystems (2)
PATCH 1/7 hwmon: (w83795) Fix fan control mode
There were two bugs:
* Speed cruise mode was improperly reported for all fans but fan1.
* Fan control method (PWM vs. DC) was mixed with the control mode. It will be added back as a separate attribute, as per the standard sysfs interface.
--- w83795.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)
drivers/hwmon/w83795.c +8 -10
@@ -857,20 +857,20 @@ show_pwm_enable(struct device *dev, struint index = sensor_attr->index;u8 tmp; - if (1 = (data->pwm_fcms[0] & (1 << index))) { +/* Speed cruise mode */ +if (data->pwm_fcms[0 ] & (1 << index)) { tmp =2 ; goto out; } +/* Thermal cruise or SmartFan IV mode */ for (tmp =0 ; tmp <6 ; tmp++) {if (data->pwm_tfmr[tmp] & (1 << index)) { tmp =3 ; goto out; } } -if (data->pwm_fomc & (1 << index)) - tmp =0 ; -else - tmp =1 ; +/* Manual mode */ + tmp =1 ; out:return sprintf (buf,"%u\n" , tmp);
@@ -890,23 +890,21 @@ store_pwm_enable(struct device *dev, strif (strict_strtoul (buf,10 , &val) <0 )return -EINVAL ; -if (val >2 ) +if (val <1 || val >2 )return -EINVAL ;mutex_lock (&data->update_lock);switch (val) { -case 0 :case 1 : +/* Clear speed cruise mode bits */ data->pwm_fcms[0 ] &= ~(1 << index);w83795_write (client,W83795_REG_FCMS1 , data->pwm_fcms[0 ]); +/* Clear thermal cruise mode bits */ for (i =0 ; i <6 ; i++) { data->pwm_tfmr[i] &= ~(1 << index);w83795_write (client,W83795_REG_TFMR (i), data->pwm_tfmr[i]); } - data->pwm_fomc |=1 << index; - data->pwm_fomc ^= val << index; -w83795_write (client,W83795_REG_FOMC , data->pwm_fomc);break ;case 2 : data->pwm_fcms[0 ] |= (1 << index);
Signature · 6 lines
Jean Delvare _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Quoted 7 lines · Jean Delvare
There were two bugs:
* Speed cruise mode was improperly reported for all fans but fan1.
* Fan control method (PWM vs. DC) was mixed with the control mode. It will be added back as a separate attribute, as per the standard sysfs interface.Signed-off-by Jean Delvare <[email protected]>
Couple of questions below. If as intended,
Quoted 10 lines
--- w83795.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)drivers/hwmon/w83795.c +0
-0@@ -857,20 +857,20 @@ show_pwm_enable(struct device *dev, struint index = sensor_attr->index;u8 tmp;
drivers/hwmon/w83795.c show_pwm_enable(struct device *dev, stru · line 868
Quoted 10 lines
drivers/hwmon/w83795.c +3
-1- if (1 = (data->pwm_fcms[0] & (1 << index))) { +/* Speed cruise mode */ +if (data->pwm_fcms[0 ] & (1 << index)) { tmp =2 ; goto out; } +/* Thermal cruise or SmartFan IV mode */ for (tmp =0 ; tmp <6 ; tmp++) {if (data->pwm_tfmr[tmp] & (1 << index)) { tmp =3 ;
That means return values are 1, 2, or 3, but never 0 (= full speed per ABI). On the setting side, you only support 1 and 2, but not 3 or 0.
Is that as intended ?
drivers/hwmon/w83795.c show_pwm_enable(struct device *dev, stru · line 874
Quoted 10 lines
drivers/hwmon/w83795.c +2
-4goto out; } } -if (data->pwm_fomc & (1 << index)) - tmp =0 ; -else - tmp =1 ; +/* Manual mode */ + tmp =1 ;
What if (pwm_fomc & (1<<index)) is set from the bios ? Doesn't that state get lost now ?
Quoted 37 lines
drivers/hwmon/w83795.c +3
-5out:return sprintf (buf,"%u\n" , tmp);@@ -890,23 +890,21 @@ store_pwm_enable(struct device *dev, strif (strict_strtoul (buf,10 , &val) <0 )return -EINVAL ; -if (val >2 ) +if (val <1 || val >2 )return -EINVAL ;mutex_lock (&data->update_lock);switch (val) { -case 0 :case 1 : +/* Clear speed cruise mode bits */ data->pwm_fcms[0 ] &= ~(1 << index);w83795_write (client,W83795_REG_FCMS1 , data->pwm_fcms[0 ]); +/* Clear thermal cruise mode bits */ for (i =0 ; i <6 ; i++) { data->pwm_tfmr[i] &= ~(1 << index);w83795_write (client,W83795_REG_TFMR (i), data->pwm_tfmr[i]); } - data->pwm_fomc |=1 << index; - data->pwm_fomc ^= val << index; -w83795_write (client,W83795_REG_FOMC , data->pwm_fomc);break ;case 2 : data->pwm_fcms[0 ] |= (1 << index);Signature · 7 lines
-- Jean Delvare _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Hi Guenter,
Thanks for the quick reviews!
Quoted 23 lines · Guenter Roeck
Quoted 7 lines · Jean Delvare
There were two bugs:
* Speed cruise mode was improperly reported for all fans but fan1.
* Fan control method (PWM vs. DC) was mixed with the control mode. It will be added back as a separate attribute, as per the standard sysfs interface.Signed-off-by Jean Delvare <[email protected]>Couple of questions below. If as intended,
Acked-by Guenter Roeck <[email protected]>Quoted 10 lines
--- w83795.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)drivers/hwmon/w83795.c +0
-0@@ -857,20 +857,20 @@ show_pwm_enable(struct device *dev, struint index = sensor_attr->index;u8 tmp;
Quoted 12 lines
drivers/hwmon/w83795.c show_pwm_enable(struct device *dev, stru · line 868
Quoted 10 lines
drivers/hwmon/w83795.c +3
-1- if (1 = (data->pwm_fcms[0] & (1 << index))) { +/* Speed cruise mode */ +if (data->pwm_fcms[0 ] & (1 << index)) { tmp =2 ; goto out; } +/* Thermal cruise or SmartFan IV mode */ for (tmp =0 ; tmp <6 ; tmp++) {if (data->pwm_tfmr[tmp] & (1 << index)) { tmp =3 ;That means return values are 1, 2, or 3, but never 0 (= full speed per ABI).
Yes. The device doesn't support mode 0, so the driver can't return it, ever.
Quoted 3 lines
On the setting side, you only support 1 and 2, but not 3 or 0.
Is that as intended ?
Not supporting 0 is completely intended, the device doesn't support that mode so the driver can't implement it.
Not supporting 3 isn't a limitation introduced by my patch, the code already didn't support setting mode to 3. And I'm not sure if we can ever support setting it directly. It is not trivial at all. The device doesn't allow setting a given PWM output to mode 3 (temperature-controlled) directly. Instead, it lets you configure temperature channels for automatic fan speed control, and a given PWM output is considered to be in mode 3 if any temperature channel has this PWM output listed as a target. In fact, the device treats manual control as a degraded variant of temperature-based automatic control (when temperature source count is zero.)
I need to look more into the details, but I suspect the code is OK as is, and setting mode 3 has to be done indirectly, by writing to the pwm/temp mapping files.
We could allow setting mode 3 directly if we remembered which temperature channels were used as sources last time mode was 3. However I'm not sure if this is desirable, for 2 reasons. First reason, this won't work if mode isn't set to 3 when the driver gets loaded. Second reason, the source temperatures are indirect as well, there is a look-up table involved, and a change to this table while a given PWM output isn't in mode 3 would mean that we will restore settings which have a different meaning when PWM mode is set back to 3.
The temperature-based fan speed control part of this device is really complex and very hard to make fit into our sysfs interface, which is why it currently doesn't. I really don't know how I'll solve this problem.
Quoted 4 lines
Quoted 4 lines
drivers/hwmon/w83795.c +0
-1goto out; } } -if (data->pwm_fomc & (1 << index))
Quoted 8 lines
drivers/hwmon/w83795.c show_pwm_enable(struct device *dev, stru · line 874
Quoted 6 lines
drivers/hwmon/w83795.c +2
-3- tmp =0 ; - else - tmp =1 ; +/* Manual mode */ + tmp =1 ;What if (
pwm_fomc& (1<<index)) is set from the bios ? Doesn't that state get lost now ?
Patch 2/7 hopefully answered this question ;)
Quoted 29 lines
Quoted 29 lines
drivers/hwmon/w83795.c +3
-5out:return sprintf (buf,"%u\n" , tmp);@@ -890,23 +890,21 @@ store_pwm_enable(struct device *dev, strif (strict_strtoul (buf,10 , &val) <0 )return -EINVAL ; -if (val >2 ) +if (val <1 || val >2 )return -EINVAL ;mutex_lock (&data->update_lock);switch (val) { -case 0 :case 1 : +/* Clear speed cruise mode bits */ data->pwm_fcms[0 ] &= ~(1 << index);w83795_write (client,W83795_REG_FCMS1 , data->pwm_fcms[0 ]); +/* Clear thermal cruise mode bits */ for (i =0 ; i <6 ; i++) { data->pwm_tfmr[i] &= ~(1 << index);w83795_write (client,W83795_REG_TFMR (i), data->pwm_tfmr[i]); } - data->pwm_fomc |=1 << index; - data->pwm_fomc ^= val << index; -w83795_write (client,W83795_REG_FOMC , data->pwm_fomc);break ;case 2 : data->pwm_fcms[0 ] |= (1 << index);
Signature · 6 lines
Jean Delvare _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors