* [PATCH 0/3] hwmon: (max31760) Fix local limits, standby and the initial fan speed
@ 2026-11-08 3:59 Stanislav Aleksandrov
2026-11-08 3:59 ` [PATCH 1/3] hwmon: (max31760) Fix the local temperature limit registers Stanislav Aleksandrov
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Stanislav Aleksandrov @ 2026-11-08 3:59 UTC (permalink / raw)
To: Guenter Roeck
Cc: Nurettin Bolucu, linux-hwmon, linux-kernel, Stanislav Aleksandrov
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,
--
Stanislav Aleksandrov <lightofmysoul@gmail.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/3] hwmon: (max31760) Fix the local temperature limit registers
2026-11-08 3:59 [PATCH 0/3] hwmon: (max31760) Fix local limits, standby and the initial fan speed Stanislav Aleksandrov
@ 2026-11-08 3:59 ` Stanislav Aleksandrov
2026-11-08 15:53 ` Guenter Roeck
2026-11-08 3:59 ` [PATCH 2/3] hwmon: (max31760) Leave standby mode at probe Stanislav Aleksandrov
2026-11-08 3:59 ` [PATCH 3/3] hwmon: (max31760) Report 0 RPM before the first fan speed measurement Stanislav Aleksandrov
2 siblings, 1 reply; 7+ messages in thread
From: Stanislav Aleksandrov @ 2026-11-08 3:59 UTC (permalink / raw)
To: Guenter Roeck
Cc: Nurettin Bolucu, linux-hwmon, linux-kernel, 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")
Signed-off-by: Stanislav Aleksandrov <lightofmysoul@gmail.com>
---
drivers/hwmon/max31760.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/hwmon/max31760.c b/drivers/hwmon/max31760.c
index 8d3be064b025..e3d86dc4257e 100644
--- a/drivers/hwmon/max31760.c
+++ b/drivers/hwmon/max31760.c
@@ -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, \
--
2.55.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/3] hwmon: (max31760) Leave standby mode at probe
2026-11-08 3:59 [PATCH 0/3] hwmon: (max31760) Fix local limits, standby and the initial fan speed Stanislav Aleksandrov
2026-11-08 3:59 ` [PATCH 1/3] hwmon: (max31760) Fix the local temperature limit registers Stanislav Aleksandrov
@ 2026-11-08 3:59 ` Stanislav Aleksandrov
2026-11-08 15:54 ` Guenter Roeck
2026-11-08 3:59 ` [PATCH 3/3] hwmon: (max31760) Report 0 RPM before the first fan speed measurement Stanislav Aleksandrov
2 siblings, 1 reply; 7+ messages in thread
From: Stanislav Aleksandrov @ 2026-11-08 3:59 UTC (permalink / raw)
To: Guenter Roeck
Cc: Nurettin Bolucu, linux-hwmon, linux-kernel, 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")
Signed-off-by: Stanislav Aleksandrov <lightofmysoul@gmail.com>
---
drivers/hwmon/max31760.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/hwmon/max31760.c b/drivers/hwmon/max31760.c
index e3d86dc4257e..e967555a21af 100644
--- a/drivers/hwmon/max31760.c
+++ b/drivers/hwmon/max31760.c
@@ -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");
--
2.55.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 3/3] hwmon: (max31760) Report 0 RPM before the first fan speed measurement
2026-11-08 3:59 [PATCH 0/3] hwmon: (max31760) Fix local limits, standby and the initial fan speed Stanislav Aleksandrov
2026-11-08 3:59 ` [PATCH 1/3] hwmon: (max31760) Fix the local temperature limit registers Stanislav Aleksandrov
2026-11-08 3:59 ` [PATCH 2/3] hwmon: (max31760) Leave standby mode at probe Stanislav Aleksandrov
@ 2026-11-08 3:59 ` Stanislav Aleksandrov
2026-11-08 15:55 ` Guenter Roeck
2 siblings, 1 reply; 7+ messages in thread
From: Stanislav Aleksandrov @ 2026-11-08 3:59 UTC (permalink / raw)
To: Guenter Roeck
Cc: Nurettin Bolucu, linux-hwmon, linux-kernel, 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 <lightofmysoul@gmail.com>
---
drivers/hwmon/max31760.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/hwmon/max31760.c b/drivers/hwmon/max31760.c
index e967555a21af..896bd0326b8c 100644
--- a/drivers/hwmon/max31760.c
+++ b/drivers/hwmon/max31760.c
@@ -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;
}
--
2.55.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/3] hwmon: (max31760) Fix the local temperature limit registers
2026-11-08 3:59 ` [PATCH 1/3] hwmon: (max31760) Fix the local temperature limit registers Stanislav Aleksandrov
@ 2026-11-08 15:53 ` Guenter Roeck
0 siblings, 0 replies; 7+ messages in thread
From: Guenter Roeck @ 2026-11-08 15:53 UTC (permalink / raw)
To: Stanislav Aleksandrov; +Cc: Nurettin Bolucu, linux-hwmon, linux-kernel
On Sun, Nov 08, 2026 at 03:59:53AM +0000, Stanislav Aleksandrov wrote:
> 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")
> Signed-off-by: Stanislav Aleksandrov <lightofmysoul@gmail.com>
Applied.
Thanks,
Guenter
> ---
> drivers/hwmon/max31760.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/hwmon/max31760.c b/drivers/hwmon/max31760.c
> index 8d3be064b025..e3d86dc4257e 100644
> --- a/drivers/hwmon/max31760.c
> +++ b/drivers/hwmon/max31760.c
> @@ -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, \
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/3] hwmon: (max31760) Leave standby mode at probe
2026-11-08 3:59 ` [PATCH 2/3] hwmon: (max31760) Leave standby mode at probe Stanislav Aleksandrov
@ 2026-11-08 15:54 ` Guenter Roeck
0 siblings, 0 replies; 7+ messages in thread
From: Guenter Roeck @ 2026-11-08 15:54 UTC (permalink / raw)
To: Stanislav Aleksandrov; +Cc: Nurettin Bolucu, linux-hwmon, linux-kernel
On Sun, Nov 08, 2026 at 03:59:54AM +0000, Stanislav Aleksandrov wrote:
> 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")
> Signed-off-by: Stanislav Aleksandrov <lightofmysoul@gmail.com>
Applied.
Thanks,
Guenter
> ---
> drivers/hwmon/max31760.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/hwmon/max31760.c b/drivers/hwmon/max31760.c
> index e3d86dc4257e..e967555a21af 100644
> --- a/drivers/hwmon/max31760.c
> +++ b/drivers/hwmon/max31760.c
> @@ -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");
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 3/3] hwmon: (max31760) Report 0 RPM before the first fan speed measurement
2026-11-08 3:59 ` [PATCH 3/3] hwmon: (max31760) Report 0 RPM before the first fan speed measurement Stanislav Aleksandrov
@ 2026-11-08 15:55 ` Guenter Roeck
0 siblings, 0 replies; 7+ messages in thread
From: Guenter Roeck @ 2026-11-08 15:55 UTC (permalink / raw)
To: Stanislav Aleksandrov; +Cc: Nurettin Bolucu, linux-hwmon, linux-kernel
On Sun, Nov 08, 2026 at 03:59:55AM +0000, Stanislav Aleksandrov wrote:
> 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 <lightofmysoul@gmail.com>
Applied.
Thanks,
Guenter
> ---
> drivers/hwmon/max31760.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/hwmon/max31760.c b/drivers/hwmon/max31760.c
> index e967555a21af..896bd0326b8c 100644
> --- a/drivers/hwmon/max31760.c
> +++ b/drivers/hwmon/max31760.c
> @@ -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;
> }
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-11-08 15:56 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-08 3:59 [PATCH 0/3] hwmon: (max31760) Fix local limits, standby and the initial fan speed Stanislav Aleksandrov
2026-11-08 3:59 ` [PATCH 1/3] hwmon: (max31760) Fix the local temperature limit registers Stanislav Aleksandrov
2026-11-08 15:53 ` Guenter Roeck
2026-11-08 3:59 ` [PATCH 2/3] hwmon: (max31760) Leave standby mode at probe Stanislav Aleksandrov
2026-11-08 15:54 ` Guenter Roeck
2026-11-08 3:59 ` [PATCH 3/3] hwmon: (max31760) Report 0 RPM before the first fan speed measurement Stanislav Aleksandrov
2026-11-08 15:55 ` Guenter Roeck
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®