Re: [PATCH] thermal: samsung: acpm-tmu: Fix spurious CPU throttling

From: Tudor Ambarus

Date: Wed Nov 18 2026 - 09:01:28 EST




On 11/18/26 3:28 PM, Tudor Ambarus wrote:
> Would something along the lines work?

Thinking more about it, caching the window instead of the raw
thresholds is simpler and closer to your v1, as inten derives from
low/high anyway. Maybe this:

diff --git a/drivers/thermal/samsung/acpm-tmu.c b/drivers/thermal/samsung/acpm-tmu.c
index 7c30401f8fc7..8422a7c970e7 100644
--- a/drivers/thermal/samsung/acpm-tmu.c
+++ b/drivers/thermal/samsung/acpm-tmu.c
@@ -39,6 +39,10 @@

#define GS101_REG_INTPEND(i) ((i) * 0x50 + 0xf8)

+#define ACPM_TMU_NUM_THRESHOLDS 8
+/* Threshold 7 throttles the CPUs in hardware, regardless of the INTEN mask. */
+#define ACPM_TMU_HW_TRIP_THRESHOLD 7
+
enum {
P0_INTPEND,
P1_INTPEND,
@@ -70,6 +74,9 @@ struct acpm_tmu_sensor {
struct acpm_tmu_priv *priv;
struct mutex lock; /* protects sensor state */
enum thermal_device_mode mode;
+ /* Last programmed window, protected by the thermal zone lock */
+ int low;
+ int high;
bool enabled;
};

@@ -228,7 +235,8 @@ static int acpm_tmu_get_temp(struct thermal_zone_device *tz, int *temp)
}

static int acpm_tmu_update_thresholds(struct acpm_tmu_sensor *sensor,
- u8 thresholds[2], u8 inten)
+ u8 thresholds[ACPM_TMU_NUM_THRESHOLDS],
+ u8 inten)
{
struct acpm_tmu_priv *priv = sensor->priv;
struct acpm_handle *handle = priv->handle;
@@ -249,7 +257,7 @@ static int acpm_tmu_update_thresholds(struct acpm_tmu_sensor *sensor,
}

ret = ops->set_threshold(handle, mbox_chan_id, acpm_sensor_id,
- thresholds, 2);
+ thresholds, ACPM_TMU_NUM_THRESHOLDS);
if (!ret) {
ret = ops->set_interrupt_enable(handle, mbox_chan_id,
acpm_sensor_id, inten);
@@ -267,12 +275,22 @@ static int acpm_tmu_update_thresholds(struct acpm_tmu_sensor *sensor,
return ret;
}

-static int acpm_tmu_set_trips(struct thermal_zone_device *tz, int low, int high)
+static int acpm_tmu_get_crit_temp(struct thermal_trip *trip, void *arg)
{
- struct acpm_tmu_sensor *sensor = thermal_zone_device_priv(tz);
- struct acpm_tmu_priv *priv = sensor->priv;
- struct device *dev = priv->dev;
- u8 thresholds[2] = {};
+ int *temp = arg;
+
+ if (trip->type == THERMAL_TRIP_CRITICAL &&
+ trip->temperature != THERMAL_TEMP_INVALID)
+ *temp = min(*temp, trip->temperature);
+
+ return 0;
+}
+
+static int acpm_tmu_program_thresholds(struct acpm_tmu_sensor *sensor,
+ int low, int high, int crit)
+{
+ struct device *dev = sensor->priv->dev;
+ u8 thresholds[ACPM_TMU_NUM_THRESHOLDS] = {};
u8 inten = 0;
int ret;

@@ -288,17 +306,61 @@ static int acpm_tmu_set_trips(struct thermal_zone_device *tz, int low, int high)
inten |= BIT(1);
}

+ /*
+ * The firmware programs all thresholds at once. Set the hardware trip
+ * to the critical trip temperature, so that it never fires below the
+ * point where the thermal core shuts the system down.
+ */
+ thresholds[ACPM_TMU_HW_TRIP_THRESHOLD] =
+ clamp_val(crit / MILLIDEGREE_PER_DEGREE, 0, 255);
+
ret = pm_runtime_resume_and_get(dev);
if (ret)
return ret;

ret = acpm_tmu_update_thresholds(sensor, thresholds, inten);
+ if (!ret) {
+ sensor->low = low;
+ sensor->high = high;
+ }

pm_runtime_put_autosuspend(dev);

return ret;
}

+static int acpm_tmu_set_trips(struct thermal_zone_device *tz, int low, int high)
+{
+ struct acpm_tmu_sensor *sensor = thermal_zone_device_priv(tz);
+ int crit = INT_MAX;
+
+ /*
+ * Use the lowest critical trip temperature. If the zone has no
+ * critical trip, crit stays INT_MAX and is clamped to the highest
+ * threshold value.
+ */
+ for_each_thermal_trip(tz, acpm_tmu_get_crit_temp, &crit);
+
+ return acpm_tmu_program_thresholds(sensor, low, high, crit);
+}
+
+static int acpm_tmu_set_trip_temp(struct thermal_zone_device *tz,
+ const struct thermal_trip *trip, int temp)
+{
+ struct acpm_tmu_sensor *sensor = thermal_zone_device_priv(tz);
+
+ if (trip->type != THERMAL_TRIP_CRITICAL)
+ return 0;
+
+ /*
+ * The thermal core skips .set_trips() when the low/high window does
+ * not change, so update the hardware trip threshold here, keeping the
+ * last programmed window.
+ */
+ return acpm_tmu_program_thresholds(sensor, sensor->low, sensor->high,
+ temp);
+}
+
static int acpm_tmu_change_mode(struct thermal_zone_device *tz,
enum thermal_device_mode mode)
{
@@ -329,6 +391,7 @@ static const struct thermal_zone_device_ops acpm_tmu_sensor_ops = {
.change_mode = acpm_tmu_change_mode,
.get_temp = acpm_tmu_get_temp,
.set_trips = acpm_tmu_set_trips,
+ .set_trip_temp = acpm_tmu_set_trip_temp,
};

static bool acpm_tmu_clear_pending_irq(struct acpm_tmu_sensor *sensor)
@@ -479,6 +542,8 @@ static int acpm_tmu_probe(struct platform_device *pdev)
mutex_init(&sensor->lock);
sensor->group = &data->sensor_groups[i];
sensor->priv = priv;
+ sensor->low = -INT_MAX;
+ sensor->high = INT_MAX;

tzd = devm_thermal_of_zone_register(dev, i, sensor,
&acpm_tmu_sensor_ops);