[PATCH] max31785: Fix fan configuration at probe and runtime

Andrew Jeffery andrew at aj.id.au
Fri Jul 21 14:00:31 AEST 2017


Several issues regarding configuration were present:

1. Failure to probe if MFR_FAN_CONFIG was non-zero
2. Failure to configure DUAL_TACH mode in MFR_FAN_CONFIG
3. Failure to configure RPM or PWM mode on attribute writes

Combined these prevented fanX_input attributes reporting expected
values for the second rotors.

Signed-off-by: Andrew Jeffery <andrew at aj.id.au>
---
 drivers/hwmon/max31785.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/drivers/hwmon/max31785.c b/drivers/hwmon/max31785.c
index 4c858c5234c6..011354df587d 100644
--- a/drivers/hwmon/max31785.c
+++ b/drivers/hwmon/max31785.c
@@ -297,6 +297,11 @@ static ssize_t max31785_fan_set_target(struct max31785 *data, int channel,
 
 	mutex_lock(&data->lock);
 
+	data->fan_config[channel] |= MAX31785_FAN_CFG_CONTROL_MODE_RPM;
+	rc = max31785_write_fan_byte(data->client, channel,
+				MAX31785_REG_FAN_CONFIG_1_2,
+				data->fan_config[channel]);
+
 	/* Write new RPM value */
 	data->fan_command[channel] = rpm;
 	rc = max31785_write_fan_word(data->client, channel,
@@ -342,6 +347,11 @@ static ssize_t max31785_pwm_set(struct max31785 *data, int channel, long pwm)
 
 	mutex_lock(&data->lock);
 
+	data->fan_config[channel] &= ~MAX31785_FAN_CFG_CONTROL_MODE_RPM;
+	rc = max31785_write_fan_byte(data->client, channel,
+				MAX31785_REG_FAN_CONFIG_1_2,
+				data->fan_config[channel]);
+
 	/* Write new PWM value */
 	data->fan_command[channel] = pwm * MAX31785_FAN_COMMAND_PWM_RATIO;
 	rc = max31785_write_fan_word(data->client, channel,
@@ -458,7 +468,7 @@ static int max31785_init_fans(struct max31785 *data)
 		}
 	}
 
-	return rv;
+	return 0;
 }
 
 /* Return 0 if detection is successful, -ENODEV otherwise */
@@ -840,14 +850,14 @@ static int max31785_probe(struct i2c_client *client,
 	if (rc)
 		return rc;
 
-	rc = max31785_init_fans(data);
-	if (rc)
-		return rc;
-
 	rc = max31785_get_capabilities(data);
 	if (rc < 0)
 		return rc;
 
+	rc = max31785_init_fans(data);
+	if (rc)
+		return rc;
+
 	if (max31785_has_dual_rotor(data))
 		chip = &max31785_chip_info_0x3040;
 	else
-- 
2.11.0



More information about the openbmc mailing list