diff mbox series

[6/7] hwmon: (max31790) Detect and report zero fan speed

Message ID 20210526154022.3223012-7-linux@roeck-us.net (mailing list archive)
State Accepted
Headers show
Series hwmon: (max31790) Fixes and improvements | expand

Commit Message

Guenter Roeck May 26, 2021, 3:40 p.m. UTC
If a fan is not running or not connected, of if fan monitoring is disabled,
the fan count register returns a fixed value of 0xffe0. So far this is then
translated to a RPM value larger than 0. Since this is misleading and does
not really make much sense, report a fan RPM of 0 in this situation.

Cc: Jan Kundrát <jan.kundrat@cesnet.cz>
Cc: Václav Kubernát <kubernat@cesnet.cz>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/hwmon/max31790.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Václav Kubernát June 1, 2021, 8:11 a.m. UTC | #1
Zero fan speed is reported correctly.

Tested-by: Václav Kubernát <kubernat@cesnet.cz>

st 26. 5. 2021 v 17:41 odesílatel Guenter Roeck <linux@roeck-us.net> napsal:
>
> If a fan is not running or not connected, of if fan monitoring is disabled,
> the fan count register returns a fixed value of 0xffe0. So far this is then
> translated to a RPM value larger than 0. Since this is misleading and does
> not really make much sense, report a fan RPM of 0 in this situation.
>
> Cc: Jan Kundrát <jan.kundrat@cesnet.cz>
> Cc: Václav Kubernát <kubernat@cesnet.cz>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---
>  drivers/hwmon/max31790.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/hwmon/max31790.c b/drivers/hwmon/max31790.c
> index 8e4fd9b7c889..91fe419b596c 100644
> --- a/drivers/hwmon/max31790.c
> +++ b/drivers/hwmon/max31790.c
> @@ -40,6 +40,8 @@
>  #define FAN_RPM_MIN                    120
>  #define FAN_RPM_MAX                    7864320
>
> +#define FAN_COUNT_REG_MAX              0xffe0
> +
>  #define RPM_FROM_REG(reg, sr)          (((reg) >> 4) ? \
>                                          ((60 * (sr) * 8192) / ((reg) >> 4)) : \
>                                          FAN_RPM_MAX)
> @@ -175,7 +177,10 @@ static int max31790_read_fan(struct device *dev, u32 attr, int channel,
>                 return 0;
>         case hwmon_fan_input:
>                 sr = get_tach_period(data->fan_dynamics[channel % NR_CHANNEL]);
> -               rpm = RPM_FROM_REG(data->tach[channel], sr);
> +               if (data->tach[channel] == FAN_COUNT_REG_MAX)
> +                       rpm = 0;
> +               else
> +                       rpm = RPM_FROM_REG(data->tach[channel], sr);
>                 *val = rpm;
>                 return 0;
>         case hwmon_fan_target:
> --
> 2.25.1
>
diff mbox series

Patch

diff --git a/drivers/hwmon/max31790.c b/drivers/hwmon/max31790.c
index 8e4fd9b7c889..91fe419b596c 100644
--- a/drivers/hwmon/max31790.c
+++ b/drivers/hwmon/max31790.c
@@ -40,6 +40,8 @@ 
 #define FAN_RPM_MIN			120
 #define FAN_RPM_MAX			7864320
 
+#define FAN_COUNT_REG_MAX		0xffe0
+
 #define RPM_FROM_REG(reg, sr)		(((reg) >> 4) ? \
 					 ((60 * (sr) * 8192) / ((reg) >> 4)) : \
 					 FAN_RPM_MAX)
@@ -175,7 +177,10 @@  static int max31790_read_fan(struct device *dev, u32 attr, int channel,
 		return 0;
 	case hwmon_fan_input:
 		sr = get_tach_period(data->fan_dynamics[channel % NR_CHANNEL]);
-		rpm = RPM_FROM_REG(data->tach[channel], sr);
+		if (data->tach[channel] == FAN_COUNT_REG_MAX)
+			rpm = 0;
+		else
+			rpm = RPM_FROM_REG(data->tach[channel], sr);
 		*val = rpm;
 		return 0;
 	case hwmon_fan_target: