Skip to contentSkip to conversation

hwmon: (max31760) Fix local limits, standby and the initial fan speed

PATCH Applied Stanislav Aleksandrov 3 participants 10 messages Nov 8 Hardware monitoring

lore
Share & tools
lore
#0 lore raw

cover hwmon: (max31760) Fix local limits, standby and the initial fan speed

Three fixes for the MAX31760 driver, found while bringing up the Samsung Galaxy XR on mainline. The headset uses the chip for its two cooling fans.

1. The local temperature max and crit limits are swapped.
2. Probe never clears the standby bit. The Galaxy XR bootloader leaves the chip in standby, so the driver gets no temperature or fan speed readings and can't control the fans.
3. The fan speed reads 3000000 RPM before the first measurement.

The patches were written with the help of an AI coding assistant (Claude Code), based on the datasheet and tests on the device. I reviewed them and tested them on the Galaxy XR.

---
Stanislav Aleksandrov (3):
hwmon: (max31760) Fix the local temperature limit registers
hwmon: (max31760) Leave standby mode at probe
hwmon: (max31760) Report 0 RPM before the first fan speed measurement

 drivers/hwmon/max31760.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

---
base-commit: f4e680ffc2e50867c5b590e26a37f8801a31e486
change-id: 20261108-max31760-fixes-0af187603717

Best regards,

Signature · 1 line
Stanislav Aleksandrov <[email protected]>
#1 lore raw

PATCH 1/3 hwmon: (max31760) Fix the local temperature limit registers

temp2_max and temp2_crit use each other's registers, so reading them shows the local limits swapped and writing temp2_max changes the overtemperature (SHDN) threshold.

Use the high limit (0x0C) for temp2_max and the overtemperature limit (0x08) for temp2_crit.

Fixes 38b04ad02d0d ("drivers: hwmon: Add max31760 fan speed controller driver")
---
 drivers/hwmon/max31760.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hwmon/max31760.c +2 -2
index 8d3be064b025..e3d86dc4257e 100644
@@ -27,8 +27,8 @@
 
 #define REG_TACH(ch)		(0x52 + (ch) * 2)
 #define REG_TEMP_INPUT(ch)	(0x56 + (ch) * 2)
-#define REG_TEMP_MAX(ch)	(0x06 + (ch) * 2)
-#define REG_TEMP_CRIT(ch)	(0x0A + (ch) * 2)
+#define REG_TEMP_MAX(ch)	((ch) ? 0x0C : 0x06)
+#define REG_TEMP_CRIT(ch)	((ch) ? 0x08 : 0x0A)
 
 #define TEMP11_FROM_REG(reg)	((reg) / 32 * 125)
 #define TEMP11_TO_REG(val)	(DIV_ROUND_CLOSEST(clamp_val((val), -128000, \
Signature · 1 line
2.55.0
#2 lore raw

Re: [PATCH 1/3] hwmon: (max31760) Fix the local temperature limit registers

Sashiko has reviewed this patch and found no issues.
Quoted 9 lines

temp2_max and temp2_crit use each other's registers, so reading them shows the local limits swapped and writing temp2_max changes the overtemperature (SHDN) threshold.

Use the high limit (0x0C) for temp2_max and the overtemperature limit (0x08) for temp2_crit.

Fixes 38b04ad02d0d ("drivers: hwmon: Add max31760 fan speed controller driver")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer Applied
#3 lore raw

Re: [PATCH 1/3] hwmon: (max31760) Fix the local temperature limit registers

In reply to Stanislav Aleksandrov
Quoted 9 lines · Stanislav Aleksandrov

temp2_max and temp2_crit use each other's registers, so reading them shows the local limits swapped and writing temp2_max changes the overtemperature (SHDN) threshold.

Use the high limit (0x0C) for temp2_max and the overtemperature limit (0x08) for temp2_crit.

Fixes 38b04ad02d0d ("drivers: hwmon: Add max31760 fan speed controller driver")

Applied.

Thanks,
Guenter

Quoted 19 lines
---
 drivers/hwmon/max31760.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hwmon/max31760.c +2 -2
index 8d3be064b025..e3d86dc4257e 100644
@@ -27,8 +27,8 @@
 
 #define REG_TACH(ch)		(0x52 + (ch) * 2)
 #define REG_TEMP_INPUT(ch)	(0x56 + (ch) * 2)
-#define REG_TEMP_MAX(ch)	(0x06 + (ch) * 2)
-#define REG_TEMP_CRIT(ch)	(0x0A + (ch) * 2)
+#define REG_TEMP_MAX(ch)	((ch) ? 0x0C : 0x06)
+#define REG_TEMP_CRIT(ch)	((ch) ? 0x08 : 0x0A)
 
 #define TEMP11_FROM_REG(reg)	((reg) / 32 * 125)
 #define TEMP11_TO_REG(val)	(DIV_ROUND_CLOSEST(clamp_val((val), -128000, \
#4 lore raw

PATCH 2/3 hwmon: (max31760) Leave standby mode at probe

In reply to Stanislav Aleksandrov

The driver never clears the standby bit (CR2_STBY) during probe. While max31760_resume() clears this bit on resume, probe only configured CR2_ALERTS.

If the chip was left in standby (for example, by boot firmware or a previously running OS before a warm reboot), it remains in standby:
temperature sensing, fan speed counting, and PWM output are halted. This occurs on the Samsung Galaxy XR, where the bootloader places the chip in standby during boot.

Clear CR2_STBY alongside setting CR2_ALERTS in probe.

Fixes 38b04ad02d0d ("drivers: hwmon: Add max31760 fan speed controller driver")
---
 drivers/hwmon/max31760.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/hwmon/max31760.c +3 -2
index e3d86dc4257e..e967555a21af 100644
@@ -533,8 +533,9 @@ static int max31760_probe(struct i2c_client *client)
 
 	dev_set_drvdata(dev, state);
 
-	/* Set alert output to comparator mode */
-	ret = regmap_set_bits(state->regmap, REG_CR2, CR2_ALERTS);
+	/* Leave standby mode, set alert output to comparator mode */
+	ret = regmap_update_bits(state->regmap, REG_CR2, CR2_STBY | CR2_ALERTS,
+				 CR2_ALERTS);
 	if (ret)
 		return dev_err_probe(dev, ret, "cannot write register\n");
 
Signature · 1 line
2.55.0
#5 lore raw

Re: [PATCH 2/3] hwmon: (max31760) Leave standby mode at probe

Sashiko has reviewed this patch and found no issues.
Quoted 10 lines

The driver never clears the standby bit (CR2_STBY) during probe. While max31760_resume() clears this bit on resume, probe only configured CR2_ALERTS.

If the chip was left in standby (for example, by boot firmware or a previously running OS before a warm reboot), it remains in standby:
temperature sensing, fan speed counting, and PWM output are halted. This occurs on the Samsung Galaxy XR, where the bootloader places the chip in standby during boot.

Quoted 4 lines

Clear CR2_STBY alongside setting CR2_ALERTS in probe.

Fixes 38b04ad02d0d ("drivers: hwmon: Add max31760 fan speed controller driver")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
maintainer Applied
#6 lore raw

Re: [PATCH 2/3] hwmon: (max31760) Leave standby mode at probe

In reply to Stanislav Aleksandrov
Quoted 10 lines · Stanislav Aleksandrov

The driver never clears the standby bit (CR2_STBY) during probe. While max31760_resume() clears this bit on resume, probe only configured CR2_ALERTS.

If the chip was left in standby (for example, by boot firmware or a previously running OS before a warm reboot), it remains in standby:
temperature sensing, fan speed counting, and PWM output are halted. This occurs on the Samsung Galaxy XR, where the bootloader places the chip in standby during boot.

Quoted 4 lines

Clear CR2_STBY alongside setting CR2_ALERTS in probe.

Fixes 38b04ad02d0d ("drivers: hwmon: Add max31760 fan speed controller driver")

Applied.

Thanks,
Guenter

Quoted 20 lines
---
 drivers/hwmon/max31760.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/hwmon/max31760.c +3 -2
index e3d86dc4257e..e967555a21af 100644
@@ -533,8 +533,9 @@ static int max31760_probe(struct i2c_client *client)
 
 	dev_set_drvdata(dev, state);
 
-	/* Set alert output to comparator mode */
-	ret = regmap_set_bits(state->regmap, REG_CR2, CR2_ALERTS);
+	/* Leave standby mode, set alert output to comparator mode */
+	ret = regmap_update_bits(state->regmap, REG_CR2, CR2_STBY | CR2_ALERTS,
+				 CR2_ALERTS);
 	if (ret)
 		return dev_err_probe(dev, ret, "cannot write register\n");
 
#7 lore raw

PATCH 3/3 hwmon: (max31760) Report 0 RPM before the first fan speed measurement

In reply to Stanislav Aleksandrov

The tachometer count registers initialize to 0 until the first measurement cycle completes after power-on. To prevent division by zero, tach_to_rpm() clamped tach == 0 to 1, causing it to compute and report 3,000,000 RPM (60 * 100000 / 1 / 2).

Return 0 RPM when tach == 0 instead.

Fixes 38b04ad02d0d ("drivers: hwmon: Add max31760 fan speed controller driver")
---
 drivers/hwmon/max31760.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/hwmon/max31760.c +2 -1
index e967555a21af..896bd0326b8c 100644
@@ -68,8 +68,9 @@ static const int max31760_pwm_freq[] = {33, 150, 1500, 25000};
 
 static int tach_to_rpm(u16 tach)
 {
+	/* The count is 0 until the first measurement */
 	if (tach == 0)
-		tach = 1;
+		return 0;
 
 	return 60 * 100000 / tach / 2;
 }
Signature · 1 line
2.55.0
#8 lore raw

Re: [PATCH 3/3] hwmon: (max31760) Report 0 RPM before the first fan speed measurement

Sashiko has reviewed this patch and found no issues.
Quoted 9 lines

The tachometer count registers initialize to 0 until the first measurement cycle completes after power-on. To prevent division by zero, tach_to_rpm() clamped tach == 0 to 1, causing it to compute and report 3,000,000 RPM (60 * 100000 / 1 / 2).

Return 0 RPM when tach == 0 instead.

Fixes 38b04ad02d0d ("drivers: hwmon: Add max31760 fan speed controller driver")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
maintainer Applied
#9 lore raw

Re: [PATCH 3/3] hwmon: (max31760) Report 0 RPM before the first fan speed measurement

In reply to Stanislav Aleksandrov
Quoted 9 lines · Stanislav Aleksandrov

The tachometer count registers initialize to 0 until the first measurement cycle completes after power-on. To prevent division by zero, tach_to_rpm() clamped tach == 0 to 1, causing it to compute and report 3,000,000 RPM (60 * 100000 / 1 / 2).

Return 0 RPM when tach == 0 instead.

Fixes 38b04ad02d0d ("drivers: hwmon: Add max31760 fan speed controller driver")

Applied.

Thanks,
Guenter

Quoted 19 lines
---
 drivers/hwmon/max31760.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/hwmon/max31760.c +2 -1
index e967555a21af..896bd0326b8c 100644
@@ -68,8 +68,9 @@ static const int max31760_pwm_freq[] = {33, 150, 1500, 25000};
 
 static int tach_to_rpm(u16 tach)
 {
+	/* The count is 0 until the first measurement */
 	if (tach == 0)
-		tach = 1;
+		return 0;
 
 	return 60 * 100000 / tach / 2;
 }