* [PATCH] thermal: samsung: acpm-tmu: Fix spurious CPU throttling
@ 2026-11-17 8:34 Christian Loehle
2026-11-17 15:37 ` Tudor Ambarus
0 siblings, 1 reply; 6+ messages in thread
From: Christian Loehle @ 2026-11-17 8:34 UTC (permalink / raw)
To: tudor.ambarus, bzolnier
Cc: krzk, rafael, daniel.lezcano, lukasz.luba, linux-kernel,
linux-samsung-soc, linux-pm, Christian Loehle
acpm_tmu_set_trips() supplies two thresholds, but the ACPM command
writes all eight slots, zero-filling the rest. On GS101, slot 7
controls autonomous CPU throttling even when its interrupt is masked.
Programming it to 0 C limits all three CPU clusters to about 200 MHz
on Pixel 6, while cpufreq continues to report the requested
frequencies.
Program slot 7 from the zone's critical trip before enabling the
sensor and preserve it when updating the low/high interrupt window.
Cache the three temperatures so a writable critical trip can update
the hardware without changing that window.
Reject critical temperatures that cannot be represented by the
firmware's unsigned degree-Celsius byte.
Fixes: 50a2c5d4062a ("thermal/drivers/samsung: Add Exynos ACPM TMU driver GS101")
Signed-off-by: Christian Loehle <christian.loehle@arm.com>
---
drivers/thermal/samsung/acpm-tmu.c | 62 ++++++++++++++++++++++++++----
1 file changed, 55 insertions(+), 7 deletions(-)
diff --git a/drivers/thermal/samsung/acpm-tmu.c b/drivers/thermal/samsung/acpm-tmu.c
index b86dfa3c3ddb..1d8076f91fe7 100644
--- a/drivers/thermal/samsung/acpm-tmu.c
+++ b/drivers/thermal/samsung/acpm-tmu.c
@@ -37,6 +37,8 @@
EXYNOS_TMU_SENSOR(2))
#define GS101_REG_INTPEND(i) ((i) * 0x50 + 0xf8)
+#define GS101_TMU_THRESHOLD_COUNT 8
+#define GS101_TMU_CRITICAL_THRESHOLD 7
enum {
P0_INTPEND,
@@ -68,6 +70,9 @@ struct acpm_tmu_sensor {
struct thermal_zone_device *tzd;
struct acpm_tmu_priv *priv;
struct mutex lock; /* protects sensor state */
+ int low;
+ int high;
+ int critical;
bool enabled;
};
@@ -250,7 +255,7 @@ 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[GS101_TMU_THRESHOLD_COUNT], u8 inten)
{
struct acpm_tmu_priv *priv = sensor->priv;
struct acpm_handle *handle = priv->handle;
@@ -260,7 +265,7 @@ static int acpm_tmu_update_thresholds(struct acpm_tmu_sensor *sensor,
bool was_enabled;
int ret, restore_ret;
- guard(mutex)(&sensor->lock);
+ lockdep_assert_held(&sensor->lock);
was_enabled = sensor->enabled;
@@ -271,7 +276,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, GS101_TMU_THRESHOLD_COUNT);
if (!ret) {
ret = ops->set_interrupt_enable(handle, mbox_chan_id,
acpm_sensor_id, inten);
@@ -289,15 +294,21 @@ 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_set_thresholds(struct acpm_tmu_sensor *sensor,
+ int low, int high, int critical)
{
- 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] = {};
+ u8 thresholds[GS101_TMU_THRESHOLD_COUNT] = {};
u8 inten = 0;
int ret;
+ if (critical < 0 || critical > 255 * MILLIDEGREE_PER_DEGREE)
+ return -EINVAL;
+
+ /* Slot 7 throttles CPU clocks independently of the interrupt mask. */
+ thresholds[GS101_TMU_CRITICAL_THRESHOLD] = critical / MILLIDEGREE_PER_DEGREE;
+
/* If a valid lower bound exists, set the threshold and enable its interrupt */
if (low > -INT_MAX) {
thresholds[0] = clamp_val(low / MILLIDEGREE_PER_DEGREE, 0, 255);
@@ -315,15 +326,43 @@ static int acpm_tmu_set_trips(struct thermal_zone_device *tz, int low, int high)
return ret;
ret = acpm_tmu_update_thresholds(sensor, thresholds, inten);
+ if (!ret) {
+ sensor->low = low;
+ sensor->high = high;
+ sensor->critical = critical;
+ }
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);
+
+ guard(mutex)(&sensor->lock);
+
+ return acpm_tmu_set_thresholds(sensor, low, high, sensor->critical);
+}
+
+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;
+
+ guard(mutex)(&sensor->lock);
+
+ return acpm_tmu_set_thresholds(sensor, sensor->low, sensor->high, temp);
+}
+
static const struct thermal_zone_device_ops acpm_tmu_sensor_ops = {
.get_temp = acpm_tmu_get_temp,
.set_trips = acpm_tmu_set_trips,
+ .set_trip_temp = acpm_tmu_set_trip_temp,
};
static int acpm_tmu_has_pending_irq(struct acpm_tmu_sensor *sensor,
@@ -469,6 +508,7 @@ static int acpm_tmu_probe(struct platform_device *pdev)
for (i = 0; i < priv->num_sensors; i++) {
struct acpm_tmu_sensor *sensor = &priv->sensors[i];
+ int critical;
mutex_init(&sensor->lock);
sensor->group = &data->sensor_groups[i];
@@ -488,8 +528,16 @@ static int acpm_tmu_probe(struct platform_device *pdev)
goto err_rollback;
}
+ ret = thermal_zone_get_crit_temp(sensor->tzd, &critical);
+ if (ret) {
+ ret = dev_err_probe(dev, ret, "Sensor %d has no critical trip\n", i);
+ goto err_rollback;
+ }
+
mutex_lock(&sensor->lock);
- ret = acpm_tmu_op_tz_control(sensor, true);
+ ret = acpm_tmu_set_thresholds(sensor, -INT_MAX, INT_MAX, critical);
+ if (!ret)
+ ret = acpm_tmu_op_tz_control(sensor, true);
mutex_unlock(&sensor->lock);
if (ret) {
ret = dev_err_probe(dev, ret, "Failed to enable sensor %d\n", i);
--
2.34.1
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] thermal: samsung: acpm-tmu: Fix spurious CPU throttling 2026-11-17 8:34 [PATCH] thermal: samsung: acpm-tmu: Fix spurious CPU throttling Christian Loehle @ 2026-11-17 15:37 ` Tudor Ambarus 2026-11-17 16:41 ` Christian Loehle 0 siblings, 1 reply; 6+ messages in thread From: Tudor Ambarus @ 2026-11-17 15:37 UTC (permalink / raw) To: Christian Loehle, bzolnier Cc: krzk, rafael, daniel.lezcano, lukasz.luba, linux-kernel, linux-samsung-soc, linux-pm, Juan Yescas Hi, Christian, Thanks for the patch! On 11/17/26 10:34 AM, Christian Loehle wrote: > acpm_tmu_set_trips() supplies two thresholds, but the ACPM command > writes all eight slots, zero-filling the rest. On GS101, slot 7 > controls autonomous CPU throttling even when its interrupt is masked. > Programming it to 0 C limits all three CPU clusters to about 200 MHz > on Pixel 6, while cpufreq continues to report the requested > frequencies. Could you share how you discovered this? I don't have access to the ACPM firmware sources, and the downstream driver doesn't state it either. How did you measure the actual CPU frequency, given that cpufreq keeps reporting the requested one? Do you know whether slots 2-6 have any side effects as well? Also note that Daniel has already queued a set of acpm-tmu fixes in thermal/linux-next, so this patch will need to be reworked on top of them. > > Program slot 7 from the zone's critical trip before enabling the > sensor and preserve it when updating the low/high interrupt window. > Cache the three temperatures so a writable critical trip can update > the hardware without changing that window. I think this can be handled with a smaller change: look up the critical trip in .set_trips() itself. The zone lock is held there, so for_each_thermal_trip() can be used. That avoids caching low/high/critical, the .set_trip_temp() callback and the probe changes. Cheers, ta ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] thermal: samsung: acpm-tmu: Fix spurious CPU throttling 2026-11-17 15:37 ` Tudor Ambarus @ 2026-11-17 16:41 ` Christian Loehle 2026-11-18 12:06 ` Christian Loehle 0 siblings, 1 reply; 6+ messages in thread From: Christian Loehle @ 2026-11-17 16:41 UTC (permalink / raw) To: Tudor Ambarus, bzolnier Cc: krzk, rafael, daniel.lezcano, lukasz.luba, linux-kernel, linux-samsung-soc, linux-pm, Juan Yescas On 11/17/26 15:37, Tudor Ambarus wrote: > Hi, Christian, > > Thanks for the patch! > > On 11/17/26 10:34 AM, Christian Loehle wrote: >> acpm_tmu_set_trips() supplies two thresholds, but the ACPM command >> writes all eight slots, zero-filling the rest. On GS101, slot 7 >> controls autonomous CPU throttling even when its interrupt is masked. >> Programming it to 0 C limits all three CPU clusters to about 200 MHz >> on Pixel 6, while cpufreq continues to report the requested >> frequencies. > > Could you share how you discovered this? I don't have access to the > ACPM firmware sources, and the downstream driver doesn't state it > either. Neither do I, I discovered this randomly through running regression tests on Energy-Aware Scheduling on the Pixel6 and acpm-tmu (7.4-rc1) causes a massive energy regression (+~1000%) for the same workloads. The reason is this DVFS throttling. > > How did you measure the actual CPU frequency, given that cpufreq > keeps reporting the requested one? PMU counters CPU_CYCLES > > Do you know whether slots 2-6 have any side effects as well? I hadn't discovered any. > > Also note that Daniel has already queued a set of acpm-tmu fixes in > thermal/linux-next, so this patch will need to be reworked on top of > them. will rebase then! > >> >> Program slot 7 from the zone's critical trip before enabling the >> sensor and preserve it when updating the low/high interrupt window. >> Cache the three temperatures so a writable critical trip can update >> the hardware without changing that window. > > I think this can be handled with a smaller change: look up the > critical trip in .set_trips() itself. The zone lock is held there, so > for_each_thermal_trip() can be used. That avoids caching > low/high/critical, the .set_trip_temp() callback and the probe changes. Ah yep you're right, will fix and resend. Thanks! ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] thermal: samsung: acpm-tmu: Fix spurious CPU throttling 2026-11-17 16:41 ` Christian Loehle @ 2026-11-18 12:06 ` Christian Loehle 2026-11-18 13:28 ` Tudor Ambarus 0 siblings, 1 reply; 6+ messages in thread From: Christian Loehle @ 2026-11-18 12:06 UTC (permalink / raw) To: Tudor Ambarus, bzolnier Cc: krzk, rafael, daniel.lezcano, lukasz.luba, linux-kernel, linux-samsung-soc, linux-pm, Juan Yescas On 11/17/26 16:41, Christian Loehle wrote: > On 11/17/26 15:37, Tudor Ambarus wrote: >> Hi, Christian, >> >> Thanks for the patch! >> >> On 11/17/26 10:34 AM, Christian Loehle wrote: >>> acpm_tmu_set_trips() supplies two thresholds, but the ACPM command >>> writes all eight slots, zero-filling the rest. On GS101, slot 7 >>> controls autonomous CPU throttling even when its interrupt is masked. >>> Programming it to 0 C limits all three CPU clusters to about 200 MHz >>> on Pixel 6, while cpufreq continues to report the requested >>> frequencies. >> >> Could you share how you discovered this? I don't have access to the >> ACPM firmware sources, and the downstream driver doesn't state it >> either. > > Neither do I, I discovered this randomly through running regression tests > on Energy-Aware Scheduling on the Pixel6 and acpm-tmu (7.4-rc1) causes a > massive energy regression (+~1000%) for the same workloads. > The reason is this DVFS throttling. > >> >> How did you measure the actual CPU frequency, given that cpufreq >> keeps reporting the requested one? > > PMU counters CPU_CYCLES > >> >> Do you know whether slots 2-6 have any side effects as well? > > I hadn't discovered any. > >> >> Also note that Daniel has already queued a set of acpm-tmu fixes in >> thermal/linux-next, so this patch will need to be reworked on top of >> them. > > will rebase then! > >> >>> >>> Program slot 7 from the zone's critical trip before enabling the >>> sensor and preserve it when updating the low/high interrupt window. >>> Cache the three temperatures so a writable critical trip can update >>> the hardware without changing that window. >> >> I think this can be handled with a smaller change: look up the >> critical trip in .set_trips() itself. The zone lock is held there, so >> for_each_thermal_trip() can be used. That avoids caching >> low/high/critical, the .set_trip_temp() callback and the probe changes. > > Ah yep you're right, will fix and resend. > Thanks! Okay, maybe I'm missing something but AFAICS we have to do the set_trip_temp because thermal core looks only at min/max and may skip set_trips() in case these are unchanged, missing a critical update. So the minimal I see working is making 'critical' (again, this is my interpretation of the value, if you want it named anything else, just shoot) non-writable by failing it's set_trip_temp()? Or is there another way? ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] thermal: samsung: acpm-tmu: Fix spurious CPU throttling 2026-11-18 12:06 ` Christian Loehle @ 2026-11-18 13:28 ` Tudor Ambarus 2026-11-18 14:01 ` Tudor Ambarus 0 siblings, 1 reply; 6+ messages in thread From: Tudor Ambarus @ 2026-11-18 13:28 UTC (permalink / raw) To: Christian Loehle, bzolnier, Daniel Lezcano Cc: krzk, rafael, lukasz.luba, linux-kernel, linux-samsung-soc, linux-pm, Juan Yescas On 11/18/26 2:06 PM, Christian Loehle wrote: > On 11/17/26 16:41, Christian Loehle wrote: >> On 11/17/26 15:37, Tudor Ambarus wrote: >>> Hi, Christian, >>> >>> Thanks for the patch! >>> >>> On 11/17/26 10:34 AM, Christian Loehle wrote: >>>> acpm_tmu_set_trips() supplies two thresholds, but the ACPM command >>>> writes all eight slots, zero-filling the rest. On GS101, slot 7 >>>> controls autonomous CPU throttling even when its interrupt is masked. >>>> Programming it to 0 C limits all three CPU clusters to about 200 MHz >>>> on Pixel 6, while cpufreq continues to report the requested >>>> frequencies. >>> >>> Could you share how you discovered this? I don't have access to the >>> ACPM firmware sources, and the downstream driver doesn't state it >>> either. >> >> Neither do I, I discovered this randomly through running regression tests >> on Energy-Aware Scheduling on the Pixel6 and acpm-tmu (7.4-rc1) causes a >> massive energy regression (+~1000%) for the same workloads. >> The reason is this DVFS throttling. >> >>> >>> How did you measure the actual CPU frequency, given that cpufreq >>> keeps reporting the requested one? >> >> PMU counters CPU_CYCLES >> >>> >>> Do you know whether slots 2-6 have any side effects as well? >> >> I hadn't discovered any. >> >>> >>> Also note that Daniel has already queued a set of acpm-tmu fixes in >>> thermal/linux-next, so this patch will need to be reworked on top of >>> them. >> >> will rebase then! >> >>> >>>> >>>> Program slot 7 from the zone's critical trip before enabling the >>>> sensor and preserve it when updating the low/high interrupt window. >>>> Cache the three temperatures so a writable critical trip can update >>>> the hardware without changing that window. >>> >>> I think this can be handled with a smaller change: look up the >>> critical trip in .set_trips() itself. The zone lock is held there, so >>> for_each_thermal_trip() can be used. That avoids caching >>> low/high/critical, the .set_trip_temp() callback and the probe changes. >> >> Ah yep you're right, will fix and resend. >> Thanks! > > Okay, maybe I'm missing something but AFAICS we have to do the set_trip_temp > because thermal core looks only at min/max and may skip set_trips() in case ah, you're right! > these are unchanged, missing a critical update. > So the minimal I see working is making 'critical' (again, this is my > interpretation of the value, if you want it named anything else, just shoot) > non-writable by failing it's set_trip_temp()? > Or is there another way? While I like it, the problem is that the trip is writable in sysfs but always failing. An alternative is to touch the core and let OF drivers mark trips read-only but maybe this is not suitable for a quick fix. We need to involve Daniel. So I think your v1 approach of caching and updating the hardware from .set_trip_temp() is the right one after all. I'd just look up the critical trip in .set_trips() instead of caching it from probe, and cache the last programmed thresholds and interrupt mask. Would something along the lines work? diff --git a/drivers/thermal/samsung/acpm-tmu.c b/drivers/thermal/samsung/acpm-tmu.c index 7c30401f8fc7..b2e5b1f6641a 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 thresholds, protected by the thermal zone lock */ + u8 thresholds[ACPM_TMU_NUM_THRESHOLDS]; + u8 inten; 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,14 +275,56 @@ static int acpm_tmu_update_thresholds(struct acpm_tmu_sensor *sensor, return ret; } +static int acpm_tmu_get_crit_temp(struct thermal_trip *trip, void *arg) +{ + 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, + u8 thresholds[ACPM_TMU_NUM_THRESHOLDS], + u8 inten) +{ + struct device *dev = sensor->priv->dev; + int ret; + + ret = pm_runtime_resume_and_get(dev); + if (ret) + return ret; + + ret = acpm_tmu_update_thresholds(sensor, thresholds, inten); + if (!ret) { + memcpy(sensor->thresholds, thresholds, sizeof(sensor->thresholds)); + sensor->inten = inten; + } + + 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); - struct acpm_tmu_priv *priv = sensor->priv; - struct device *dev = priv->dev; - u8 thresholds[2] = {}; + u8 thresholds[ACPM_TMU_NUM_THRESHOLDS] = {}; + int crit = INT_MAX; u8 inten = 0; - int ret; + + /* + * The firmware programs all thresholds at once. Set the hardware trip + * to the lowest critical trip temperature, so that it never fires + * below the point where the thermal core shuts the system down. 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); + thresholds[ACPM_TMU_HW_TRIP_THRESHOLD] = + clamp_val(crit / MILLIDEGREE_PER_DEGREE, 0, 255); /* If a valid lower bound exists, set the threshold and enable its interrupt */ if (low > -INT_MAX) { @@ -288,15 +338,28 @@ static int acpm_tmu_set_trips(struct thermal_zone_device *tz, int low, int high) inten |= BIT(1); } - ret = pm_runtime_resume_and_get(dev); - if (ret) - return ret; + return acpm_tmu_program_thresholds(sensor, thresholds, inten); +} - ret = acpm_tmu_update_thresholds(sensor, thresholds, inten); +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); + u8 thresholds[ACPM_TMU_NUM_THRESHOLDS]; - pm_runtime_put_autosuspend(dev); + if (trip->type != THERMAL_TRIP_CRITICAL) + return 0; - return ret; + /* + * 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. + */ + memcpy(thresholds, sensor->thresholds, sizeof(thresholds)); + thresholds[ACPM_TMU_HW_TRIP_THRESHOLD] = + clamp_val(temp / MILLIDEGREE_PER_DEGREE, 0, 255); + + return acpm_tmu_program_thresholds(sensor, thresholds, sensor->inten); } static int acpm_tmu_change_mode(struct thermal_zone_device *tz, @@ -329,6 +392,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) ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] thermal: samsung: acpm-tmu: Fix spurious CPU throttling 2026-11-18 13:28 ` Tudor Ambarus @ 2026-11-18 14:01 ` Tudor Ambarus 0 siblings, 0 replies; 6+ messages in thread From: Tudor Ambarus @ 2026-11-18 14:01 UTC (permalink / raw) To: Christian Loehle, bzolnier, Daniel Lezcano Cc: krzk, rafael, lukasz.luba, linux-kernel, linux-samsung-soc, linux-pm, Juan Yescas 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); ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-18 14:01 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2026-11-17 8:34 [PATCH] thermal: samsung: acpm-tmu: Fix spurious CPU throttling Christian Loehle 2026-11-17 15:37 ` Tudor Ambarus 2026-11-17 16:41 ` Christian Loehle 2026-11-18 12:06 ` Christian Loehle 2026-11-18 13:28 ` Tudor Ambarus 2026-11-18 14:01 ` Tudor Ambarus
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®