]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
hwmon: (max31790) Clear fan fault after reporting it
authorGuenter Roeck <linux@roeck-us.net>
Wed, 26 May 2021 15:40:20 +0000 (08:40 -0700)
committerGuenter Roeck <linux@roeck-us.net>
Thu, 17 Jun 2021 11:21:46 +0000 (04:21 -0700)
Fault bits in MAX31790 are sticky and have to be cleared explicitly.
A write operation into either the 'Target Duty Cycle' register or the
'Target Count' register is necessary to clear a fault.

At the same time, we can never clear cached fault status values before
reading them because the companion fault status for any given fan is
cleared as well when clearing a fault.

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>
Tested-by: Václav Kubernát <kubernat@cesnet.cz>
Link: https://lore.kernel.org/r/20210526154022.3223012-6-linux@roeck-us.net
drivers/hwmon/max31790.c

index 67677c43776879721e1149ed8e04799ebac83f26..7927468c527158c45fc9aabcaeca8c8100fc0575 100644 (file)
@@ -80,7 +80,7 @@ static struct max31790_data *max31790_update_device(struct device *dev)
                                MAX31790_REG_FAN_FAULT_STATUS1);
                if (rv < 0)
                        goto abort;
-               data->fault_status = rv & 0x3F;
+               data->fault_status |= rv & 0x3F;
 
                rv = i2c_smbus_read_byte_data(client,
                                MAX31790_REG_FAN_FAULT_STATUS2);
@@ -181,7 +181,21 @@ static int max31790_read_fan(struct device *dev, u32 attr, int channel,
                *val = rpm;
                return 0;
        case hwmon_fan_fault:
+               mutex_lock(&data->update_lock);
                *val = !!(data->fault_status & (1 << channel));
+               data->fault_status &= ~(1 << channel);
+               /*
+                * If a fault bit is set, we need to write into one of the fan
+                * configuration registers to clear it. Note that this also
+                * clears the fault for the companion channel if enabled.
+                */
+               if (*val) {
+                       int reg = MAX31790_REG_TARGET_COUNT(channel % NR_CHANNEL);
+
+                       i2c_smbus_write_byte_data(data->client, reg,
+                                                 data->target_count[channel % NR_CHANNEL] >> 8);
+               }
+               mutex_unlock(&data->update_lock);
                return 0;
        default:
                return -EOPNOTSUPP;