* [PATCH v2 0/3] thermal: samsung: acpm-tmu: Add Exynos850 support
@ 2026-11-18 13:51 Alexey Klimov
2026-11-18 13:51 ` [PATCH v2 1/3] dt-bindings: thermal: gs101-tmu: add Exynos850 compatible Alexey Klimov
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Alexey Klimov @ 2026-11-18 13:51 UTC (permalink / raw)
To: Daniel Lezcano, Tudor Ambarus, Rafael J. Wysocki, Zhang Rui,
Lukasz Luba, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Bartlomiej Zolnierkiewicz, Krzysztof Kozlowski
Cc: Mateusz Majewski, Thomas Turner, Peter Griffin, linux-pm,
linux-samsung-soc, devicetree, linux-kernel
This series adds support for the Thermal Management Unit found on
the Samsung Exynos850 SoC to the existing acpm-tmu driver.
The acpm-tmu driver was recently introduced to support a hybrid thermal
architecture where hardware management is shared between the kernel and
the ACPM firmware.
However, the distribution of responsibilities between the Application
Processor and the firmware varies depending on the SoC:
1. GS101 (Existing):
The ACPM firmware handles sensor initialization, threshold configuration,
and temperature reading via ACPM IPC. The kernel only uses MMIO to read
the interrupt pending registers.
2. Exynos850 (This series):
The firmware implements a much smaller subset of TMU IPC commands
(temperature readings, TMU suspend/resume, basic TMU init).
The driver should use direct MMIO register access to support the
remaining functionality.
In this series the patch 2/3 prepares the acpm-tmu driver by moving the
hardcoded GS101 IPC calls into SoC-specific callbacks: tz_control,
tmu_init, tmu_update_thresholds, and tmu_check_and_clear_irqs.
The patch 3/3 implements actual Exynos850 support.
Tested with:
tmu_top: thermal-sensor@100a0000 {
compatible = "samsung,exynos850-tmu-top";
reg = <0x10070000 0x800>;
interrupts = <GIC_SPI 226 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&cmu_peri CLK_GOUT_BUSIF_TMU_PCLK>;
samsung,acpm-ipc = <&acpm_ipc>;
#thermal-sensor-cells = <1>;
};
and corresponding thermal zones.
Signed-off-by: Alexey Klimov <alexey.klimov@linaro.org>
---
Changes in v2:
- rebased;
- reworked defines and hardcoded values a bit;
- removed efuse_value from acpm_tmu_sensor struct;
- regmap renamed to "exynos850_tmu_regs" from "e850_tmu_regs";
- checked ret value from regmap_read/update_bits calls;
- dev_err() -> dev_err_ratelimited() and return error if clearing
irq failed in exynos850_handle_irqs();
- exynos850_tmu_update_thresholds() tries to restore sensor state
if failed;
- Link to v1: https://lore.kernel.org/r/20260709-acpm-tmu-e850-support-v1-0-9fdd58b634af@linaro.org
---
Alexey Klimov (3):
dt-bindings: thermal: gs101-tmu: add Exynos850 compatible
thermal: samsung: acpm-tmu: refactor SoC-specific operations into driver data
thermal: samsung: acpm-tmu: add Exynos850 support
.../bindings/thermal/google,gs101-tmu-top.yaml | 26 +-
drivers/thermal/samsung/acpm-tmu.c | 588 ++++++++++++++++++++-
2 files changed, 577 insertions(+), 37 deletions(-)
---
base-commit: 7cfbf79c66c63e807ea452abf0546e6f6d6833a6
change-id: 20261118-acpm-tmu-e850-support-d10e9018719b
Best regards,
--
Alexey Klimov <alexey.klimov@linaro.org>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/3] dt-bindings: thermal: gs101-tmu: add Exynos850 compatible
2026-11-18 13:51 [PATCH v2 0/3] thermal: samsung: acpm-tmu: Add Exynos850 support Alexey Klimov
@ 2026-11-18 13:51 ` Alexey Klimov
2026-11-18 13:51 ` [PATCH v2 2/3] thermal: samsung: acpm-tmu: refactor SoC-specific operations into driver data Alexey Klimov
2026-11-18 13:51 ` [PATCH v2 3/3] thermal: samsung: acpm-tmu: add Exynos850 support Alexey Klimov
2 siblings, 0 replies; 5+ messages in thread
From: Alexey Klimov @ 2026-11-18 13:51 UTC (permalink / raw)
To: Daniel Lezcano, Tudor Ambarus, Rafael J. Wysocki, Zhang Rui,
Lukasz Luba, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Bartlomiej Zolnierkiewicz, Krzysztof Kozlowski
Cc: Mateusz Majewski, Thomas Turner, Peter Griffin, linux-pm,
linux-samsung-soc, devicetree, linux-kernel
Document the `samsung,exynos850-tmu-top` compatible string for the
Exynos850 SoC.
Unlike the GS101, where the ACPM firmware handles most of the TMU
initialization and threshold configuration, the Exynos850 firmware
implements a significantly smaller subset of TMU IPC commands.
Consequently, the Application Processor requires broader direct
MMIO access to initialize the thermal unit, configure thresholds,
clear interrupts and collect calibration data.
Acked-by: Rob Herring (Arm) <robh@kernel.org>
Signed-off-by: Alexey Klimov <alexey.klimov@linaro.org>
---
.../bindings/thermal/google,gs101-tmu-top.yaml | 26 +++++++++++++++-------
1 file changed, 18 insertions(+), 8 deletions(-)
diff --git a/Documentation/devicetree/bindings/thermal/google,gs101-tmu-top.yaml b/Documentation/devicetree/bindings/thermal/google,gs101-tmu-top.yaml
index 75560ebca48d..bea208cd4619 100644
--- a/Documentation/devicetree/bindings/thermal/google,gs101-tmu-top.yaml
+++ b/Documentation/devicetree/bindings/thermal/google,gs101-tmu-top.yaml
@@ -15,17 +15,27 @@ description:
both direct register-level access and firmware-mediated management
via the ACPM (Alive Clock and Power Manager) firmware.
- On these platforms, the hardware is managed in a hybrid fashion. The
- Application Processor (AP) maintains direct memory-mapped access
- exclusively to the interrupt pending registers to identify thermal
- events. All other functional aspects - including sensor
- initialization, threshold configuration, and temperature acquisition
- - are handled by the ACPM firmware. The AP coordinates these
- operations through the ACPM IPC protocol.
+ On these platforms, the hardware is managed in a hybrid fashion, though
+ the distribution of responsibilities between the Application Processor
+ (AP) and the ACPM firmware varies by SoC.
+
+ On the GS101, the AP maintains direct memory-mapped access exclusively
+ to the interrupt pending registers to identify thermal events. All other
+ functional aspects - including sensor initialization, threshold
+ configuration, and temperature acquisition - are handled by the ACPM
+ firmware. The AP coordinates these operations through the ACPM IPC protocol.
+
+ On the Exynos850, the ACPM firmware implements a smaller subset of TMU IPC
+ commands (mainly temperature querying, basic TMU initialization, and power
+ state management). Consequently, the AP is responsible for register-level
+ access to initialize the thermal unit, configure thresholds and handle
+ interrupts via MMIO.
properties:
compatible:
- const: google,gs101-tmu-top
+ enum:
+ - google,gs101-tmu-top
+ - samsung,exynos850-tmu-top
reg:
maxItems: 1
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 2/3] thermal: samsung: acpm-tmu: refactor SoC-specific operations into driver data
2026-11-18 13:51 [PATCH v2 0/3] thermal: samsung: acpm-tmu: Add Exynos850 support Alexey Klimov
2026-11-18 13:51 ` [PATCH v2 1/3] dt-bindings: thermal: gs101-tmu: add Exynos850 compatible Alexey Klimov
@ 2026-11-18 13:51 ` Alexey Klimov
2026-11-18 13:51 ` [PATCH v2 3/3] thermal: samsung: acpm-tmu: add Exynos850 support Alexey Klimov
2 siblings, 0 replies; 5+ messages in thread
From: Alexey Klimov @ 2026-11-18 13:51 UTC (permalink / raw)
To: Daniel Lezcano, Tudor Ambarus, Rafael J. Wysocki, Zhang Rui,
Lukasz Luba, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Bartlomiej Zolnierkiewicz, Krzysztof Kozlowski
Cc: Mateusz Majewski, Thomas Turner, Peter Griffin, linux-pm,
linux-samsung-soc, devicetree, linux-kernel
The current ACPM TMU driver assumes that all TMU operations (init,
threshold updates, and interrupt clearing) are handled exclusively
via ACPM IPC commands, which is true for the GS101.
However, other Exynos platforms (like Exynos850) lack complete firmware
support for these operations and require direct MMIO register access
instead for missing ACPM TMU IPC calls.
Prepare the driver for multi-SoC support by moving the hardcoded GS101
IPC calls into SoC-specific callbacks: "tz_control", "tmu_init",
"tmu_update_thresholds" and "tmu_check_and_clear_irqs" within the
acpm_tmu_driver_data struct. Additionally, save the regmap pointer in
the private structure so that these callbacks can utilize it for other
SoCs.
Signed-off-by: Alexey Klimov <alexey.klimov@linaro.org>
---
drivers/thermal/samsung/acpm-tmu.c | 113 +++++++++++++++++++++++++++----------
1 file changed, 82 insertions(+), 31 deletions(-)
diff --git a/drivers/thermal/samsung/acpm-tmu.c b/drivers/thermal/samsung/acpm-tmu.c
index 4799ef518a7a..0def0ec09084 100644
--- a/drivers/thermal/samsung/acpm-tmu.c
+++ b/drivers/thermal/samsung/acpm-tmu.c
@@ -74,6 +74,8 @@ struct acpm_tmu_sensor {
};
struct acpm_tmu_priv {
+ const struct acpm_tmu_driver_data *data;
+ struct regmap *regmap;
struct regmap_field *regmap_fields[REG_INTPEND_COUNT];
struct acpm_handle *handle;
struct device *dev;
@@ -86,9 +88,18 @@ struct acpm_tmu_priv {
struct acpm_tmu_driver_data {
const struct reg_field *reg_fields;
+ const struct regmap_config *regmap_config;
const struct acpm_tmu_sensor_group *sensor_groups;
unsigned int num_sensor_groups;
unsigned int mbox_chan_id;
+
+ /* SoC-specific TMU routines and values */
+ int (*tz_control)(struct acpm_tmu_sensor *sensor, bool on);
+ int (*tmu_check_and_clear_irqs)(struct acpm_tmu_sensor *sensor,
+ bool *pending_irq);
+ int (*tmu_init)(struct acpm_tmu_priv *priv);
+ int (*tmu_update_thresholds)(struct acpm_tmu_sensor *sensor,
+ u8 thresholds[2], u8 inten);
};
#define ACPM_TMU_SENSOR_GROUP(_mask, _id) \
@@ -131,24 +142,32 @@ static const struct regmap_config gs101_regmap_config = {
.max_register = GS101_REG_INTPEND(15),
};
-static const struct acpm_tmu_driver_data acpm_tmu_gs101 = {
- .reg_fields = gs101_reg_fields,
- .sensor_groups = gs101_sensor_groups,
- .num_sensor_groups = ARRAY_SIZE(gs101_sensor_groups),
- .mbox_chan_id = 9,
-};
+static int gs101_tz_control(struct acpm_tmu_sensor *sensor, bool on)
+{
+ struct acpm_tmu_priv *priv = sensor->priv;
+ struct acpm_handle *handle = priv->handle;
+
+ return handle->ops->tmu.tz_control(handle, priv->mbox_chan_id,
+ sensor->group->id, on);
+}
+
+static int gs101_tmu_init(struct acpm_tmu_priv *priv)
+{
+ struct acpm_handle *handle = priv->handle;
+
+ return handle->ops->tmu.init(handle, priv->mbox_chan_id);
+}
static int acpm_tmu_op_tz_control(struct acpm_tmu_sensor *sensor, bool on)
{
struct acpm_tmu_priv *priv = sensor->priv;
- struct acpm_handle *handle = priv->handle;
- const struct acpm_tmu_ops *ops = &handle->ops->tmu;
int ret;
- ret = ops->tz_control(handle, priv->mbox_chan_id, sensor->group->id,
- on);
- if (ret)
- return ret;
+ if (priv->data->tz_control) {
+ ret = priv->data->tz_control(sensor, on);
+ if (ret)
+ return ret;
+ }
WRITE_ONCE(sensor->enabled, on);
@@ -227,8 +246,8 @@ static int acpm_tmu_get_temp(struct thermal_zone_device *tz, int *temp)
return 0;
}
-static int acpm_tmu_update_thresholds(struct acpm_tmu_sensor *sensor,
- u8 thresholds[2], u8 inten)
+static int gs101_tmu_update_thresholds(struct acpm_tmu_sensor *sensor,
+ u8 thresholds[2], u8 inten)
{
struct acpm_tmu_priv *priv = sensor->priv;
struct acpm_handle *handle = priv->handle;
@@ -292,7 +311,8 @@ static int acpm_tmu_set_trips(struct thermal_zone_device *tz, int low, int high)
if (ret)
return ret;
- ret = acpm_tmu_update_thresholds(sensor, thresholds, inten);
+ if (priv->data->tmu_update_thresholds)
+ ret = priv->data->tmu_update_thresholds(sensor, thresholds, inten);
pm_runtime_put_autosuspend(dev);
@@ -331,12 +351,12 @@ static const struct thermal_zone_device_ops acpm_tmu_sensor_ops = {
.set_trips = acpm_tmu_set_trips,
};
-static bool acpm_tmu_clear_pending_irq(struct acpm_tmu_sensor *sensor)
+static int gs101_handle_irqs(struct acpm_tmu_sensor *sensor, bool *pending_irq)
{
struct acpm_tmu_priv *priv = sensor->priv;
const struct acpm_tmu_ops *ops = &priv->handle->ops->tmu;
unsigned long mask = sensor->group->mask;
- bool pending_irq = false;
+ bool pending = false;
int i, ret;
u32 val;
@@ -345,16 +365,16 @@ static bool acpm_tmu_clear_pending_irq(struct acpm_tmu_sensor *sensor)
for_each_set_bit(i, &mask, EXYNOS_TMU_SENSORS_MAX_COUNT) {
ret = regmap_field_read(priv->regmap_fields[i], &val);
if (ret)
- return false;
+ return ret;
if (val) {
- pending_irq = true;
+ pending = true;
break;
}
}
- if (!pending_irq)
- return false;
+ if (!pending)
+ return 0;
ret = ops->clear_tz_irq(priv->handle, priv->mbox_chan_id,
sensor->group->id);
@@ -362,10 +382,12 @@ static bool acpm_tmu_clear_pending_irq(struct acpm_tmu_sensor *sensor)
dev_err_ratelimited(priv->dev,
"Sensor %u: failed to clear IRQ (%d)\n",
sensor->group->id, ret);
- return false;
+ return ret;
}
- return true;
+ *pending_irq = true;
+
+ return ret;
}
static irqreturn_t acpm_tmu_thread_fn(int irq, void *id)
@@ -383,8 +405,13 @@ static irqreturn_t acpm_tmu_thread_fn(int irq, void *id)
for (i = 0; i < priv->num_sensors; i++) {
struct acpm_tmu_sensor *sensor = &priv->sensors[i];
+ bool pending_irq = false;
- if (!sensor->tzd || !acpm_tmu_clear_pending_irq(sensor))
+ if (!sensor->tzd)
+ continue;
+
+ ret = priv->data->tmu_check_and_clear_irqs(sensor, &pending_irq);
+ if (ret || !pending_irq)
continue;
handled = true;
@@ -398,15 +425,30 @@ static irqreturn_t acpm_tmu_thread_fn(int irq, void *id)
return handled ? IRQ_HANDLED : IRQ_NONE;
}
+static const struct acpm_tmu_driver_data acpm_tmu_gs101 = {
+ .reg_fields = gs101_reg_fields,
+ .regmap_config = &gs101_regmap_config,
+ .sensor_groups = gs101_sensor_groups,
+ .num_sensor_groups = ARRAY_SIZE(gs101_sensor_groups),
+ .mbox_chan_id = 9,
+ .tz_control = gs101_tz_control,
+ .tmu_check_and_clear_irqs = gs101_handle_irqs,
+ .tmu_init = gs101_tmu_init,
+ .tmu_update_thresholds = gs101_tmu_update_thresholds,
+};
+
static const struct of_device_id acpm_tmu_match[] = {
- { .compatible = "google,gs101-tmu-top" },
+ {
+ .compatible = "google,gs101-tmu-top",
+ .data = &acpm_tmu_gs101
+ },
{ /* sentinel */ },
};
MODULE_DEVICE_TABLE(of, acpm_tmu_match);
static int acpm_tmu_probe(struct platform_device *pdev)
{
- const struct acpm_tmu_driver_data *data = &acpm_tmu_gs101;
+ const struct acpm_tmu_driver_data *data;
struct acpm_handle *acpm_handle;
struct device *dev = &pdev->dev;
struct acpm_tmu_priv *priv;
@@ -414,6 +456,10 @@ static int acpm_tmu_probe(struct platform_device *pdev)
void __iomem *base;
int i, ret;
+ data = of_device_get_match_data(dev);
+ if (!data)
+ return dev_err_probe(dev, -ENODEV, "No matching driver data found\n");
+
acpm_handle = devm_acpm_get_by_phandle(dev);
if (IS_ERR(acpm_handle))
return dev_err_probe(dev, PTR_ERR(acpm_handle),
@@ -423,6 +469,7 @@ static int acpm_tmu_probe(struct platform_device *pdev)
if (!priv)
return -ENOMEM;
+ priv->data = data;
priv->dev = dev;
priv->handle = acpm_handle;
priv->mbox_chan_id = data->mbox_chan_id;
@@ -434,10 +481,12 @@ static int acpm_tmu_probe(struct platform_device *pdev)
if (IS_ERR(base))
return dev_err_probe(dev, PTR_ERR(base), "Failed to ioremap resource\n");
- regmap = devm_regmap_init_mmio(dev, base, &gs101_regmap_config);
+ regmap = devm_regmap_init_mmio(dev, base, data->regmap_config);
if (IS_ERR(regmap))
return dev_err_probe(dev, PTR_ERR(regmap), "Failed to init regmap\n");
+ priv->regmap = regmap;
+
ret = devm_regmap_field_bulk_alloc(dev, regmap, priv->regmap_fields,
data->reg_fields, REG_INTPEND_COUNT);
if (ret)
@@ -464,10 +513,12 @@ static int acpm_tmu_probe(struct platform_device *pdev)
if (ret)
return dev_err_probe(dev, ret, "Failed to resume device\n");
- ret = acpm_handle->ops->tmu.init(acpm_handle, priv->mbox_chan_id);
- if (ret) {
- ret = dev_err_probe(dev, ret, "Failed to init TMU\n");
- goto out_pm_put;
+ if (priv->data->tmu_init) {
+ ret = priv->data->tmu_init(priv);
+ if (ret) {
+ ret = dev_err_probe(dev, ret, "Failed to init TMU\n");
+ goto out_pm_put;
+ }
}
for (i = 0; i < priv->num_sensors; i++) {
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 3/3] thermal: samsung: acpm-tmu: add Exynos850 support
2026-11-18 13:51 [PATCH v2 0/3] thermal: samsung: acpm-tmu: Add Exynos850 support Alexey Klimov
2026-11-18 13:51 ` [PATCH v2 1/3] dt-bindings: thermal: gs101-tmu: add Exynos850 compatible Alexey Klimov
2026-11-18 13:51 ` [PATCH v2 2/3] thermal: samsung: acpm-tmu: refactor SoC-specific operations into driver data Alexey Klimov
@ 2026-11-18 13:51 ` Alexey Klimov
2026-11-18 14:16 ` sashiko-bot
2 siblings, 1 reply; 5+ messages in thread
From: Alexey Klimov @ 2026-11-18 13:51 UTC (permalink / raw)
To: Daniel Lezcano, Tudor Ambarus, Rafael J. Wysocki, Zhang Rui,
Lukasz Luba, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Bartlomiej Zolnierkiewicz, Krzysztof Kozlowski
Cc: Mateusz Majewski, Thomas Turner, Peter Griffin, linux-pm,
linux-samsung-soc, devicetree, linux-kernel
Add support for the Thermal Management Unit block found on the
Exynos850 SoC.
Unlike the GS101, the Exynos850 ACPM firmware implements a smaller
set of IPC commands (primarily basic TMU initialization, suspend/resume,
and temperature reading). While the firmware supports basic TMU
initialization, suspend/resume, and temperature polling, it lacks the
ability to fully configure the hardware. The remaining functionality
is implemented via direct MMIO access:
- TMU initialization sequence,
- setting falling and rising thresholds and associated IRQs,
- helpers to convert temperature to hardware values,
- handling of IRQs,
- thermal zone control (TMU core enable/disable).
Additionally, this also reorders the sensor group assignment in
acpm_tmu_probe() to let it happen before TMU init SoC callback.
Signed-off-by: Alexey Klimov <alexey.klimov@linaro.org>
---
drivers/thermal/samsung/acpm-tmu.c | 481 ++++++++++++++++++++++++++++++++++++-
1 file changed, 480 insertions(+), 1 deletion(-)
diff --git a/drivers/thermal/samsung/acpm-tmu.c b/drivers/thermal/samsung/acpm-tmu.c
index 0def0ec09084..054c99dc8250 100644
--- a/drivers/thermal/samsung/acpm-tmu.c
+++ b/drivers/thermal/samsung/acpm-tmu.c
@@ -5,6 +5,7 @@
* Copyright 2026 Linaro Ltd.
*/
+#include <linux/bitfield.h>
#include <linux/cleanup.h>
#include <linux/clk.h>
#include <linux/compiler.h>
@@ -27,6 +28,120 @@
#define EXYNOS_TMU_SENSOR(i) BIT(i)
#define EXYNOS_TMU_SENSORS_MAX_COUNT 16
+/*
+ * Exynos850 TMU calibration type stored in the TRIMINFO CALIB_SEL field.
+ * Only two-point calibration needs special handling; anything else is
+ * treated as one-point calibration.
+ */
+#define EXYNOS850_TMU_CAL_TWO_POINT 1
+
+#define EXYNOS850_TMU_TRIM_TEMP_25C 25
+#define EXYNOS850_TMU_TRIM_TEMP_85C 85
+#define EXYNOS850_TMU_EFUSE_VALUE 55
+
+#define EXYNOS850_TMU_INTPEND_RISE_MASK GENMASK(8, 0)
+#define EXYNOS850_TMU_INTPEND_FALL_MASK GENMASK(23, 16)
+
+#define EXYNOS850_CPUCL0_SENSOR_MASK EXYNOS_TMU_SENSOR(1)
+#define EXYNOS850_CPUCL1_SENSOR_MASK EXYNOS_TMU_SENSOR(2)
+#define EXYNOS850_GPU_SENSOR_MASK EXYNOS_TMU_SENSOR(3)
+
+/* Exynos850 TMU registers */
+#define EXYNOS850_TMU_REG_TRIMINFO 0x00
+#define EXYNOS850_TMU_TRIMINFO_STRIDE 0x04
+#define EXYNOS850_TMU_TRIMINFO_OFFSET(n) \
+ (EXYNOS850_TMU_REG_TRIMINFO + (n) * EXYNOS850_TMU_TRIMINFO_STRIDE)
+
+#define EXYNOS850_TMU_REG_CONTROL 0x20
+#define EXYNOS850_TMU_REG_CONTROL1 0x24
+#define EXYNOS850_TMU_REG_COUNTER_VALUE0 0x30
+#define EXYNOS850_TMU_REG_COUNTER_VALUE1 0x34
+#define EXYNOS850_TMU_REG_AVG_CONTROL 0x38
+#define EXYNOS850_TMU_REG_TRIM0 0x3c
+
+#define EXYNOS850_TMU_REG_INTPEND0 0x118
+#define EXYNOS850_TMU_REG_INTPEND5 0x318
+#define EXYNOS850_TMU_REG_INTPEND8 0x658
+
+#define EXYNOS850_TMU_REG_INTEN0 0x110
+#define EXYNOS850_TMU_REG_INTEN5 0x310
+#define EXYNOS850_TMU_REG_INTEN8 0x650
+
+#define EXYNOS850_TMU_REG_THD0 0x50
+#define EXYNOS850_TMU_REG_THD1 0x170
+#define EXYNOS850_TMU_REG_THD8 0x450
+
+#define EXYNOS850_TMU_INT_REG_STRIDE 0x10
+#define EXYNOS850_TMU_THD_REG_STRIDE 0x20
+
+/* TRIMINFO fields */
+#define EXYNOS850_TMU_TRIMINFO_CALIB_SEL BIT(23)
+#define EXYNOS850_TMU_TRIMINFO_25C_MASK GENMASK(8, 0)
+#define EXYNOS850_TMU_TRIMINFO_85C_MASK GENMASK(17, 9)
+#define EXYNOS850_TMU_TRIMINFO_BUF_VREF_SEL GENMASK(22, 18)
+#define EXYNOS850_TMU_TRIMINFO_BUF_SLOPE_SEL GENMASK(21, 18)
+#define EXYNOS850_TMU_TRIMINFO_AVG_MODE GENMASK(20, 18)
+#define EXYNOS850_TMU_TRIMINFO_ANALOG_TRIM GENMASK(21, 18)
+
+/* CONTROL fields */
+#define EXYNOS850_TMU_CONTROL_CORE_EN BIT(0)
+#define EXYNOS850_TMU_CONTROL_BUF_SLOPE_SEL GENMASK(11, 8)
+#define EXYNOS850_TMU_CONTROL_THERM_TRIP_EN BIT(12)
+#define EXYNOS850_TMU_CONTROL_BUF_VREF_SEL GENMASK(28, 24)
+
+/* CONTROL1 fields */
+#define EXYNOS850_TMU_CONTROL1_NUM_PROBE GENMASK(19, 16)
+#define EXYNOS850_TMU_CONTROL1_LPI BIT(10)
+
+/* AVG_CONTROL fields */
+#define EXYNOS850_TMU_AVG_CONTROL_EN BIT(4)
+#define EXYNOS850_TMU_AVG_CONTROL_MODE GENMASK(2, 0)
+
+/* COUNTER_VALUE0/1 fields */
+#define EXYNOS850_TMU_COUNTER_VALUE0_MASK GENMASK(15, 0)
+#define EXYNOS850_TMU_COUNTER_VALUE1_MASK GENMASK(31, 16)
+/* Measurement counter value recommended by the TRM */
+#define EXYNOS850_TMU_COUNTER_VALUE 0x028a
+
+/* TRIM0 fields */
+#define EXYNOS850_TMU_TRIM0_BGRI GENMASK(23, 20)
+#define EXYNOS850_TMU_TRIM0_VREF GENMASK(15, 12)
+#define EXYNOS850_TMU_TRIM0_VBEI GENMASK(11, 8)
+
+/* THD and INTEN fields */
+#define EXYNOS850_TMU_THD_RISE1_OFFSET 0x0c
+#define EXYNOS850_TMU_THD_FALL1_OFFSET \
+ (EXYNOS850_TMU_THD_RISE1_OFFSET + 0x10)
+#define EXYNOS850_TMU_THD_LEVEL1_MASK GENMASK(24, 16)
+#define EXYNOS850_TMU_INTEN_RISE1 BIT(1)
+#define EXYNOS850_TMU_INTEN_FALL1 BIT(17)
+
+#define EXYNOS850_TMU_REG_THD(p) \
+ ((p) == 0 ? EXYNOS850_TMU_REG_THD0 : \
+ ((p) < 8 ? \
+ EXYNOS850_TMU_REG_THD1 + \
+ ((p) - 1) * EXYNOS850_TMU_THD_REG_STRIDE : \
+ EXYNOS850_TMU_REG_THD8 + \
+ ((p) - 8) * EXYNOS850_TMU_THD_REG_STRIDE))
+
+#define EXYNOS850_TMU_REG_INTEN(p) \
+ ((p) < 5 ? \
+ EXYNOS850_TMU_REG_INTEN0 + (p) * EXYNOS850_TMU_INT_REG_STRIDE : \
+ ((p) < 8 ? \
+ EXYNOS850_TMU_REG_INTEN5 + \
+ ((p) - 5) * EXYNOS850_TMU_INT_REG_STRIDE : \
+ EXYNOS850_TMU_REG_INTEN8 + \
+ ((p) - 8) * EXYNOS850_TMU_INT_REG_STRIDE))
+
+#define EXYNOS850_TMU_REG_INTPEND(p) \
+ ((p) < 5 ? \
+ EXYNOS850_TMU_REG_INTPEND0 + (p) * EXYNOS850_TMU_INT_REG_STRIDE : \
+ ((p) < 8 ? \
+ EXYNOS850_TMU_REG_INTPEND5 + \
+ ((p) - 5) * EXYNOS850_TMU_INT_REG_STRIDE : \
+ EXYNOS850_TMU_REG_INTPEND8 + \
+ ((p) - 8) * EXYNOS850_TMU_INT_REG_STRIDE))
+
#define GS101_CPUCL2_SENSOR_MASK (EXYNOS_TMU_SENSOR(0) | \
EXYNOS_TMU_SENSOR(6) | \
EXYNOS_TMU_SENSOR(7) | \
@@ -71,6 +186,8 @@ struct acpm_tmu_sensor {
struct mutex lock; /* protects sensor state */
enum thermal_device_mode mode;
bool enabled;
+
+ u16 temp_error1, temp_error2;
};
struct acpm_tmu_priv {
@@ -83,6 +200,7 @@ struct acpm_tmu_priv {
unsigned int mbox_chan_id;
unsigned int num_sensors;
int irq;
+ u32 cal_type;
struct acpm_tmu_sensor sensors[] __counted_by(num_sensors);
};
@@ -94,6 +212,7 @@ struct acpm_tmu_driver_data {
unsigned int mbox_chan_id;
/* SoC-specific TMU routines and values */
+ u32 efuse_value;
int (*tz_control)(struct acpm_tmu_sensor *sensor, bool on);
int (*tmu_check_and_clear_irqs)(struct acpm_tmu_sensor *sensor,
bool *pending_irq);
@@ -142,6 +261,40 @@ static const struct regmap_config gs101_regmap_config = {
.max_register = GS101_REG_INTPEND(15),
};
+static const struct acpm_tmu_sensor_group exynos850_sensor_groups[] = {
+ ACPM_TMU_SENSOR_GROUP(EXYNOS850_CPUCL0_SENSOR_MASK, 0),
+ ACPM_TMU_SENSOR_GROUP(EXYNOS850_CPUCL1_SENSOR_MASK, 1),
+ ACPM_TMU_SENSOR_GROUP(EXYNOS850_GPU_SENSOR_MASK, 2),
+};
+
+static const struct reg_field exynos850_reg_fields[REG_INTPEND_COUNT] = {
+ [P0_INTPEND] = REG_FIELD(EXYNOS850_TMU_REG_INTPEND(0), 0, 23),
+ [P1_INTPEND] = REG_FIELD(EXYNOS850_TMU_REG_INTPEND(1), 0, 23),
+ [P2_INTPEND] = REG_FIELD(EXYNOS850_TMU_REG_INTPEND(2), 0, 23),
+ [P3_INTPEND] = REG_FIELD(EXYNOS850_TMU_REG_INTPEND(3), 0, 23),
+ [P4_INTPEND] = REG_FIELD(EXYNOS850_TMU_REG_INTPEND(4), 0, 23),
+ [P5_INTPEND] = REG_FIELD(EXYNOS850_TMU_REG_INTPEND(5), 0, 23),
+ [P6_INTPEND] = REG_FIELD(EXYNOS850_TMU_REG_INTPEND(6), 0, 23),
+ [P7_INTPEND] = REG_FIELD(EXYNOS850_TMU_REG_INTPEND(7), 0, 23),
+ [P8_INTPEND] = REG_FIELD(EXYNOS850_TMU_REG_INTPEND(8), 0, 23),
+ [P9_INTPEND] = REG_FIELD(EXYNOS850_TMU_REG_INTPEND(9), 0, 23),
+ [P10_INTPEND] = REG_FIELD(EXYNOS850_TMU_REG_INTPEND(10), 0, 23),
+ [P11_INTPEND] = REG_FIELD(EXYNOS850_TMU_REG_INTPEND(11), 0, 23),
+ [P12_INTPEND] = REG_FIELD(EXYNOS850_TMU_REG_INTPEND(12), 0, 23),
+ [P13_INTPEND] = REG_FIELD(EXYNOS850_TMU_REG_INTPEND(13), 0, 23),
+ [P14_INTPEND] = REG_FIELD(EXYNOS850_TMU_REG_INTPEND(14), 0, 23),
+ [P15_INTPEND] = REG_FIELD(EXYNOS850_TMU_REG_INTPEND(15), 0, 23),
+};
+
+static const struct regmap_config exynos850_regmap_config = {
+ .name = "exynos850_tmu_regs",
+ .reg_bits = 32,
+ .reg_stride = 4,
+ .val_bits = 32,
+ .use_relaxed_mmio = true,
+ .max_register = EXYNOS850_TMU_REG_INTPEND(15),
+};
+
static int gs101_tz_control(struct acpm_tmu_sensor *sensor, bool on)
{
struct acpm_tmu_priv *priv = sensor->priv;
@@ -158,6 +311,190 @@ static int gs101_tmu_init(struct acpm_tmu_priv *priv)
return handle->ops->tmu.init(handle, priv->mbox_chan_id);
}
+static int exynos850_tz_control(struct acpm_tmu_sensor *sensor, bool on)
+{
+ struct acpm_tmu_priv *priv = sensor->priv;
+
+ return regmap_update_bits(priv->regmap, EXYNOS850_TMU_REG_CONTROL,
+ EXYNOS850_TMU_CONTROL_CORE_EN,
+ on ? EXYNOS850_TMU_CONTROL_CORE_EN : 0);
+}
+
+static int exynos850_tmu_read_trim_info(struct acpm_tmu_priv *priv)
+{
+ struct regmap *regmap = priv->regmap;
+ unsigned int trim_info;
+ int i, ret;
+
+ ret = regmap_read(regmap, EXYNOS850_TMU_TRIMINFO_OFFSET(0), &trim_info);
+ if (ret)
+ return ret;
+
+ priv->cal_type = FIELD_GET(EXYNOS850_TMU_TRIMINFO_CALIB_SEL, trim_info);
+
+ for (i = 0; i < priv->num_sensors; i++) {
+ struct acpm_tmu_sensor *sensor = &priv->sensors[i];
+ unsigned long mask = sensor->group->mask;
+ int t;
+
+ for_each_set_bit(t, &mask, EXYNOS_TMU_SENSORS_MAX_COUNT) {
+ u16 temp_error1, temp_error2;
+
+ ret = regmap_read(regmap, EXYNOS850_TMU_TRIMINFO_OFFSET(t),
+ &trim_info);
+ if (ret)
+ return ret;
+
+ temp_error1 = FIELD_GET(EXYNOS850_TMU_TRIMINFO_25C_MASK,
+ trim_info);
+ temp_error2 = FIELD_GET(EXYNOS850_TMU_TRIMINFO_85C_MASK,
+ trim_info);
+
+ if (temp_error1)
+ sensor->temp_error1 = temp_error1;
+ else
+ sensor->temp_error1 =
+ FIELD_GET(EXYNOS850_TMU_TRIMINFO_25C_MASK,
+ priv->data->efuse_value);
+
+ if (priv->cal_type != EXYNOS850_TMU_CAL_TWO_POINT)
+ continue;
+
+ if (temp_error2)
+ sensor->temp_error2 = temp_error2;
+ else
+ sensor->temp_error2 =
+ FIELD_GET(EXYNOS850_TMU_TRIMINFO_85C_MASK,
+ priv->data->efuse_value);
+ }
+ }
+
+ return 0;
+}
+
+static int exynos850_tmu_init(struct acpm_tmu_priv *priv)
+{
+ struct acpm_handle *handle = priv->handle;
+ struct regmap *regmap = priv->regmap;
+ unsigned int trim, t_buf_vref_sel, t_buf_slope_sel, avg_mode;
+ unsigned int t_bgri_trim, t_vref_trim, t_vbei_trim;
+ unsigned int avg_mode_val = 0;
+ u32 trim0_mask, trim0_val;
+ int ret;
+
+ ret = handle->ops->tmu.init(handle, priv->mbox_chan_id);
+ if (ret)
+ return ret;
+
+ /*
+ * The bootloader may have partially initialized the TMU or not
+ * initialized it at all, so always perform the full initialization.
+ */
+ ret = exynos850_tmu_read_trim_info(priv);
+ if (ret)
+ return ret;
+
+ /* Read TRIMINFO 0, 1, 2 settings */
+ ret = regmap_read(regmap, EXYNOS850_TMU_TRIMINFO_OFFSET(0), &trim);
+ if (ret)
+ return ret;
+ t_buf_vref_sel = FIELD_GET(EXYNOS850_TMU_TRIMINFO_BUF_VREF_SEL, trim);
+
+ ret = regmap_read(regmap, EXYNOS850_TMU_TRIMINFO_OFFSET(1), &trim);
+ if (ret)
+ return ret;
+ t_buf_slope_sel = FIELD_GET(EXYNOS850_TMU_TRIMINFO_BUF_SLOPE_SEL, trim);
+
+ ret = regmap_read(regmap, EXYNOS850_TMU_TRIMINFO_OFFSET(2), &trim);
+ if (ret)
+ return ret;
+ avg_mode = FIELD_GET(EXYNOS850_TMU_TRIMINFO_AVG_MODE, trim);
+
+ /*
+ * Set BUF_VREF_SEL and BUF_SLOPE_SEL.
+ * Clear THERM_TRIP_EN -- disable thermal tripping for now.
+ * Clear CORE_EN -- TMU core off.
+ */
+ ret = regmap_update_bits(regmap, EXYNOS850_TMU_REG_CONTROL,
+ EXYNOS850_TMU_CONTROL_BUF_VREF_SEL |
+ EXYNOS850_TMU_CONTROL_THERM_TRIP_EN |
+ EXYNOS850_TMU_CONTROL_BUF_SLOPE_SEL |
+ EXYNOS850_TMU_CONTROL_CORE_EN,
+ FIELD_PREP(EXYNOS850_TMU_CONTROL_BUF_VREF_SEL,
+ t_buf_vref_sel) |
+ FIELD_PREP(EXYNOS850_TMU_CONTROL_BUF_SLOPE_SEL,
+ t_buf_slope_sel));
+ if (ret)
+ return ret;
+
+ /*
+ * Set NUM_PROBE equal to the number of sensors.
+ * Disable LPI by clearing CONTROL1_LPI.
+ */
+ ret = regmap_update_bits(regmap, EXYNOS850_TMU_REG_CONTROL1,
+ EXYNOS850_TMU_CONTROL1_NUM_PROBE |
+ EXYNOS850_TMU_CONTROL1_LPI,
+ FIELD_PREP(EXYNOS850_TMU_CONTROL1_NUM_PROBE,
+ priv->num_sensors));
+ if (ret)
+ return ret;
+
+ /* Set AVG_MODE: enable averaging if the AVG_MODE field is non-zero. */
+ if (avg_mode)
+ avg_mode_val = EXYNOS850_TMU_AVG_CONTROL_EN |
+ FIELD_PREP(EXYNOS850_TMU_AVG_CONTROL_MODE,
+ avg_mode);
+
+ ret = regmap_update_bits(regmap, EXYNOS850_TMU_REG_AVG_CONTROL,
+ EXYNOS850_TMU_AVG_CONTROL_EN |
+ EXYNOS850_TMU_AVG_CONTROL_MODE,
+ avg_mode_val);
+ if (ret)
+ return ret;
+
+ /* Set COUNTER_VALUE 0 & 1 */
+ ret = regmap_update_bits(regmap, EXYNOS850_TMU_REG_COUNTER_VALUE0,
+ EXYNOS850_TMU_COUNTER_VALUE0_MASK,
+ FIELD_PREP(EXYNOS850_TMU_COUNTER_VALUE0_MASK,
+ EXYNOS850_TMU_COUNTER_VALUE));
+ if (ret)
+ return ret;
+
+ ret = regmap_update_bits(regmap, EXYNOS850_TMU_REG_COUNTER_VALUE1,
+ EXYNOS850_TMU_COUNTER_VALUE1_MASK,
+ FIELD_PREP(EXYNOS850_TMU_COUNTER_VALUE1_MASK,
+ EXYNOS850_TMU_COUNTER_VALUE));
+ if (ret)
+ return ret;
+
+ /* Read TRIMINFO 3, 4, 5 for BGR_I/VREF/VBE_I */
+ ret = regmap_read(regmap, EXYNOS850_TMU_TRIMINFO_OFFSET(3), &trim);
+ if (ret)
+ return ret;
+ t_bgri_trim = FIELD_GET(EXYNOS850_TMU_TRIMINFO_ANALOG_TRIM, trim);
+
+ ret = regmap_read(regmap, EXYNOS850_TMU_TRIMINFO_OFFSET(4), &trim);
+ if (ret)
+ return ret;
+ t_vref_trim = FIELD_GET(EXYNOS850_TMU_TRIMINFO_ANALOG_TRIM, trim);
+
+ ret = regmap_read(regmap, EXYNOS850_TMU_TRIMINFO_OFFSET(5), &trim);
+ if (ret)
+ return ret;
+ t_vbei_trim = FIELD_GET(EXYNOS850_TMU_TRIMINFO_ANALOG_TRIM, trim);
+
+ /* Set TRIM0 */
+ trim0_mask = EXYNOS850_TMU_TRIM0_BGRI |
+ EXYNOS850_TMU_TRIM0_VREF |
+ EXYNOS850_TMU_TRIM0_VBEI;
+ trim0_val = FIELD_PREP(EXYNOS850_TMU_TRIM0_BGRI, t_bgri_trim) |
+ FIELD_PREP(EXYNOS850_TMU_TRIM0_VREF, t_vref_trim) |
+ FIELD_PREP(EXYNOS850_TMU_TRIM0_VBEI, t_vbei_trim);
+
+ return regmap_update_bits(regmap, EXYNOS850_TMU_REG_TRIM0,
+ trim0_mask, trim0_val);
+}
+
static int acpm_tmu_op_tz_control(struct acpm_tmu_sensor *sensor, bool on)
{
struct acpm_tmu_priv *priv = sensor->priv;
@@ -246,6 +583,90 @@ static int acpm_tmu_get_temp(struct thermal_zone_device *tz, int *temp)
return 0;
}
+static int exynos850_temp_to_code(struct acpm_tmu_sensor *sensor, u8 temp)
+{
+ struct acpm_tmu_priv *priv = sensor->priv;
+
+ if (priv->cal_type == EXYNOS850_TMU_CAL_TWO_POINT)
+ return (temp - EXYNOS850_TMU_TRIM_TEMP_25C) *
+ (sensor->temp_error2 - sensor->temp_error1) /
+ (EXYNOS850_TMU_TRIM_TEMP_85C -
+ EXYNOS850_TMU_TRIM_TEMP_25C) +
+ sensor->temp_error1;
+
+ return temp + sensor->temp_error1 - EXYNOS850_TMU_TRIM_TEMP_25C;
+}
+
+static int exynos850_tmu_update_thresholds(struct acpm_tmu_sensor *sensor,
+ u8 thresholds[2], u8 inten)
+{
+ struct acpm_tmu_priv *priv = sensor->priv;
+ unsigned long mask = sensor->group->mask;
+ bool was_enabled;
+ int ret = 0, restore_ret, i, trip_code, trip_code_low;
+ u32 addr;
+
+ guard(mutex)(&sensor->lock);
+
+ was_enabled = sensor->enabled;
+
+ if (was_enabled) {
+ ret = acpm_tmu_op_tz_control(sensor, false);
+ if (ret)
+ return ret;
+ }
+
+ trip_code = exynos850_temp_to_code(sensor, thresholds[1]);
+ trip_code_low = exynos850_temp_to_code(sensor, thresholds[0]);
+
+ for_each_set_bit(i, &mask, EXYNOS_TMU_SENSORS_MAX_COUNT) {
+ u32 irq_en = 0;
+
+ if (inten & BIT(0)) {
+ addr = EXYNOS850_TMU_REG_THD(i) +
+ EXYNOS850_TMU_THD_FALL1_OFFSET;
+ ret = regmap_update_bits(priv->regmap, addr,
+ EXYNOS850_TMU_THD_LEVEL1_MASK,
+ FIELD_PREP(EXYNOS850_TMU_THD_LEVEL1_MASK,
+ trip_code_low));
+ if (ret)
+ goto out_restore;
+ irq_en = EXYNOS850_TMU_INTEN_FALL1;
+ }
+
+ if (inten & BIT(1)) {
+ addr = EXYNOS850_TMU_REG_THD(i) +
+ EXYNOS850_TMU_THD_RISE1_OFFSET;
+ ret = regmap_update_bits(priv->regmap, addr,
+ EXYNOS850_TMU_THD_LEVEL1_MASK,
+ FIELD_PREP(EXYNOS850_TMU_THD_LEVEL1_MASK,
+ trip_code));
+ if (ret)
+ goto out_restore;
+ irq_en |= EXYNOS850_TMU_INTEN_RISE1;
+ }
+
+ ret = regmap_update_bits(priv->regmap, EXYNOS850_TMU_REG_INTEN(i),
+ EXYNOS850_TMU_INTEN_FALL1 |
+ EXYNOS850_TMU_INTEN_RISE1, irq_en);
+ if (ret)
+ goto out_restore;
+ }
+
+out_restore:
+ if (was_enabled) {
+ restore_ret = acpm_tmu_op_tz_control(sensor, true);
+ if (restore_ret) {
+ dev_err(priv->dev, "Failed to restore sensor state: %d\n",
+ restore_ret);
+ if (!ret)
+ ret = restore_ret;
+ }
+ }
+
+ return ret;
+}
+
static int gs101_tmu_update_thresholds(struct acpm_tmu_sensor *sensor,
u8 thresholds[2], u8 inten)
{
@@ -390,6 +811,41 @@ static int gs101_handle_irqs(struct acpm_tmu_sensor *sensor, bool *pending_irq)
return ret;
}
+static int exynos850_handle_irqs(struct acpm_tmu_sensor *sensor,
+ bool *pending_irq)
+{
+ struct acpm_tmu_priv *priv = sensor->priv;
+ unsigned long mask = sensor->group->mask;
+ int i, ret;
+ u32 val, clear_val;
+
+ guard(mutex)(&sensor->lock);
+
+ for_each_set_bit(i, &mask, EXYNOS_TMU_SENSORS_MAX_COUNT) {
+ ret = regmap_field_read(priv->regmap_fields[i], &val);
+ if (ret)
+ return ret;
+
+ if (val) {
+ clear_val = val &
+ (EXYNOS850_TMU_INTPEND_RISE_MASK |
+ EXYNOS850_TMU_INTPEND_FALL_MASK);
+ ret = regmap_field_force_write(priv->regmap_fields[i],
+ clear_val);
+ if (ret) {
+ dev_err_ratelimited(priv->dev,
+ "sensor %d: failed to clear IRQ: %d\n",
+ i, ret);
+ return ret;
+ }
+ *pending_irq = true;
+ break;
+ }
+ }
+
+ return 0;
+}
+
static irqreturn_t acpm_tmu_thread_fn(int irq, void *id)
{
struct acpm_tmu_priv *priv = id;
@@ -437,11 +893,28 @@ static const struct acpm_tmu_driver_data acpm_tmu_gs101 = {
.tmu_update_thresholds = gs101_tmu_update_thresholds,
};
+static const struct acpm_tmu_driver_data acpm_tmu_exynos850 = {
+ .reg_fields = exynos850_reg_fields,
+ .regmap_config = &exynos850_regmap_config,
+ .sensor_groups = exynos850_sensor_groups,
+ .num_sensor_groups = ARRAY_SIZE(exynos850_sensor_groups),
+ .mbox_chan_id = 9,
+ .efuse_value = EXYNOS850_TMU_EFUSE_VALUE,
+ .tz_control = exynos850_tz_control,
+ .tmu_check_and_clear_irqs = exynos850_handle_irqs,
+ .tmu_init = exynos850_tmu_init,
+ .tmu_update_thresholds = exynos850_tmu_update_thresholds,
+};
+
static const struct of_device_id acpm_tmu_match[] = {
{
.compatible = "google,gs101-tmu-top",
.data = &acpm_tmu_gs101
},
+ {
+ .compatible = "samsung,exynos850-tmu-top",
+ .data = &acpm_tmu_exynos850,
+ },
{ /* sentinel */ },
};
MODULE_DEVICE_TABLE(of, acpm_tmu_match);
@@ -513,6 +986,13 @@ static int acpm_tmu_probe(struct platform_device *pdev)
if (ret)
return dev_err_probe(dev, ret, "Failed to resume device\n");
+ /* Sensor groups should be assigned before ->tmu_init() for some SoCs */
+ for (i = 0; i < priv->num_sensors; i++) {
+ struct acpm_tmu_sensor *sensor = &priv->sensors[i];
+
+ sensor->group = &data->sensor_groups[i];
+ }
+
if (priv->data->tmu_init) {
ret = priv->data->tmu_init(priv);
if (ret) {
@@ -526,7 +1006,6 @@ static int acpm_tmu_probe(struct platform_device *pdev)
struct thermal_zone_device *tzd;
mutex_init(&sensor->lock);
- sensor->group = &data->sensor_groups[i];
sensor->priv = priv;
tzd = devm_thermal_of_zone_register(dev, i, sensor,
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 3/3] thermal: samsung: acpm-tmu: add Exynos850 support
2026-11-18 13:51 ` [PATCH v2 3/3] thermal: samsung: acpm-tmu: add Exynos850 support Alexey Klimov
@ 2026-11-18 14:16 ` sashiko-bot
0 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-11-18 14:16 UTC (permalink / raw)
To: Alexey Klimov; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] thermal: samsung: acpm-tmu: uncoordinated global CORE_EN in
exynos850_tz_control()
- [Medium] thermal: samsung: acpm-tmu: zero temp_error2 fallback in
exynos850_tmu_read_trim_info()
- [Low] thermal: samsung: acpm-tmu: guard() mixed with goto in
exynos850_tmu_update_thresholds()
--
commit 4f3f530f809e63acf5e867e3d286ccbbbdd52053
Author: Alexey Klimov <alexey.klimov@linaro.org>
thermal: samsung: acpm-tmu: add Exynos850 support
This commit adds Exynos850 SoC support to the ACPM TMU driver using a mix of
ACPM IPC commands and direct MMIO register access for initialization,
threshold configuration, interrupt handling, and thermal zone control.
> diff --git a/drivers/thermal/samsung/acpm-tmu.c b/drivers/thermal/samsung/acpm-tmu.c
> index 0def0ec090841..054c99dc8250c 100644
> --- a/drivers/thermal/samsung/acpm-tmu.c
> +++ b/drivers/thermal/samsung/acpm-tmu.c
> @@ -27,6 +28,120 @@
> #define EXYNOS_TMU_SENSOR(i) BIT(i)
> #define EXYNOS_TMU_SENSORS_MAX_COUNT 16
>
> +/*
> + * Exynos850 TMU calibration type stored in the TRIMINFO CALIB_SEL field.
> + * Only two-point calibration needs special handling; anything else is
> + * treated as one-point calibration.
> + */
> +#define EXYNOS850_TMU_CAL_TWO_POINT 1
> +
> +#define EXYNOS850_TMU_TRIM_TEMP_25C 25
> +#define EXYNOS850_TMU_TRIM_TEMP_85C 85
> +#define EXYNOS850_TMU_EFUSE_VALUE 55
[ ... ]
> +/* TRIMINFO fields */
> +#define EXYNOS850_TMU_TRIMINFO_CALIB_SEL BIT(23)
> +#define EXYNOS850_TMU_TRIMINFO_25C_MASK GENMASK(8, 0)
> +#define EXYNOS850_TMU_TRIMINFO_85C_MASK GENMASK(17, 9)
[ ... ]
> @@ -158,6 +311,190 @@ static int gs101_tmu_init(struct acpm_tmu_priv *priv)
> return handle->ops->tmu.init(handle, priv->mbox_chan_id);
> }
>
> +static int exynos850_tz_control(struct acpm_tmu_sensor *sensor, bool on)
> +{
> + struct acpm_tmu_priv *priv = sensor->priv;
> +
> + return regmap_update_bits(priv->regmap, EXYNOS850_TMU_REG_CONTROL,
> + EXYNOS850_TMU_CONTROL_CORE_EN,
> + on ? EXYNOS850_TMU_CONTROL_CORE_EN : 0);
> +}
[Severity: High]
Does toggling EXYNOS850_TMU_CONTROL_CORE_EN per sensor without controller-wide
coordination disable the shared TMU core across all three Exynos850 thermal
zones?
All three groups in exynos850_sensor_groups share the single global
EXYNOS850_TMU_CONTROL_CORE_EN bit, while sensor->enabled and sensor->lock are
per-sensor. Disabling one thermal zone via acpm_tmu_change_mode() clears
EXYNOS850_TMU_CONTROL_CORE_EN globally and stops temperature sensing and
interrupts for the remaining active zones.
In addition, exynos850_tmu_update_thresholds() only checks sensor->enabled and
holds sensor->lock before toggling EXYNOS850_TMU_CONTROL_CORE_EN. During
acpm_tmu_probe(), registering sensor 1 after sensor 0 is already enabled
updates EXYNOS850_TMU_REG_THD and EXYNOS850_TMU_REG_INTEN while
EXYNOS850_TMU_CONTROL_CORE_EN is active, and concurrent trip updates on two
enabled zones race on CORE_EN:
CPU0 (sensor 0) CPU1 (sensor 1)
exynos850_tmu_update_thresholds()
lock(&sensor0->lock)
acpm_tmu_op_tz_control(false)
/* clears global CORE_EN */
exynos850_tmu_update_thresholds()
lock(&sensor1->lock)
acpm_tmu_op_tz_control(false)
...
acpm_tmu_op_tz_control(true)
/* sets global CORE_EN */
regmap_update_bits(..., REG_THD, ...)
<-- programs thresholds with CORE_EN set
> +
> +static int exynos850_tmu_read_trim_info(struct acpm_tmu_priv *priv)
> +{
> + struct regmap *regmap = priv->regmap;
> + unsigned int trim_info;
> + int i, ret;
> +
> + ret = regmap_read(regmap, EXYNOS850_TMU_TRIMINFO_OFFSET(0), &trim_info);
> + if (ret)
> + return ret;
> +
> + priv->cal_type = FIELD_GET(EXYNOS850_TMU_TRIMINFO_CALIB_SEL, trim_info);
> +
> + for (i = 0; i < priv->num_sensors; i++) {
> + struct acpm_tmu_sensor *sensor = &priv->sensors[i];
> + unsigned long mask = sensor->group->mask;
> + int t;
> +
> + for_each_set_bit(t, &mask, EXYNOS_TMU_SENSORS_MAX_COUNT) {
> + u16 temp_error1, temp_error2;
> +
> + ret = regmap_read(regmap, EXYNOS850_TMU_TRIMINFO_OFFSET(t),
> + &trim_info);
> + if (ret)
> + return ret;
> +
> + temp_error1 = FIELD_GET(EXYNOS850_TMU_TRIMINFO_25C_MASK,
> + trim_info);
> + temp_error2 = FIELD_GET(EXYNOS850_TMU_TRIMINFO_85C_MASK,
> + trim_info);
> +
> + if (temp_error1)
> + sensor->temp_error1 = temp_error1;
> + else
> + sensor->temp_error1 =
> + FIELD_GET(EXYNOS850_TMU_TRIMINFO_25C_MASK,
> + priv->data->efuse_value);
> +
> + if (priv->cal_type != EXYNOS850_TMU_CAL_TWO_POINT)
> + continue;
> +
> + if (temp_error2)
> + sensor->temp_error2 = temp_error2;
> + else
> + sensor->temp_error2 =
> + FIELD_GET(EXYNOS850_TMU_TRIMINFO_85C_MASK,
> + priv->data->efuse_value);
> + }
> + }
> +
> + return 0;
> +}
[Severity: Medium]
Does the fallback for sensor->temp_error2 always evaluate to 0?
priv->data->efuse_value is EXYNOS850_TMU_EFUSE_VALUE (55, or 0x37), so
extracting EXYNOS850_TMU_TRIMINFO_85C_MASK (GENMASK(17, 9)) yields 0. When
two-point calibration is selected and the 85C trim field in TRIMINFO is 0,
sensor->temp_error2 becomes 0 and exynos850_temp_to_code() computes
(sensor->temp_error2 - sensor->temp_error1) with a negative slope, producing
bogus threshold codes in exynos850_tmu_update_thresholds().
[ ... ]
> @@ -246,6 +583,90 @@ static int acpm_tmu_get_temp(struct thermal_zone_device *tz, int *temp)
> return 0;
> }
[ ... ]
> +static int exynos850_tmu_update_thresholds(struct acpm_tmu_sensor *sensor,
> + u8 thresholds[2], u8 inten)
> +{
> + struct acpm_tmu_priv *priv = sensor->priv;
> + unsigned long mask = sensor->group->mask;
> + bool was_enabled;
> + int ret = 0, restore_ret, i, trip_code, trip_code_low;
> + u32 addr;
> +
> + guard(mutex)(&sensor->lock);
> +
> + was_enabled = sensor->enabled;
> +
> + if (was_enabled) {
> + ret = acpm_tmu_op_tz_control(sensor, false);
> + if (ret)
> + return ret;
> + }
> +
> + trip_code = exynos850_temp_to_code(sensor, thresholds[1]);
> + trip_code_low = exynos850_temp_to_code(sensor, thresholds[0]);
> +
> + for_each_set_bit(i, &mask, EXYNOS_TMU_SENSORS_MAX_COUNT) {
> + u32 irq_en = 0;
> +
> + if (inten & BIT(0)) {
> + addr = EXYNOS850_TMU_REG_THD(i) +
> + EXYNOS850_TMU_THD_FALL1_OFFSET;
> + ret = regmap_update_bits(priv->regmap, addr,
> + EXYNOS850_TMU_THD_LEVEL1_MASK,
> + FIELD_PREP(EXYNOS850_TMU_THD_LEVEL1_MASK,
> + trip_code_low));
> + if (ret)
> + goto out_restore;
> + irq_en = EXYNOS850_TMU_INTEN_FALL1;
> + }
> +
> + if (inten & BIT(1)) {
> + addr = EXYNOS850_TMU_REG_THD(i) +
> + EXYNOS850_TMU_THD_RISE1_OFFSET;
> + ret = regmap_update_bits(priv->regmap, addr,
> + EXYNOS850_TMU_THD_LEVEL1_MASK,
> + FIELD_PREP(EXYNOS850_TMU_THD_LEVEL1_MASK,
> + trip_code));
> + if (ret)
> + goto out_restore;
> + irq_en |= EXYNOS850_TMU_INTEN_RISE1;
> + }
> +
> + ret = regmap_update_bits(priv->regmap, EXYNOS850_TMU_REG_INTEN(i),
> + EXYNOS850_TMU_INTEN_FALL1 |
> + EXYNOS850_TMU_INTEN_RISE1, irq_en);
> + if (ret)
> + goto out_restore;
> + }
> +
> +out_restore:
> + if (was_enabled) {
> + restore_ret = acpm_tmu_op_tz_control(sensor, true);
> + if (restore_ret) {
> + dev_err(priv->dev, "Failed to restore sensor state: %d\n",
> + restore_ret);
> + if (!ret)
> + ret = restore_ret;
> + }
> + }
> +
> + return ret;
> +}
[Severity: Low]
This isn't a bug, but exynos850_tmu_update_thresholds() mixes
guard(mutex)(&sensor->lock) with goto out_restore. Using break inside the
for_each_set_bit() loop would avoid mixing scope-based cleanup with goto
error handling.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118-acpm-tmu-e850-support-v2-0-19848c0d97e5@linaro.org?part=3
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-18 14:16 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 13:51 [PATCH v2 0/3] thermal: samsung: acpm-tmu: Add Exynos850 support Alexey Klimov
2026-11-18 13:51 ` [PATCH v2 1/3] dt-bindings: thermal: gs101-tmu: add Exynos850 compatible Alexey Klimov
2026-11-18 13:51 ` [PATCH v2 2/3] thermal: samsung: acpm-tmu: refactor SoC-specific operations into driver data Alexey Klimov
2026-11-18 13:51 ` [PATCH v2 3/3] thermal: samsung: acpm-tmu: add Exynos850 support Alexey Klimov
2026-11-18 14:16 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox