hwmon: (max31760) Fix local limits, standby and the initial fan speed
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]>
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.
--- drivers/hwmon/max31760.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hwmon/max31760.c +2 -2
@@ -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
[email protected]
AI reviewRe: [PATCH 1/3] hwmon: (max31760) Fix the local temperature limit registers
Sashiko has reviewed this patch and found no issues.
Quoted 9 lines
temp2_maxandtemp2_crituse each other's registers, so reading them shows the local limits swapped and writingtemp2_maxchanges the overtemperature (SHDN) threshold.Use the high limit (
0x0C) fortemp2_maxand the overtemperature limit (0x08) fortemp2_crit.Fixes 38b04ad02d0d ("drivers: hwmon: Add max31760 fan speed controller driver")Signed-off-by Stanislav Aleksandrov <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH 1/3] hwmon: (max31760) Fix the local temperature limit registers
In reply to Stanislav AleksandrovQuoted 9 lines · Stanislav Aleksandrov
temp2_maxandtemp2_crituse each other's registers, so reading them shows the local limits swapped and writingtemp2_maxchanges the overtemperature (SHDN) threshold.Use the high limit (
0x0C) fortemp2_maxand the overtemperature limit (0x08) fortemp2_crit.Fixes 38b04ad02d0d ("drivers: hwmon: Add max31760 fan speed controller driver")Signed-off-by Stanislav Aleksandrov <[email protected]>
Applied.
Thanks,
Guenter
Quoted 19 lines
--- drivers/hwmon/max31760.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/hwmon/max31760.c +2
-2@@ -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, \
PATCH 2/3 hwmon: (max31760) Leave standby mode at probe
In reply to Stanislav AleksandrovThe 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.
--- drivers/hwmon/max31760.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/hwmon/max31760.c +3 -2
@@ -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
[email protected]
AI reviewRe: [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. Whilemax31760_resume()clears this bit on resume, probe only configuredCR2_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_STBYalongside settingCR2_ALERTSin probe.Fixes 38b04ad02d0d ("drivers: hwmon: Add max31760 fan speed controller driver")Signed-off-by Stanislav Aleksandrov <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH 2/3] hwmon: (max31760) Leave standby mode at probe
In reply to Stanislav AleksandrovQuoted 10 lines · Stanislav Aleksandrov
The driver never clears the standby bit (
CR2_STBY) during probe. Whilemax31760_resume()clears this bit on resume, probe only configuredCR2_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_STBYalongside settingCR2_ALERTSin probe.Fixes 38b04ad02d0d ("drivers: hwmon: Add max31760 fan speed controller driver")Signed-off-by Stanislav Aleksandrov <[email protected]>
Applied.
Thanks,
Guenter
Quoted 20 lines
--- drivers/hwmon/max31760.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/hwmon/max31760.c +3
-2@@ -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" );
PATCH 3/3 hwmon: (max31760) Report 0 RPM before the first fan speed measurement
In reply to Stanislav AleksandrovThe 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.
--- drivers/hwmon/max31760.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/hwmon/max31760.c +2 -1
@@ -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
[email protected]
AI reviewRe: [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")Signed-off-by Stanislav Aleksandrov <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Re: [PATCH 3/3] hwmon: (max31760) Report 0 RPM before the first fan speed measurement
In reply to Stanislav AleksandrovQuoted 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")Signed-off-by Stanislav Aleksandrov <[email protected]>
Applied.
Thanks,
Guenter
Quoted 19 lines
--- drivers/hwmon/max31760.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/hwmon/max31760.c +2
-1@@ -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 ; }