* [PATCH 0/9] Add thermal sensor driver support for Mediatek MT8196
@ 2025-07-21 8:14 Laura Nao
2025-07-21 8:14 ` [PATCH 1/9] dt-bindings: thermal: mediatek: Add LVTS thermal controller support for MT8196 Laura Nao
` (9 more replies)
0 siblings, 10 replies; 21+ messages in thread
From: Laura Nao @ 2025-07-21 8:14 UTC (permalink / raw)
To: srini, robh, krzk+dt, conor+dt, rafael, daniel.lezcano, rui.zhang,
lukasz.luba, matthias.bgg, angelogioacchino.delregno
Cc: nfraprado, arnd, colin.i.king, u.kleine-koenig, andrew-ct.chen,
lala.lin, bchihi, frank-w, devicetree, linux-kernel, linux-pm,
linux-arm-kernel, linux-mediatek, kernel, Laura Nao
This patch series extends the MediaTek LVTS thermal driver to support the
MT8196 SoC.
MT8196 uses a positive temp_factor for temperature conversion, requiring
slight adjustments in the conversion logic.
To support this, the series introduces:
- A new struct lvts_platform_ops to allow platform-specific
conversion logic between raw sensor values and temperature
- A variant of the lvts_temp_to_raw() implementation for SoCs with positive
temp_factor values
- Platform data and controller definitions for MT8196
Laura Nao (9):
dt-bindings: thermal: mediatek: Add LVTS thermal controller support
for MT8196
thermal/drivers/mediatek/lvts: Make number of calibration offsets
configurable
thermal/drivers/mediatek/lvts: Guard against zero temp_factor in
lvts_raw_to_temp
thermal: mediatek: lvts: Add platform ops to support alternative
conversion logic
thermal/drivers/mediatek/lvts: Add lvts_temp_to_raw variant for
positive temp_factor
thermal/drivers/mediatek/lvts: Add support for ATP mode
thermal/drivers/mediatek/lvts: Support MSR offset for 16-bit
calibration data
thermal/drivers/mediatek/lvts_thermal: Add MT8196 support
dt-bindings: nvmem: mediatek: efuse: Add support for MT8196
.../bindings/nvmem/mediatek,efuse.yaml | 1 +
.../thermal/mediatek,lvts-thermal.yaml | 2 +
drivers/thermal/mediatek/lvts_thermal.c | 315 ++++++++++++++++--
.../thermal/mediatek,lvts-thermal.h | 26 ++
4 files changed, 325 insertions(+), 19 deletions(-)
--
2.39.5
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 1/9] dt-bindings: thermal: mediatek: Add LVTS thermal controller support for MT8196
2025-07-21 8:14 [PATCH 0/9] Add thermal sensor driver support for Mediatek MT8196 Laura Nao
@ 2025-07-21 8:14 ` Laura Nao
2025-07-22 7:20 ` Krzysztof Kozlowski
2025-07-21 8:14 ` [PATCH 2/9] thermal/drivers/mediatek/lvts: Make number of calibration offsets configurable Laura Nao
` (8 subsequent siblings)
9 siblings, 1 reply; 21+ messages in thread
From: Laura Nao @ 2025-07-21 8:14 UTC (permalink / raw)
To: srini, robh, krzk+dt, conor+dt, rafael, daniel.lezcano, rui.zhang,
lukasz.luba, matthias.bgg, angelogioacchino.delregno
Cc: nfraprado, arnd, colin.i.king, u.kleine-koenig, andrew-ct.chen,
lala.lin, bchihi, frank-w, devicetree, linux-kernel, linux-pm,
linux-arm-kernel, linux-mediatek, kernel, Laura Nao
Add LVTS thermal controller binding for MediaTek MT8196.
Signed-off-by: Laura Nao <laura.nao@collabora.com>
---
.../thermal/mediatek,lvts-thermal.yaml | 2 ++
.../thermal/mediatek,lvts-thermal.h | 26 +++++++++++++++++++
2 files changed, 28 insertions(+)
diff --git a/Documentation/devicetree/bindings/thermal/mediatek,lvts-thermal.yaml b/Documentation/devicetree/bindings/thermal/mediatek,lvts-thermal.yaml
index 0259cd3ce9c5..beccdabe110b 100644
--- a/Documentation/devicetree/bindings/thermal/mediatek,lvts-thermal.yaml
+++ b/Documentation/devicetree/bindings/thermal/mediatek,lvts-thermal.yaml
@@ -26,6 +26,8 @@ properties:
- mediatek,mt8192-lvts-mcu
- mediatek,mt8195-lvts-ap
- mediatek,mt8195-lvts-mcu
+ - mediatek,mt8196-lvts-ap
+ - mediatek,mt8196-lvts-mcu
reg:
maxItems: 1
diff --git a/include/dt-bindings/thermal/mediatek,lvts-thermal.h b/include/dt-bindings/thermal/mediatek,lvts-thermal.h
index ddc7302a510a..0ec8ad184d47 100644
--- a/include/dt-bindings/thermal/mediatek,lvts-thermal.h
+++ b/include/dt-bindings/thermal/mediatek,lvts-thermal.h
@@ -80,4 +80,30 @@
#define MT8192_AP_MD1 15
#define MT8192_AP_MD2 16
+#define MT8196_MCU_MEDIUM_CPU6_0 0
+#define MT8196_MCU_MEDIUM_CPU6_1 1
+#define MT8196_MCU_DSU2 2
+#define MT8196_MCU_DSU3 3
+#define MT8196_MCU_LITTLE_CPU3 4
+#define MT8196_MCU_LITTLE_CPU0 5
+#define MT8196_MCU_LITTLE_CPU1 6
+#define MT8196_MCU_LITTLE_CPU2 7
+#define MT8196_MCU_MEDIUM_CPU4_0 8
+#define MT8196_MCU_MEDIUM_CPU4_1 9
+#define MT8196_MCU_MEDIUM_CPU5_0 10
+#define MT8196_MCU_MEDIUM_CPU5_1 11
+#define MT8196_MCU_DSU0 12
+#define MT8196_MCU_DSU1 13
+#define MT8196_MCU_BIG_CPU7_0 14
+#define MT8196_MCU_BIG_CPU7_1 15
+
+#define MT8196_AP_TOP0 0
+#define MT8196_AP_TOP1 1
+#define MT8196_AP_TOP2 2
+#define MT8196_AP_TOP3 3
+#define MT8196_AP_BOT0 4
+#define MT8196_AP_BOT1 5
+#define MT8196_AP_BOT2 6
+#define MT8196_AP_BOT3 7
+
#endif /* __MEDIATEK_LVTS_DT_H */
--
2.39.5
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 2/9] thermal/drivers/mediatek/lvts: Make number of calibration offsets configurable
2025-07-21 8:14 [PATCH 0/9] Add thermal sensor driver support for Mediatek MT8196 Laura Nao
2025-07-21 8:14 ` [PATCH 1/9] dt-bindings: thermal: mediatek: Add LVTS thermal controller support for MT8196 Laura Nao
@ 2025-07-21 8:14 ` Laura Nao
2025-07-21 8:14 ` [PATCH 3/9] thermal/drivers/mediatek/lvts: Guard against zero temp_factor in lvts_raw_to_temp Laura Nao
` (7 subsequent siblings)
9 siblings, 0 replies; 21+ messages in thread
From: Laura Nao @ 2025-07-21 8:14 UTC (permalink / raw)
To: srini, robh, krzk+dt, conor+dt, rafael, daniel.lezcano, rui.zhang,
lukasz.luba, matthias.bgg, angelogioacchino.delregno
Cc: nfraprado, arnd, colin.i.king, u.kleine-koenig, andrew-ct.chen,
lala.lin, bchihi, frank-w, devicetree, linux-kernel, linux-pm,
linux-arm-kernel, linux-mediatek, kernel, Laura Nao
MT8196/MT6991 use 2-byte eFuse calibration data, whereas other SoCs
supported by the driver rely on 3 bytes. Make the number of calibration
bytes per sensor configurable, enabling support for SoCs with varying
calibration formats.
Signed-off-by: Laura Nao <laura.nao@collabora.com>
---
drivers/thermal/mediatek/lvts_thermal.c | 32 +++++++++++++++++--------
1 file changed, 22 insertions(+), 10 deletions(-)
diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c
index 985925147ac0..8d5259b9d03b 100644
--- a/drivers/thermal/mediatek/lvts_thermal.c
+++ b/drivers/thermal/mediatek/lvts_thermal.c
@@ -96,12 +96,14 @@
#define LVTS_MINIMUM_THRESHOLD 20000
+#define LVTS_MAX_CAL_OFFSETS 3
+
static int golden_temp = LVTS_GOLDEN_TEMP_DEFAULT;
static int golden_temp_offset;
struct lvts_sensor_data {
int dt_id;
- u8 cal_offsets[3];
+ u8 cal_offsets[LVTS_MAX_CAL_OFFSETS];
};
struct lvts_ctrl_data {
@@ -125,6 +127,7 @@ struct lvts_ctrl_data {
struct lvts_data {
const struct lvts_ctrl_data *lvts_ctrl;
+ int num_cal_offsets;
int num_lvts_ctrl;
int temp_factor;
int temp_offset;
@@ -707,7 +710,7 @@ static int lvts_calibration_init(struct device *dev, struct lvts_ctrl *lvts_ctrl
u8 *efuse_calibration,
size_t calib_len)
{
- int i;
+ int i, j;
u32 gt;
/* A zero value for gt means that device has invalid efuse data */
@@ -716,17 +719,18 @@ static int lvts_calibration_init(struct device *dev, struct lvts_ctrl *lvts_ctrl
lvts_for_each_valid_sensor(i, lvts_ctrl_data) {
const struct lvts_sensor_data *sensor =
&lvts_ctrl_data->lvts_sensor[i];
+ u32 calib = 0;
- if (sensor->cal_offsets[0] >= calib_len ||
- sensor->cal_offsets[1] >= calib_len ||
- sensor->cal_offsets[2] >= calib_len)
- return -EINVAL;
+ for (j = 0; j < lvts_ctrl->lvts_data->num_cal_offsets; j++) {
+ u8 offset = sensor->cal_offsets[j];
+
+ if (offset >= calib_len)
+ return -EINVAL;
+ calib |= efuse_calibration[offset] << (8 * j);
+ }
if (gt) {
- lvts_ctrl->calibration[i] =
- (efuse_calibration[sensor->cal_offsets[0]] << 0) +
- (efuse_calibration[sensor->cal_offsets[1]] << 8) +
- (efuse_calibration[sensor->cal_offsets[2]] << 16);
+ lvts_ctrl->calibration[i] = calib;
} else if (lvts_ctrl->lvts_data->def_calibration) {
lvts_ctrl->calibration[i] = lvts_ctrl->lvts_data->def_calibration;
} else {
@@ -1743,6 +1747,7 @@ static const struct lvts_data mt7988_lvts_ap_data = {
.temp_factor = LVTS_COEFF_A_MT7988,
.temp_offset = LVTS_COEFF_B_MT7988,
.gt_calib_bit_offset = 24,
+ .num_cal_offsets = 3,
};
static const struct lvts_data mt8186_lvts_data = {
@@ -1752,6 +1757,7 @@ static const struct lvts_data mt8186_lvts_data = {
.temp_offset = LVTS_COEFF_B_MT7988,
.gt_calib_bit_offset = 24,
.def_calibration = 19000,
+ .num_cal_offsets = 3,
};
static const struct lvts_data mt8188_lvts_mcu_data = {
@@ -1761,6 +1767,7 @@ static const struct lvts_data mt8188_lvts_mcu_data = {
.temp_offset = LVTS_COEFF_B_MT8195,
.gt_calib_bit_offset = 20,
.def_calibration = 35000,
+ .num_cal_offsets = 3,
};
static const struct lvts_data mt8188_lvts_ap_data = {
@@ -1770,6 +1777,7 @@ static const struct lvts_data mt8188_lvts_ap_data = {
.temp_offset = LVTS_COEFF_B_MT8195,
.gt_calib_bit_offset = 20,
.def_calibration = 35000,
+ .num_cal_offsets = 3,
};
static const struct lvts_data mt8192_lvts_mcu_data = {
@@ -1779,6 +1787,7 @@ static const struct lvts_data mt8192_lvts_mcu_data = {
.temp_offset = LVTS_COEFF_B_MT8195,
.gt_calib_bit_offset = 24,
.def_calibration = 35000,
+ .num_cal_offsets = 3,
};
static const struct lvts_data mt8192_lvts_ap_data = {
@@ -1788,6 +1797,7 @@ static const struct lvts_data mt8192_lvts_ap_data = {
.temp_offset = LVTS_COEFF_B_MT8195,
.gt_calib_bit_offset = 24,
.def_calibration = 35000,
+ .num_cal_offsets = 3,
};
static const struct lvts_data mt8195_lvts_mcu_data = {
@@ -1797,6 +1807,7 @@ static const struct lvts_data mt8195_lvts_mcu_data = {
.temp_offset = LVTS_COEFF_B_MT8195,
.gt_calib_bit_offset = 24,
.def_calibration = 35000,
+ .num_cal_offsets = 3,
};
static const struct lvts_data mt8195_lvts_ap_data = {
@@ -1806,6 +1817,7 @@ static const struct lvts_data mt8195_lvts_ap_data = {
.temp_offset = LVTS_COEFF_B_MT8195,
.gt_calib_bit_offset = 24,
.def_calibration = 35000,
+ .num_cal_offsets = 3,
};
static const struct of_device_id lvts_of_match[] = {
--
2.39.5
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 3/9] thermal/drivers/mediatek/lvts: Guard against zero temp_factor in lvts_raw_to_temp
2025-07-21 8:14 [PATCH 0/9] Add thermal sensor driver support for Mediatek MT8196 Laura Nao
2025-07-21 8:14 ` [PATCH 1/9] dt-bindings: thermal: mediatek: Add LVTS thermal controller support for MT8196 Laura Nao
2025-07-21 8:14 ` [PATCH 2/9] thermal/drivers/mediatek/lvts: Make number of calibration offsets configurable Laura Nao
@ 2025-07-21 8:14 ` Laura Nao
2025-07-21 10:08 ` Chen-Yu Tsai
2025-07-21 8:14 ` [PATCH 4/9] thermal: mediatek: lvts: Add platform ops to support alternative conversion logic Laura Nao
` (6 subsequent siblings)
9 siblings, 1 reply; 21+ messages in thread
From: Laura Nao @ 2025-07-21 8:14 UTC (permalink / raw)
To: srini, robh, krzk+dt, conor+dt, rafael, daniel.lezcano, rui.zhang,
lukasz.luba, matthias.bgg, angelogioacchino.delregno
Cc: nfraprado, arnd, colin.i.king, u.kleine-koenig, andrew-ct.chen,
lala.lin, bchihi, frank-w, devicetree, linux-kernel, linux-pm,
linux-arm-kernel, linux-mediatek, kernel, Laura Nao
Add a guard against zero temp_factor in lvts_raw_to_temp() to prevent
division by zero and ensure safe conversion.
Fixes: 6725a29321e4 ("thermal/drivers/mediatek/lvts_thermal: Make coeff configurable")
Signed-off-by: Laura Nao <laura.nao@collabora.com>
---
drivers/thermal/mediatek/lvts_thermal.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c
index 8d5259b9d03b..b80c2929ae74 100644
--- a/drivers/thermal/mediatek/lvts_thermal.c
+++ b/drivers/thermal/mediatek/lvts_thermal.c
@@ -280,11 +280,14 @@ static int lvts_raw_to_temp(u32 raw_temp, int temp_factor)
static u32 lvts_temp_to_raw(int temperature, int temp_factor)
{
- u32 raw_temp = ((s64)(golden_temp_offset - temperature)) << 14;
+ u32 raw_temp;
- raw_temp = div_s64(raw_temp, -temp_factor);
+ if (temp_factor == 0)
+ return temperature;
- return raw_temp;
+ raw_temp = ((s64)(golden_temp_offset - temperature)) << 14;
+
+ return div_s64(raw_temp, -temp_factor);
}
static int lvts_get_temp(struct thermal_zone_device *tz, int *temp)
--
2.39.5
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 4/9] thermal: mediatek: lvts: Add platform ops to support alternative conversion logic
2025-07-21 8:14 [PATCH 0/9] Add thermal sensor driver support for Mediatek MT8196 Laura Nao
` (2 preceding siblings ...)
2025-07-21 8:14 ` [PATCH 3/9] thermal/drivers/mediatek/lvts: Guard against zero temp_factor in lvts_raw_to_temp Laura Nao
@ 2025-07-21 8:14 ` Laura Nao
2025-07-21 8:14 ` [PATCH 5/9] thermal/drivers/mediatek/lvts: Add lvts_temp_to_raw variant for positive temp_factor Laura Nao
` (5 subsequent siblings)
9 siblings, 0 replies; 21+ messages in thread
From: Laura Nao @ 2025-07-21 8:14 UTC (permalink / raw)
To: srini, robh, krzk+dt, conor+dt, rafael, daniel.lezcano, rui.zhang,
lukasz.luba, matthias.bgg, angelogioacchino.delregno
Cc: nfraprado, arnd, colin.i.king, u.kleine-koenig, andrew-ct.chen,
lala.lin, bchihi, frank-w, devicetree, linux-kernel, linux-pm,
linux-arm-kernel, linux-mediatek, kernel, Laura Nao
Introduce lvts_platform_ops struct to support SoC-specific versions of
lvts_raw_to_temp() and lvts_temp_to_raw() conversion functions.
This is in preparation for supporting SoCs like MT8196/MT6991, which
have a positive temp_factor and need a different lvts_temp_to_raw()
implementation.
Signed-off-by: Laura Nao <laura.nao@collabora.com>
---
drivers/thermal/mediatek/lvts_thermal.c | 46 +++++++++++++++++++++++--
1 file changed, 43 insertions(+), 3 deletions(-)
diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c
index b80c2929ae74..db83137c7537 100644
--- a/drivers/thermal/mediatek/lvts_thermal.c
+++ b/drivers/thermal/mediatek/lvts_thermal.c
@@ -125,8 +125,14 @@ struct lvts_ctrl_data {
continue; \
else
+struct lvts_platform_ops {
+ int (*lvts_raw_to_temp)(u32 raw_temp, int temp_factor);
+ u32 (*lvts_temp_to_raw)(int temperature, int temp_factor);
+};
+
struct lvts_data {
const struct lvts_ctrl_data *lvts_ctrl;
+ struct lvts_platform_ops ops;
int num_cal_offsets;
int num_lvts_ctrl;
int temp_factor;
@@ -296,6 +302,7 @@ static int lvts_get_temp(struct thermal_zone_device *tz, int *temp)
struct lvts_ctrl *lvts_ctrl = container_of(lvts_sensor, struct lvts_ctrl,
sensors[lvts_sensor->id]);
const struct lvts_data *lvts_data = lvts_ctrl->lvts_data;
+ const struct lvts_platform_ops *ops = &lvts_data->ops;
void __iomem *msr = lvts_sensor->msr;
u32 value;
int rc;
@@ -328,7 +335,7 @@ static int lvts_get_temp(struct thermal_zone_device *tz, int *temp)
if (rc)
return -EAGAIN;
- *temp = lvts_raw_to_temp(value & 0xFFFF, lvts_data->temp_factor);
+ *temp = ops->lvts_raw_to_temp(value & 0xFFFF, lvts_data->temp_factor);
return 0;
}
@@ -396,10 +403,11 @@ static int lvts_set_trips(struct thermal_zone_device *tz, int low, int high)
struct lvts_ctrl *lvts_ctrl = container_of(lvts_sensor, struct lvts_ctrl,
sensors[lvts_sensor->id]);
const struct lvts_data *lvts_data = lvts_ctrl->lvts_data;
+ const struct lvts_platform_ops *ops = &lvts_data->ops;
void __iomem *base = lvts_sensor->base;
- u32 raw_low = lvts_temp_to_raw(low != -INT_MAX ? low : LVTS_MINIMUM_THRESHOLD,
+ u32 raw_low = ops->lvts_temp_to_raw(low != -INT_MAX ? low : LVTS_MINIMUM_THRESHOLD,
lvts_data->temp_factor);
- u32 raw_high = lvts_temp_to_raw(high, lvts_data->temp_factor);
+ u32 raw_high = ops->lvts_temp_to_raw(high, lvts_data->temp_factor);
bool should_update_thresh;
lvts_sensor->low_thresh = low;
@@ -1751,6 +1759,10 @@ static const struct lvts_data mt7988_lvts_ap_data = {
.temp_offset = LVTS_COEFF_B_MT7988,
.gt_calib_bit_offset = 24,
.num_cal_offsets = 3,
+ .ops = {
+ .lvts_raw_to_temp = lvts_raw_to_temp,
+ .lvts_temp_to_raw = lvts_temp_to_raw,
+ }
};
static const struct lvts_data mt8186_lvts_data = {
@@ -1761,6 +1773,10 @@ static const struct lvts_data mt8186_lvts_data = {
.gt_calib_bit_offset = 24,
.def_calibration = 19000,
.num_cal_offsets = 3,
+ .ops = {
+ .lvts_raw_to_temp = lvts_raw_to_temp,
+ .lvts_temp_to_raw = lvts_temp_to_raw,
+ }
};
static const struct lvts_data mt8188_lvts_mcu_data = {
@@ -1771,6 +1787,10 @@ static const struct lvts_data mt8188_lvts_mcu_data = {
.gt_calib_bit_offset = 20,
.def_calibration = 35000,
.num_cal_offsets = 3,
+ .ops = {
+ .lvts_raw_to_temp = lvts_raw_to_temp,
+ .lvts_temp_to_raw = lvts_temp_to_raw,
+ }
};
static const struct lvts_data mt8188_lvts_ap_data = {
@@ -1781,6 +1801,10 @@ static const struct lvts_data mt8188_lvts_ap_data = {
.gt_calib_bit_offset = 20,
.def_calibration = 35000,
.num_cal_offsets = 3,
+ .ops = {
+ .lvts_raw_to_temp = lvts_raw_to_temp,
+ .lvts_temp_to_raw = lvts_temp_to_raw,
+ }
};
static const struct lvts_data mt8192_lvts_mcu_data = {
@@ -1791,6 +1815,10 @@ static const struct lvts_data mt8192_lvts_mcu_data = {
.gt_calib_bit_offset = 24,
.def_calibration = 35000,
.num_cal_offsets = 3,
+ .ops = {
+ .lvts_raw_to_temp = lvts_raw_to_temp,
+ .lvts_temp_to_raw = lvts_temp_to_raw,
+ }
};
static const struct lvts_data mt8192_lvts_ap_data = {
@@ -1801,6 +1829,10 @@ static const struct lvts_data mt8192_lvts_ap_data = {
.gt_calib_bit_offset = 24,
.def_calibration = 35000,
.num_cal_offsets = 3,
+ .ops = {
+ .lvts_raw_to_temp = lvts_raw_to_temp,
+ .lvts_temp_to_raw = lvts_temp_to_raw,
+ }
};
static const struct lvts_data mt8195_lvts_mcu_data = {
@@ -1811,6 +1843,10 @@ static const struct lvts_data mt8195_lvts_mcu_data = {
.gt_calib_bit_offset = 24,
.def_calibration = 35000,
.num_cal_offsets = 3,
+ .ops = {
+ .lvts_raw_to_temp = lvts_raw_to_temp,
+ .lvts_temp_to_raw = lvts_temp_to_raw,
+ }
};
static const struct lvts_data mt8195_lvts_ap_data = {
@@ -1821,6 +1857,10 @@ static const struct lvts_data mt8195_lvts_ap_data = {
.gt_calib_bit_offset = 24,
.def_calibration = 35000,
.num_cal_offsets = 3,
+ .ops = {
+ .lvts_raw_to_temp = lvts_raw_to_temp,
+ .lvts_temp_to_raw = lvts_temp_to_raw,
+ }
};
static const struct of_device_id lvts_of_match[] = {
--
2.39.5
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 5/9] thermal/drivers/mediatek/lvts: Add lvts_temp_to_raw variant for positive temp_factor
2025-07-21 8:14 [PATCH 0/9] Add thermal sensor driver support for Mediatek MT8196 Laura Nao
` (3 preceding siblings ...)
2025-07-21 8:14 ` [PATCH 4/9] thermal: mediatek: lvts: Add platform ops to support alternative conversion logic Laura Nao
@ 2025-07-21 8:14 ` Laura Nao
2025-07-21 11:12 ` Chen-Yu Tsai
2025-07-21 8:14 ` [PATCH 6/9] thermal/drivers/mediatek/lvts: Add support for ATP mode Laura Nao
` (4 subsequent siblings)
9 siblings, 1 reply; 21+ messages in thread
From: Laura Nao @ 2025-07-21 8:14 UTC (permalink / raw)
To: srini, robh, krzk+dt, conor+dt, rafael, daniel.lezcano, rui.zhang,
lukasz.luba, matthias.bgg, angelogioacchino.delregno
Cc: nfraprado, arnd, colin.i.king, u.kleine-koenig, andrew-ct.chen,
lala.lin, bchihi, frank-w, devicetree, linux-kernel, linux-pm,
linux-arm-kernel, linux-mediatek, kernel, Laura Nao
The current lvts_temp_to_raw() implementation assumes a negative
temperature-to-raw slope (temp_factor), which holds for the SoCs
currently supported by the driver. However, this assumption breaks on
MT8196/MT6991, where the slope is positive.
Add a variant of the function that inverts the calculation logic
accordingly. This ensures accurate raw value generation for temperature
thresholds,avoiding spurious thermal interrupts or unintended hardware
resets on MT8196/MT6991.
Signed-off-by: Laura Nao <laura.nao@collabora.com>
---
drivers/thermal/mediatek/lvts_thermal.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c
index db83137c7537..3c34956e37c1 100644
--- a/drivers/thermal/mediatek/lvts_thermal.c
+++ b/drivers/thermal/mediatek/lvts_thermal.c
@@ -296,6 +296,18 @@ static u32 lvts_temp_to_raw(int temperature, int temp_factor)
return div_s64(raw_temp, -temp_factor);
}
+static u32 lvts_temp_to_raw_v2(int temperature, int temp_factor)
+{
+ u32 raw_temp;
+
+ if (temp_factor == 0)
+ return temperature;
+
+ raw_temp = temperature - golden_temp_offset;
+
+ return div_s64((s64)temp_factor << 14, raw_temp);
+}
+
static int lvts_get_temp(struct thermal_zone_device *tz, int *temp)
{
struct lvts_sensor *lvts_sensor = thermal_zone_device_priv(tz);
--
2.39.5
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 6/9] thermal/drivers/mediatek/lvts: Add support for ATP mode
2025-07-21 8:14 [PATCH 0/9] Add thermal sensor driver support for Mediatek MT8196 Laura Nao
` (4 preceding siblings ...)
2025-07-21 8:14 ` [PATCH 5/9] thermal/drivers/mediatek/lvts: Add lvts_temp_to_raw variant for positive temp_factor Laura Nao
@ 2025-07-21 8:14 ` Laura Nao
2025-07-21 11:09 ` Chen-Yu Tsai
2025-07-21 8:14 ` [PATCH 7/9] thermal/drivers/mediatek/lvts: Support MSR offset for 16-bit calibration data Laura Nao
` (3 subsequent siblings)
9 siblings, 1 reply; 21+ messages in thread
From: Laura Nao @ 2025-07-21 8:14 UTC (permalink / raw)
To: srini, robh, krzk+dt, conor+dt, rafael, daniel.lezcano, rui.zhang,
lukasz.luba, matthias.bgg, angelogioacchino.delregno
Cc: nfraprado, arnd, colin.i.king, u.kleine-koenig, andrew-ct.chen,
lala.lin, bchihi, frank-w, devicetree, linux-kernel, linux-pm,
linux-arm-kernel, linux-mediatek, kernel, Laura Nao
MT8196/MT6991 uses ATP (Abnormal Temperature Prevention) mode to detect
abnormal temperature conditions, which involves reading temperature data
from a dedicated set of registers separate from the ones used for
immediate and filtered modes.
Add support for ATP mode and its relative registers to ensure accurate
temperature readings and proper thermal management on MT8196/MT6991
devices.
Signed-off-by: Laura Nao <laura.nao@collabora.com>
---
drivers/thermal/mediatek/lvts_thermal.c | 34 ++++++++++++++++++++++---
1 file changed, 31 insertions(+), 3 deletions(-)
diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c
index 3c34956e37c1..8f9da0d5b886 100644
--- a/drivers/thermal/mediatek/lvts_thermal.c
+++ b/drivers/thermal/mediatek/lvts_thermal.c
@@ -44,6 +44,10 @@
#define LVTS_EDATA01(__base) (__base + 0x0058)
#define LVTS_EDATA02(__base) (__base + 0x005C)
#define LVTS_EDATA03(__base) (__base + 0x0060)
+#define LVTS_ATP0(__base) (__base + 0x0070)
+#define LVTS_ATP1(__base) (__base + 0x0074)
+#define LVTS_ATP2(__base) (__base + 0x0078)
+#define LVTS_ATP3(__base) (__base + 0x007C)
#define LVTS_MSR0(__base) (__base + 0x0090)
#define LVTS_MSR1(__base) (__base + 0x0094)
#define LVTS_MSR2(__base) (__base + 0x0098)
@@ -90,6 +94,7 @@
#define LVTS_MSR_IMMEDIATE_MODE 0
#define LVTS_MSR_FILTERED_MODE 1
+#define LVTS_MSR_ATP_MODE 2
#define LVTS_MSR_READ_TIMEOUT_US 400
#define LVTS_MSR_READ_WAIT_US (LVTS_MSR_READ_TIMEOUT_US / 2)
@@ -207,6 +212,10 @@ static const struct debugfs_reg32 lvts_regs[] = {
LVTS_DEBUG_FS_REGS(LVTS_EDATA01),
LVTS_DEBUG_FS_REGS(LVTS_EDATA02),
LVTS_DEBUG_FS_REGS(LVTS_EDATA03),
+ LVTS_DEBUG_FS_REGS(LVTS_ATP0),
+ LVTS_DEBUG_FS_REGS(LVTS_ATP1),
+ LVTS_DEBUG_FS_REGS(LVTS_ATP2),
+ LVTS_DEBUG_FS_REGS(LVTS_ATP3),
LVTS_DEBUG_FS_REGS(LVTS_MSR0),
LVTS_DEBUG_FS_REGS(LVTS_MSR1),
LVTS_DEBUG_FS_REGS(LVTS_MSR2),
@@ -621,6 +630,13 @@ static int lvts_sensor_init(struct device *dev, struct lvts_ctrl *lvts_ctrl,
LVTS_IMMD3(lvts_ctrl->base)
};
+ void __iomem *atp_regs[] = {
+ LVTS_ATP0(lvts_ctrl->base),
+ LVTS_ATP1(lvts_ctrl->base),
+ LVTS_ATP2(lvts_ctrl->base),
+ LVTS_ATP3(lvts_ctrl->base)
+ };
+
int i;
lvts_for_each_valid_sensor(i, lvts_ctrl_data) {
@@ -656,8 +672,20 @@ static int lvts_sensor_init(struct device *dev, struct lvts_ctrl *lvts_ctrl,
/*
* Each sensor has its own register address to read from.
*/
- lvts_sensor[i].msr = lvts_ctrl_data->mode == LVTS_MSR_IMMEDIATE_MODE ?
- imm_regs[i] : msr_regs[i];
+ switch (lvts_ctrl_data->mode) {
+ case LVTS_MSR_IMMEDIATE_MODE:
+ lvts_sensor[i].msr = imm_regs[i];
+ break;
+ case LVTS_MSR_FILTERED_MODE:
+ lvts_sensor[i].msr = msr_regs[i];
+ break;
+ case LVTS_MSR_ATP_MODE:
+ lvts_sensor[i].msr = atp_regs[i];
+ break;
+ default:
+ lvts_sensor[i].msr = imm_regs[i];
+ break;
+ }
lvts_sensor[i].low_thresh = INT_MIN;
lvts_sensor[i].high_thresh = INT_MIN;
@@ -907,7 +935,7 @@ static void lvts_ctrl_monitor_enable(struct device *dev, struct lvts_ctrl *lvts_
u32 sensor_map = 0;
int i;
- if (lvts_ctrl->mode != LVTS_MSR_FILTERED_MODE)
+ if (lvts_ctrl->mode == LVTS_MSR_IMMEDIATE_MODE)
return;
if (enable) {
--
2.39.5
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 7/9] thermal/drivers/mediatek/lvts: Support MSR offset for 16-bit calibration data
2025-07-21 8:14 [PATCH 0/9] Add thermal sensor driver support for Mediatek MT8196 Laura Nao
` (5 preceding siblings ...)
2025-07-21 8:14 ` [PATCH 6/9] thermal/drivers/mediatek/lvts: Add support for ATP mode Laura Nao
@ 2025-07-21 8:14 ` Laura Nao
2025-07-21 8:14 ` [PATCH 8/9] thermal/drivers/mediatek/lvts_thermal: Add MT8196 support Laura Nao
` (2 subsequent siblings)
9 siblings, 0 replies; 21+ messages in thread
From: Laura Nao @ 2025-07-21 8:14 UTC (permalink / raw)
To: srini, robh, krzk+dt, conor+dt, rafael, daniel.lezcano, rui.zhang,
lukasz.luba, matthias.bgg, angelogioacchino.delregno
Cc: nfraprado, arnd, colin.i.king, u.kleine-koenig, andrew-ct.chen,
lala.lin, bchihi, frank-w, devicetree, linux-kernel, linux-pm,
linux-arm-kernel, linux-mediatek, kernel, Laura Nao
On MT8196/MT6991, per-sensor calibration data read from eFuses is
16-bit. When the LVTS controller operates in 16-bit mode, a fixed offset
must be added to MSR values during post-processing to obtain correct
temperature readings. Introduce a new msr_offset field in lvts_data,
program the respective register and apply the offset to the calibration
data read from eFuses.
Signed-off-by: Laura Nao <laura.nao@collabora.com>
---
drivers/thermal/mediatek/lvts_thermal.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c
index 8f9da0d5b886..81c8309ff9df 100644
--- a/drivers/thermal/mediatek/lvts_thermal.c
+++ b/drivers/thermal/mediatek/lvts_thermal.c
@@ -44,6 +44,7 @@
#define LVTS_EDATA01(__base) (__base + 0x0058)
#define LVTS_EDATA02(__base) (__base + 0x005C)
#define LVTS_EDATA03(__base) (__base + 0x0060)
+#define LVTS_MSROFT(__base) (__base + 0x006C)
#define LVTS_ATP0(__base) (__base + 0x0070)
#define LVTS_ATP1(__base) (__base + 0x0074)
#define LVTS_ATP2(__base) (__base + 0x0078)
@@ -144,6 +145,7 @@ struct lvts_data {
int temp_offset;
int gt_calib_bit_offset;
unsigned int def_calibration;
+ u16 msr_offset;
};
struct lvts_sensor {
@@ -212,6 +214,7 @@ static const struct debugfs_reg32 lvts_regs[] = {
LVTS_DEBUG_FS_REGS(LVTS_EDATA01),
LVTS_DEBUG_FS_REGS(LVTS_EDATA02),
LVTS_DEBUG_FS_REGS(LVTS_EDATA03),
+ LVTS_DEBUG_FS_REGS(LVTS_MSROFT),
LVTS_DEBUG_FS_REGS(LVTS_ATP0),
LVTS_DEBUG_FS_REGS(LVTS_ATP1),
LVTS_DEBUG_FS_REGS(LVTS_ATP2),
@@ -782,6 +785,8 @@ static int lvts_calibration_init(struct device *dev, struct lvts_ctrl *lvts_ctrl
if (gt) {
lvts_ctrl->calibration[i] = calib;
+ if (lvts_ctrl->lvts_data->msr_offset)
+ lvts_ctrl->calibration[i] += lvts_ctrl->lvts_data->msr_offset;
} else if (lvts_ctrl->lvts_data->def_calibration) {
lvts_ctrl->calibration[i] = lvts_ctrl->lvts_data->def_calibration;
} else {
@@ -1096,6 +1101,17 @@ static int lvts_ctrl_calibrate(struct device *dev, struct lvts_ctrl *lvts_ctrl)
for (i = 0; i < LVTS_SENSOR_MAX; i++)
writel(lvts_ctrl->calibration[i], lvts_edata[i]);
+ /* LVTS_MSROFT : Constant offset applied to MSR values
+ * for post-processing
+ *
+ * Bits:
+ *
+ * 20-0 : Constant data added to MSR values
+ */
+ if (lvts_ctrl->lvts_data->msr_offset)
+ writel(lvts_ctrl->lvts_data->msr_offset,
+ LVTS_MSROFT(lvts_ctrl->base));
+
return 0;
}
--
2.39.5
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 8/9] thermal/drivers/mediatek/lvts_thermal: Add MT8196 support
2025-07-21 8:14 [PATCH 0/9] Add thermal sensor driver support for Mediatek MT8196 Laura Nao
` (6 preceding siblings ...)
2025-07-21 8:14 ` [PATCH 7/9] thermal/drivers/mediatek/lvts: Support MSR offset for 16-bit calibration data Laura Nao
@ 2025-07-21 8:14 ` Laura Nao
2025-07-21 8:14 ` [PATCH 9/9] dt-bindings: nvmem: mediatek: efuse: Add support for MT8196 Laura Nao
2025-07-22 7:40 ` [PATCH 0/9] Add thermal sensor driver support for Mediatek MT8196 Chen-Yu Tsai
9 siblings, 0 replies; 21+ messages in thread
From: Laura Nao @ 2025-07-21 8:14 UTC (permalink / raw)
To: srini, robh, krzk+dt, conor+dt, rafael, daniel.lezcano, rui.zhang,
lukasz.luba, matthias.bgg, angelogioacchino.delregno
Cc: nfraprado, arnd, colin.i.king, u.kleine-koenig, andrew-ct.chen,
lala.lin, bchihi, frank-w, devicetree, linux-kernel, linux-pm,
linux-arm-kernel, linux-mediatek, kernel, Laura Nao
Add LVTS driver support for MT8196.
Signed-off-by: Laura Nao <laura.nao@collabora.com>
---
drivers/thermal/mediatek/lvts_thermal.c | 166 ++++++++++++++++++++++++
1 file changed, 166 insertions(+)
diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c
index 81c8309ff9df..1242d0bf6f8b 100644
--- a/drivers/thermal/mediatek/lvts_thermal.c
+++ b/drivers/thermal/mediatek/lvts_thermal.c
@@ -92,6 +92,10 @@
#define LVTS_COEFF_B_MT8195 250460
#define LVTS_COEFF_A_MT7988 -204650
#define LVTS_COEFF_B_MT7988 204650
+#define LVTS_COEFF_A_MT8196 391460
+#define LVTS_COEFF_B_MT8196 -391460
+
+#define LVTS_MSR_OFFSET_MT8196 -984
#define LVTS_MSR_IMMEDIATE_MODE 0
#define LVTS_MSR_FILTERED_MODE 1
@@ -755,6 +759,39 @@ static int lvts_sensor_init(struct device *dev, struct lvts_ctrl *lvts_ctrl,
* <-----ap--tc#3-----> <-----sensor#7-----> <-----sensor#8----->
* 0x40 | 0x41 | 0x42 | 0x43 | 0x44 | 0x45 | 0x46 | 0x47 | 0x48
*
+ * MT8196 :
+ * Stream index map for MCU Domain mt8196 :
+ *
+ * <-sensor#1--> <-sensor#0--> <-sensor#3--> <-sensor#2-->
+ * 0x04 | 0x05 | 0x06 | 0x07 | 0x08 | 0x09 | 0x0A | 0x0B
+ *
+ * <-sensor#5--> <-sensor#4--> <-sensor#7--> <-sensor#6-->
+ * 0x0C | 0x0D | 0x0E | 0x0F | 0x10 | 0x11 | 0x12 | 0x13
+ *
+ * <-sensor#9--> <-sensor#8--> <-sensor#11-> <-sensor#10->
+ * 0x14 | 0x15 | 0x16 | 0x17 | 0x18 | 0x19 | 0x1A | 0X1B
+ *
+ * <-sensor#13-> <-sensor#12-> <-sensor#15-> <-sensor#14->
+ * 0x1C | 0x1D | 0x1E | 0x1F | 0x20 | 0x21 | 0x22 | 0x23
+ *
+ * Stream index map for APU Domain mt8196 :
+ *
+ * <-sensor#1--> <-sensor#0--> <-sensor#3--> <-sensor#2-->
+ * 0x24 | 0x25 | 0x26 | 0x27 | 0x28 | 0x29 | 0x2A | 0x2B
+ *
+ * Stream index map for GPU Domain mt8196 :
+ *
+ * <-sensor#1--> <-sensor#0-->
+ * 0x2C | 0x2D | 0x2E | 0x2F
+ *
+ * Stream index map for AP Domain mt8196 :
+ *
+ * <-sensor#1--> <-sensor#0--> <-sensor#3--> <-sensor#2-->
+ * 0x30 | 0x31 | 0x32 | 0x33 | 0x34 | 0x35 | 0x36 | 0x37
+ *
+ * <-sensor#5--> <-sensor#4--> <-sensor#6--> <-sensor#7-->
+ * 0x38 | 0x39 | 0x3A | 0x3B | 0x3C | 0x3D | 0x3E | 0x3F
+ *
* Note: In some cases, values don't strictly follow a little endian ordering.
* The data description gives byte offsets constituting each calibration value
* for each sensor.
@@ -1808,6 +1845,103 @@ static const struct lvts_ctrl_data mt8195_lvts_ap_data_ctrl[] = {
}
};
+static const struct lvts_ctrl_data mt8196_lvts_mcu_data_ctrl[] = {
+ {
+ .lvts_sensor = {
+ { .dt_id = MT8196_MCU_MEDIUM_CPU6_0,
+ .cal_offsets = { 0x06, 0x07 } },
+ { .dt_id = MT8196_MCU_MEDIUM_CPU6_1,
+ .cal_offsets = { 0x04, 0x05 } },
+ { .dt_id = MT8196_MCU_DSU2,
+ .cal_offsets = { 0x0A, 0x0B } },
+ { .dt_id = MT8196_MCU_DSU3,
+ .cal_offsets = { 0x08, 0x09 } }
+ },
+ VALID_SENSOR_MAP(1, 1, 1, 1),
+ .offset = 0x0,
+ .mode = LVTS_MSR_ATP_MODE,
+ },
+ {
+ .lvts_sensor = {
+ { .dt_id = MT8196_MCU_LITTLE_CPU3,
+ .cal_offsets = { 0x0E, 0x0F } },
+ { .dt_id = MT8196_MCU_LITTLE_CPU0,
+ .cal_offsets = { 0x0C, 0x0D } },
+ { .dt_id = MT8196_MCU_LITTLE_CPU1,
+ .cal_offsets = { 0x12, 0x13 } },
+ { .dt_id = MT8196_MCU_LITTLE_CPU2,
+ .cal_offsets = { 0x10, 0x11 } }
+ },
+ VALID_SENSOR_MAP(1, 1, 1, 1),
+ .offset = 0x100,
+ .mode = LVTS_MSR_ATP_MODE,
+ },
+ {
+ .lvts_sensor = {
+ { .dt_id = MT8196_MCU_MEDIUM_CPU4_0,
+ .cal_offsets = { 0x16, 0x17 } },
+ { .dt_id = MT8196_MCU_MEDIUM_CPU4_1,
+ .cal_offsets = { 0x14, 0x15 } },
+ { .dt_id = MT8196_MCU_MEDIUM_CPU5_0,
+ .cal_offsets = { 0x1A, 0x1B } },
+ { .dt_id = MT8196_MCU_MEDIUM_CPU5_1,
+ .cal_offsets = { 0x18, 0x19 } }
+ },
+ VALID_SENSOR_MAP(1, 1, 1, 1),
+ .offset = 0x200,
+ .mode = LVTS_MSR_ATP_MODE,
+ },
+ {
+ .lvts_sensor = {
+ { .dt_id = MT8196_MCU_DSU0,
+ .cal_offsets = { 0x1E, 0x1F } },
+ { .dt_id = MT8196_MCU_DSU1,
+ .cal_offsets = { 0x1C, 0x1D } },
+ { .dt_id = MT8196_MCU_BIG_CPU7_0,
+ .cal_offsets = { 0x22, 0x23 } },
+ { .dt_id = MT8196_MCU_BIG_CPU7_1,
+ .cal_offsets = { 0x20, 0x21 } }
+ },
+ VALID_SENSOR_MAP(1, 1, 1, 1),
+ .offset = 0x300,
+ .mode = LVTS_MSR_ATP_MODE,
+ }
+};
+
+static const struct lvts_ctrl_data mt8196_lvts_ap_data_ctrl[] = {
+ {
+ .lvts_sensor = {
+ { .dt_id = MT8196_AP_TOP0,
+ .cal_offsets = { 0x32, 0x33 } },
+ { .dt_id = MT8196_AP_TOP1,
+ .cal_offsets = { 0x30, 0x31 } },
+ { .dt_id = MT8196_AP_TOP2,
+ .cal_offsets = { 0x36, 0x37 } },
+ { .dt_id = MT8196_AP_TOP3,
+ .cal_offsets = { 0x34, 0x35 } }
+ },
+ VALID_SENSOR_MAP(1, 1, 1, 1),
+ .offset = 0x0,
+ .mode = LVTS_MSR_ATP_MODE,
+ },
+ {
+ .lvts_sensor = {
+ { .dt_id = MT8196_AP_BOT0,
+ .cal_offsets = { 0x3A, 0x3B } },
+ { .dt_id = MT8196_AP_BOT1,
+ .cal_offsets = { 0x38, 0x39 } },
+ { .dt_id = MT8196_AP_BOT2,
+ .cal_offsets = { 0x3E, 0x3F } },
+ { .dt_id = MT8196_AP_BOT3,
+ .cal_offsets = { 0x3C, 0x3D } }
+ },
+ VALID_SENSOR_MAP(1, 1, 1, 1),
+ .offset = 0x100,
+ .mode = LVTS_MSR_ATP_MODE,
+ }
+};
+
+
static const struct lvts_data mt7988_lvts_ap_data = {
.lvts_ctrl = mt7988_lvts_ap_data_ctrl,
.num_lvts_ctrl = ARRAY_SIZE(mt7988_lvts_ap_data_ctrl),
@@ -1919,6 +2053,36 @@ static const struct lvts_data mt8195_lvts_ap_data = {
}
};
+static const struct lvts_data mt8196_lvts_mcu_data = {
+ .lvts_ctrl = mt8196_lvts_mcu_data_ctrl,
+ .num_lvts_ctrl = ARRAY_SIZE(mt8196_lvts_mcu_data_ctrl),
+ .temp_factor = LVTS_COEFF_A_MT8196,
+ .temp_offset = LVTS_COEFF_B_MT8196,
+ .gt_calib_bit_offset = 0,
+ .def_calibration = 14437,
+ .num_cal_offsets = 2,
+ .msr_offset = LVTS_MSR_OFFSET_MT8196,
+ .ops = {
+ .lvts_raw_to_temp = lvts_raw_to_temp,
+ .lvts_temp_to_raw = lvts_temp_to_raw_v2,
+ }
+};
+
+static const struct lvts_data mt8196_lvts_ap_data = {
+ .lvts_ctrl = mt8196_lvts_ap_data_ctrl,
+ .num_lvts_ctrl = ARRAY_SIZE(mt8196_lvts_ap_data_ctrl),
+ .temp_factor = LVTS_COEFF_A_MT8196,
+ .temp_offset = LVTS_COEFF_B_MT8196,
+ .gt_calib_bit_offset = 0,
+ .def_calibration = 14437,
+ .num_cal_offsets = 2,
+ .msr_offset = LVTS_MSR_OFFSET_MT8196,
+ .ops = {
+ .lvts_raw_to_temp = lvts_raw_to_temp,
+ .lvts_temp_to_raw = lvts_temp_to_raw_v2,
+ }
+};
+
static const struct of_device_id lvts_of_match[] = {
{ .compatible = "mediatek,mt7988-lvts-ap", .data = &mt7988_lvts_ap_data },
{ .compatible = "mediatek,mt8186-lvts", .data = &mt8186_lvts_data },
@@ -1928,6 +2092,8 @@ static const struct of_device_id lvts_of_match[] = {
{ .compatible = "mediatek,mt8192-lvts-ap", .data = &mt8192_lvts_ap_data },
{ .compatible = "mediatek,mt8195-lvts-mcu", .data = &mt8195_lvts_mcu_data },
{ .compatible = "mediatek,mt8195-lvts-ap", .data = &mt8195_lvts_ap_data },
+ { .compatible = "mediatek,mt8196-lvts-mcu", .data = &mt8196_lvts_mcu_data },
+ { .compatible = "mediatek,mt8196-lvts-ap", .data = &mt8196_lvts_ap_data },
{},
};
MODULE_DEVICE_TABLE(of, lvts_of_match);
--
2.39.5
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 9/9] dt-bindings: nvmem: mediatek: efuse: Add support for MT8196
2025-07-21 8:14 [PATCH 0/9] Add thermal sensor driver support for Mediatek MT8196 Laura Nao
` (7 preceding siblings ...)
2025-07-21 8:14 ` [PATCH 8/9] thermal/drivers/mediatek/lvts_thermal: Add MT8196 support Laura Nao
@ 2025-07-21 8:14 ` Laura Nao
2025-07-22 7:23 ` Krzysztof Kozlowski
2025-07-22 9:04 ` AngeloGioacchino Del Regno
2025-07-22 7:40 ` [PATCH 0/9] Add thermal sensor driver support for Mediatek MT8196 Chen-Yu Tsai
9 siblings, 2 replies; 21+ messages in thread
From: Laura Nao @ 2025-07-21 8:14 UTC (permalink / raw)
To: srini, robh, krzk+dt, conor+dt, rafael, daniel.lezcano, rui.zhang,
lukasz.luba, matthias.bgg, angelogioacchino.delregno
Cc: nfraprado, arnd, colin.i.king, u.kleine-koenig, andrew-ct.chen,
lala.lin, bchihi, frank-w, devicetree, linux-kernel, linux-pm,
linux-arm-kernel, linux-mediatek, kernel, Laura Nao
Add compatible for MT8196 SoC.
Signed-off-by: Laura Nao <laura.nao@collabora.com>
---
Documentation/devicetree/bindings/nvmem/mediatek,efuse.yaml | 1 +
1 file changed, 1 insertion(+)
diff --git a/Documentation/devicetree/bindings/nvmem/mediatek,efuse.yaml b/Documentation/devicetree/bindings/nvmem/mediatek,efuse.yaml
index 32b8c1eb4e80..e209a1132a26 100644
--- a/Documentation/devicetree/bindings/nvmem/mediatek,efuse.yaml
+++ b/Documentation/devicetree/bindings/nvmem/mediatek,efuse.yaml
@@ -37,6 +37,7 @@ properties:
- mediatek,mt8188-efuse
- mediatek,mt8192-efuse
- mediatek,mt8195-efuse
+ - mediatek,mt8196-efuse
- mediatek,mt8516-efuse
- const: mediatek,efuse
- const: mediatek,mt8173-efuse
--
2.39.5
^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [PATCH 3/9] thermal/drivers/mediatek/lvts: Guard against zero temp_factor in lvts_raw_to_temp
2025-07-21 8:14 ` [PATCH 3/9] thermal/drivers/mediatek/lvts: Guard against zero temp_factor in lvts_raw_to_temp Laura Nao
@ 2025-07-21 10:08 ` Chen-Yu Tsai
2025-07-22 9:57 ` Laura Nao
0 siblings, 1 reply; 21+ messages in thread
From: Chen-Yu Tsai @ 2025-07-21 10:08 UTC (permalink / raw)
To: Laura Nao
Cc: srini, robh, krzk+dt, conor+dt, rafael, daniel.lezcano, rui.zhang,
lukasz.luba, matthias.bgg, angelogioacchino.delregno,
andrew-ct.chen, lala.lin, arnd, linux-pm, linux-kernel, nfraprado,
devicetree, u.kleine-koenig, linux-arm-kernel, linux-mediatek,
kernel, colin.i.king, bchihi
On Mon, Jul 21, 2025 at 4:26 PM Laura Nao <laura.nao@collabora.com> wrote:
>
> Add a guard against zero temp_factor in lvts_raw_to_temp() to prevent
> division by zero and ensure safe conversion.
>
> Fixes: 6725a29321e4 ("thermal/drivers/mediatek/lvts_thermal: Make coeff configurable")
> Signed-off-by: Laura Nao <laura.nao@collabora.com>
Code wise,
Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>
However I assume this would only happen with bad platform data? The
factor should _never_ be zero. Maybe also issue a warning in the probe
function?
ChenYu
> ---
> drivers/thermal/mediatek/lvts_thermal.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c
> index 8d5259b9d03b..b80c2929ae74 100644
> --- a/drivers/thermal/mediatek/lvts_thermal.c
> +++ b/drivers/thermal/mediatek/lvts_thermal.c
> @@ -280,11 +280,14 @@ static int lvts_raw_to_temp(u32 raw_temp, int temp_factor)
>
> static u32 lvts_temp_to_raw(int temperature, int temp_factor)
> {
> - u32 raw_temp = ((s64)(golden_temp_offset - temperature)) << 14;
> + u32 raw_temp;
>
> - raw_temp = div_s64(raw_temp, -temp_factor);
> + if (temp_factor == 0)
> + return temperature;
>
> - return raw_temp;
> + raw_temp = ((s64)(golden_temp_offset - temperature)) << 14;
> +
> + return div_s64(raw_temp, -temp_factor);
> }
>
> static int lvts_get_temp(struct thermal_zone_device *tz, int *temp)
> --
> 2.39.5
>
>
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 6/9] thermal/drivers/mediatek/lvts: Add support for ATP mode
2025-07-21 8:14 ` [PATCH 6/9] thermal/drivers/mediatek/lvts: Add support for ATP mode Laura Nao
@ 2025-07-21 11:09 ` Chen-Yu Tsai
0 siblings, 0 replies; 21+ messages in thread
From: Chen-Yu Tsai @ 2025-07-21 11:09 UTC (permalink / raw)
To: Laura Nao
Cc: srini, robh, krzk+dt, conor+dt, rafael, daniel.lezcano, rui.zhang,
lukasz.luba, matthias.bgg, angelogioacchino.delregno,
andrew-ct.chen, lala.lin, arnd, linux-pm, linux-kernel, nfraprado,
devicetree, u.kleine-koenig, linux-arm-kernel, linux-mediatek,
kernel, colin.i.king, bchihi
On Mon, Jul 21, 2025 at 4:33 PM Laura Nao <laura.nao@collabora.com> wrote:
>
> MT8196/MT6991 uses ATP (Abnormal Temperature Prevention) mode to detect
> abnormal temperature conditions, which involves reading temperature data
> from a dedicated set of registers separate from the ones used for
> immediate and filtered modes.
>
> Add support for ATP mode and its relative registers to ensure accurate
> temperature readings and proper thermal management on MT8196/MT6991
> devices.
>
> Signed-off-by: Laura Nao <laura.nao@collabora.com>
> ---
> drivers/thermal/mediatek/lvts_thermal.c | 34 ++++++++++++++++++++++---
> 1 file changed, 31 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c
> index 3c34956e37c1..8f9da0d5b886 100644
> --- a/drivers/thermal/mediatek/lvts_thermal.c
> +++ b/drivers/thermal/mediatek/lvts_thermal.c
> @@ -44,6 +44,10 @@
> #define LVTS_EDATA01(__base) (__base + 0x0058)
> #define LVTS_EDATA02(__base) (__base + 0x005C)
> #define LVTS_EDATA03(__base) (__base + 0x0060)
> +#define LVTS_ATP0(__base) (__base + 0x0070)
> +#define LVTS_ATP1(__base) (__base + 0x0074)
> +#define LVTS_ATP2(__base) (__base + 0x0078)
> +#define LVTS_ATP3(__base) (__base + 0x007C)
> #define LVTS_MSR0(__base) (__base + 0x0090)
> #define LVTS_MSR1(__base) (__base + 0x0094)
> #define LVTS_MSR2(__base) (__base + 0x0098)
> @@ -90,6 +94,7 @@
>
> #define LVTS_MSR_IMMEDIATE_MODE 0
> #define LVTS_MSR_FILTERED_MODE 1
> +#define LVTS_MSR_ATP_MODE 2
Nit: I suggest changing this to an enum since they are related, and
also because these are artificial (unrelated to hardware values).
Otherwise,
Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>
> #define LVTS_MSR_READ_TIMEOUT_US 400
> #define LVTS_MSR_READ_WAIT_US (LVTS_MSR_READ_TIMEOUT_US / 2)
> @@ -207,6 +212,10 @@ static const struct debugfs_reg32 lvts_regs[] = {
> LVTS_DEBUG_FS_REGS(LVTS_EDATA01),
> LVTS_DEBUG_FS_REGS(LVTS_EDATA02),
> LVTS_DEBUG_FS_REGS(LVTS_EDATA03),
> + LVTS_DEBUG_FS_REGS(LVTS_ATP0),
> + LVTS_DEBUG_FS_REGS(LVTS_ATP1),
> + LVTS_DEBUG_FS_REGS(LVTS_ATP2),
> + LVTS_DEBUG_FS_REGS(LVTS_ATP3),
> LVTS_DEBUG_FS_REGS(LVTS_MSR0),
> LVTS_DEBUG_FS_REGS(LVTS_MSR1),
> LVTS_DEBUG_FS_REGS(LVTS_MSR2),
> @@ -621,6 +630,13 @@ static int lvts_sensor_init(struct device *dev, struct lvts_ctrl *lvts_ctrl,
> LVTS_IMMD3(lvts_ctrl->base)
> };
>
> + void __iomem *atp_regs[] = {
> + LVTS_ATP0(lvts_ctrl->base),
> + LVTS_ATP1(lvts_ctrl->base),
> + LVTS_ATP2(lvts_ctrl->base),
> + LVTS_ATP3(lvts_ctrl->base)
> + };
> +
> int i;
>
> lvts_for_each_valid_sensor(i, lvts_ctrl_data) {
> @@ -656,8 +672,20 @@ static int lvts_sensor_init(struct device *dev, struct lvts_ctrl *lvts_ctrl,
> /*
> * Each sensor has its own register address to read from.
> */
> - lvts_sensor[i].msr = lvts_ctrl_data->mode == LVTS_MSR_IMMEDIATE_MODE ?
> - imm_regs[i] : msr_regs[i];
> + switch (lvts_ctrl_data->mode) {
> + case LVTS_MSR_IMMEDIATE_MODE:
> + lvts_sensor[i].msr = imm_regs[i];
> + break;
> + case LVTS_MSR_FILTERED_MODE:
> + lvts_sensor[i].msr = msr_regs[i];
> + break;
> + case LVTS_MSR_ATP_MODE:
> + lvts_sensor[i].msr = atp_regs[i];
> + break;
> + default:
> + lvts_sensor[i].msr = imm_regs[i];
> + break;
> + }
>
> lvts_sensor[i].low_thresh = INT_MIN;
> lvts_sensor[i].high_thresh = INT_MIN;
> @@ -907,7 +935,7 @@ static void lvts_ctrl_monitor_enable(struct device *dev, struct lvts_ctrl *lvts_
> u32 sensor_map = 0;
> int i;
>
> - if (lvts_ctrl->mode != LVTS_MSR_FILTERED_MODE)
> + if (lvts_ctrl->mode == LVTS_MSR_IMMEDIATE_MODE)
> return;
>
> if (enable) {
> --
> 2.39.5
>
>
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 5/9] thermal/drivers/mediatek/lvts: Add lvts_temp_to_raw variant for positive temp_factor
2025-07-21 8:14 ` [PATCH 5/9] thermal/drivers/mediatek/lvts: Add lvts_temp_to_raw variant for positive temp_factor Laura Nao
@ 2025-07-21 11:12 ` Chen-Yu Tsai
2025-07-22 10:26 ` Laura Nao
0 siblings, 1 reply; 21+ messages in thread
From: Chen-Yu Tsai @ 2025-07-21 11:12 UTC (permalink / raw)
To: Laura Nao
Cc: srini, robh, krzk+dt, conor+dt, rafael, daniel.lezcano, rui.zhang,
lukasz.luba, matthias.bgg, angelogioacchino.delregno,
andrew-ct.chen, lala.lin, arnd, linux-pm, linux-kernel, nfraprado,
devicetree, u.kleine-koenig, linux-arm-kernel, linux-mediatek,
kernel, colin.i.king, bchihi
On Mon, Jul 21, 2025 at 4:31 PM Laura Nao <laura.nao@collabora.com> wrote:
>
> The current lvts_temp_to_raw() implementation assumes a negative
> temperature-to-raw slope (temp_factor), which holds for the SoCs
> currently supported by the driver. However, this assumption breaks on
> MT8196/MT6991, where the slope is positive.
I don't think that's really a problem. The formula is:
temp = (raw * factor) >> 14 + golden
If we move the terms around we get
((temp - golden) << 14) / factor = raw
Or
raw = ((golden - temp) << 14) / -factor
The calculations should work regardless of whether the factor is positive
or negative, as long as the intermediate and final values are within
the range of s64.
> Add a variant of the function that inverts the calculation logic
> accordingly. This ensures accurate raw value generation for temperature
> thresholds,avoiding spurious thermal interrupts or unintended hardware
> resets on MT8196/MT6991.
>
> Signed-off-by: Laura Nao <laura.nao@collabora.com>
> ---
> drivers/thermal/mediatek/lvts_thermal.c | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
> diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c
> index db83137c7537..3c34956e37c1 100644
> --- a/drivers/thermal/mediatek/lvts_thermal.c
> +++ b/drivers/thermal/mediatek/lvts_thermal.c
> @@ -296,6 +296,18 @@ static u32 lvts_temp_to_raw(int temperature, int temp_factor)
> return div_s64(raw_temp, -temp_factor);
> }
>
> +static u32 lvts_temp_to_raw_v2(int temperature, int temp_factor)
> +{
> + u32 raw_temp;
> +
> + if (temp_factor == 0)
> + return temperature;
> +
> + raw_temp = temperature - golden_temp_offset;
> +
> + return div_s64((s64)temp_factor << 14, raw_temp);
> +}
Here you have
raw = (factor << 14) / (temp - golden)
which, barring integer arithmetic limitations, is actually the
multiplicative inverse of the original version.
So I think the commit message is misleading. It's not negative or
positive that matters, but that the hardware expects the
multiplicative inverse in this version.
(or the downstream code is just botched.)
ChenYu
> +
> static int lvts_get_temp(struct thermal_zone_device *tz, int *temp)
> {
> struct lvts_sensor *lvts_sensor = thermal_zone_device_priv(tz);
> --
> 2.39.5
>
>
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 1/9] dt-bindings: thermal: mediatek: Add LVTS thermal controller support for MT8196
2025-07-21 8:14 ` [PATCH 1/9] dt-bindings: thermal: mediatek: Add LVTS thermal controller support for MT8196 Laura Nao
@ 2025-07-22 7:20 ` Krzysztof Kozlowski
0 siblings, 0 replies; 21+ messages in thread
From: Krzysztof Kozlowski @ 2025-07-22 7:20 UTC (permalink / raw)
To: Laura Nao
Cc: srini, robh, krzk+dt, conor+dt, rafael, daniel.lezcano, rui.zhang,
lukasz.luba, matthias.bgg, angelogioacchino.delregno, nfraprado,
arnd, colin.i.king, u.kleine-koenig, andrew-ct.chen, lala.lin,
bchihi, frank-w, devicetree, linux-kernel, linux-pm,
linux-arm-kernel, linux-mediatek, kernel
On Mon, Jul 21, 2025 at 10:14:51AM +0200, Laura Nao wrote:
> Add LVTS thermal controller binding for MediaTek MT8196.
>
> Signed-off-by: Laura Nao <laura.nao@collabora.com>
> ---
> .../thermal/mediatek,lvts-thermal.yaml | 2 ++
> .../thermal/mediatek,lvts-thermal.h | 26 +++++++++++++++++++
> 2 files changed, 28 insertions(+)
Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 9/9] dt-bindings: nvmem: mediatek: efuse: Add support for MT8196
2025-07-21 8:14 ` [PATCH 9/9] dt-bindings: nvmem: mediatek: efuse: Add support for MT8196 Laura Nao
@ 2025-07-22 7:23 ` Krzysztof Kozlowski
2025-07-22 9:04 ` AngeloGioacchino Del Regno
1 sibling, 0 replies; 21+ messages in thread
From: Krzysztof Kozlowski @ 2025-07-22 7:23 UTC (permalink / raw)
To: Laura Nao
Cc: srini, robh, krzk+dt, conor+dt, rafael, daniel.lezcano, rui.zhang,
lukasz.luba, matthias.bgg, angelogioacchino.delregno, nfraprado,
arnd, colin.i.king, u.kleine-koenig, andrew-ct.chen, lala.lin,
bchihi, frank-w, devicetree, linux-kernel, linux-pm,
linux-arm-kernel, linux-mediatek, kernel
On Mon, Jul 21, 2025 at 10:14:59AM +0200, Laura Nao wrote:
> Add compatible for MT8196 SoC.
This we see from diff. Describe the hardware. Is it compatible with
anything existing? No changes in the driver, so maybe this should use
8195 as fallback?
There are some differences in existing Mediatek efuses, so seeing here
empty commit only raises questions.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 0/9] Add thermal sensor driver support for Mediatek MT8196
2025-07-21 8:14 [PATCH 0/9] Add thermal sensor driver support for Mediatek MT8196 Laura Nao
` (8 preceding siblings ...)
2025-07-21 8:14 ` [PATCH 9/9] dt-bindings: nvmem: mediatek: efuse: Add support for MT8196 Laura Nao
@ 2025-07-22 7:40 ` Chen-Yu Tsai
2025-07-22 9:50 ` Laura Nao
9 siblings, 1 reply; 21+ messages in thread
From: Chen-Yu Tsai @ 2025-07-22 7:40 UTC (permalink / raw)
To: Laura Nao
Cc: srini, robh, krzk+dt, conor+dt, rafael, daniel.lezcano, rui.zhang,
lukasz.luba, matthias.bgg, angelogioacchino.delregno,
andrew-ct.chen, lala.lin, arnd, linux-pm, linux-kernel, nfraprado,
devicetree, u.kleine-koenig, linux-arm-kernel, linux-mediatek,
kernel, colin.i.king, bchihi
Hi,
On Mon, Jul 21, 2025 at 4:18 PM Laura Nao <laura.nao@collabora.com> wrote:
>
> This patch series extends the MediaTek LVTS thermal driver to support the
> MT8196 SoC.
>
> MT8196 uses a positive temp_factor for temperature conversion, requiring
> slight adjustments in the conversion logic.
>
> To support this, the series introduces:
>
> - A new struct lvts_platform_ops to allow platform-specific
> conversion logic between raw sensor values and temperature
> - A variant of the lvts_temp_to_raw() implementation for SoCs with positive
> temp_factor values
> - Platform data and controller definitions for MT8196
I see the GPU and APU thermal sensors were left out. Was there a reason
for this?
Thanks
ChenYu
> Laura Nao (9):
> dt-bindings: thermal: mediatek: Add LVTS thermal controller support
> for MT8196
> thermal/drivers/mediatek/lvts: Make number of calibration offsets
> configurable
> thermal/drivers/mediatek/lvts: Guard against zero temp_factor in
> lvts_raw_to_temp
> thermal: mediatek: lvts: Add platform ops to support alternative
> conversion logic
> thermal/drivers/mediatek/lvts: Add lvts_temp_to_raw variant for
> positive temp_factor
> thermal/drivers/mediatek/lvts: Add support for ATP mode
> thermal/drivers/mediatek/lvts: Support MSR offset for 16-bit
> calibration data
> thermal/drivers/mediatek/lvts_thermal: Add MT8196 support
> dt-bindings: nvmem: mediatek: efuse: Add support for MT8196
>
> .../bindings/nvmem/mediatek,efuse.yaml | 1 +
> .../thermal/mediatek,lvts-thermal.yaml | 2 +
> drivers/thermal/mediatek/lvts_thermal.c | 315 ++++++++++++++++--
> .../thermal/mediatek,lvts-thermal.h | 26 ++
> 4 files changed, 325 insertions(+), 19 deletions(-)
>
> --
> 2.39.5
>
>
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 9/9] dt-bindings: nvmem: mediatek: efuse: Add support for MT8196
2025-07-21 8:14 ` [PATCH 9/9] dt-bindings: nvmem: mediatek: efuse: Add support for MT8196 Laura Nao
2025-07-22 7:23 ` Krzysztof Kozlowski
@ 2025-07-22 9:04 ` AngeloGioacchino Del Regno
2025-07-22 10:37 ` Laura Nao
1 sibling, 1 reply; 21+ messages in thread
From: AngeloGioacchino Del Regno @ 2025-07-22 9:04 UTC (permalink / raw)
To: Laura Nao, srini, robh, krzk+dt, conor+dt, rafael, daniel.lezcano,
rui.zhang, lukasz.luba, matthias.bgg
Cc: nfraprado, arnd, colin.i.king, u.kleine-koenig, andrew-ct.chen,
lala.lin, bchihi, frank-w, devicetree, linux-kernel, linux-pm,
linux-arm-kernel, linux-mediatek, kernel
Il 21/07/25 10:14, Laura Nao ha scritto:
> Add compatible for MT8196 SoC.
>
This is compatible with MT8186's layout - not with the others - and
besides: "mediatek,efuse" is deprecated.
Adding something to deprecated bindings is not even really permitted (unless
there's a *very* good reason to, which you definitely don't have in this case).
Also, this commit has no description - repeating the same as the title adds
no information and doesn't help at all.
NACK.
Regards,
Angelo
> Signed-off-by: Laura Nao <laura.nao@collabora.com>
> ---
> Documentation/devicetree/bindings/nvmem/mediatek,efuse.yaml | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/Documentation/devicetree/bindings/nvmem/mediatek,efuse.yaml b/Documentation/devicetree/bindings/nvmem/mediatek,efuse.yaml
> index 32b8c1eb4e80..e209a1132a26 100644
> --- a/Documentation/devicetree/bindings/nvmem/mediatek,efuse.yaml
> +++ b/Documentation/devicetree/bindings/nvmem/mediatek,efuse.yaml
> @@ -37,6 +37,7 @@ properties:
> - mediatek,mt8188-efuse
> - mediatek,mt8192-efuse
> - mediatek,mt8195-efuse
> + - mediatek,mt8196-efuse
> - mediatek,mt8516-efuse
> - const: mediatek,efuse
> - const: mediatek,mt8173-efuse
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 0/9] Add thermal sensor driver support for Mediatek MT8196
2025-07-22 7:40 ` [PATCH 0/9] Add thermal sensor driver support for Mediatek MT8196 Chen-Yu Tsai
@ 2025-07-22 9:50 ` Laura Nao
0 siblings, 0 replies; 21+ messages in thread
From: Laura Nao @ 2025-07-22 9:50 UTC (permalink / raw)
To: wenst
Cc: andrew-ct.chen, angelogioacchino.delregno, arnd, bchihi,
colin.i.king, conor+dt, daniel.lezcano, devicetree, kernel,
krzk+dt, lala.lin, laura.nao, linux-arm-kernel, linux-kernel,
linux-mediatek, linux-pm, lukasz.luba, matthias.bgg, nfraprado,
rafael, robh, rui.zhang, srini, u.kleine-koenig
Hi ChenYu,
On 7/22/25 09:40, Chen-Yu Tsai wrote:
> Hi,
>
> On Mon, Jul 21, 2025 at 4:18 PM Laura Nao <laura.nao@collabora.com> wrote:
>>
>> This patch series extends the MediaTek LVTS thermal driver to support the
>> MT8196 SoC.
>>
>> MT8196 uses a positive temp_factor for temperature conversion, requiring
>> slight adjustments in the conversion logic.
>>
>> To support this, the series introduces:
>>
>> - A new struct lvts_platform_ops to allow platform-specific
>> conversion logic between raw sensor values and temperature
>> - A variant of the lvts_temp_to_raw() implementation for SoCs with positive
>> temp_factor values
>> - Platform data and controller definitions for MT8196
>
> I see the GPU and APU thermal sensors were left out. Was there a reason
> for this?
>
Based on my testing, the GPU and APU sensors are not functional at this
stage - the APU controller returns an invalid ID, and the GPU sensors
report invalid values. I suspect that both the GPU and APU need to be
fully initialized for the sensors to operate correctly, so I'm planning
to upstream support for those at a later stage.
Best,
Laura
> Thanks
> ChenYu
>
>> Laura Nao (9):
>> dt-bindings: thermal: mediatek: Add LVTS thermal controller support
>> for MT8196
>> thermal/drivers/mediatek/lvts: Make number of calibration offsets
>> configurable
>> thermal/drivers/mediatek/lvts: Guard against zero temp_factor in
>> lvts_raw_to_temp
>> thermal: mediatek: lvts: Add platform ops to support alternative
>> conversion logic
>> thermal/drivers/mediatek/lvts: Add lvts_temp_to_raw variant for
>> positive temp_factor
>> thermal/drivers/mediatek/lvts: Add support for ATP mode
>> thermal/drivers/mediatek/lvts: Support MSR offset for 16-bit
>> calibration data
>> thermal/drivers/mediatek/lvts_thermal: Add MT8196 support
>> dt-bindings: nvmem: mediatek: efuse: Add support for MT8196
>>
>> .../bindings/nvmem/mediatek,efuse.yaml | 1 +
>> .../thermal/mediatek,lvts-thermal.yaml | 2 +
>> drivers/thermal/mediatek/lvts_thermal.c | 315 ++++++++++++++++--
>> .../thermal/mediatek,lvts-thermal.h | 26 ++
>> 4 files changed, 325 insertions(+), 19 deletions(-)
>>
>> --
>> 2.39.5
>>
>>
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 3/9] thermal/drivers/mediatek/lvts: Guard against zero temp_factor in lvts_raw_to_temp
2025-07-21 10:08 ` Chen-Yu Tsai
@ 2025-07-22 9:57 ` Laura Nao
0 siblings, 0 replies; 21+ messages in thread
From: Laura Nao @ 2025-07-22 9:57 UTC (permalink / raw)
To: wenst
Cc: andrew-ct.chen, angelogioacchino.delregno, arnd, bchihi,
colin.i.king, conor+dt, daniel.lezcano, devicetree, kernel,
krzk+dt, lala.lin, laura.nao, linux-arm-kernel, linux-kernel,
linux-mediatek, linux-pm, lukasz.luba, matthias.bgg, nfraprado,
rafael, robh, rui.zhang, srini, u.kleine-koenig
On 7/21/25 12:08, Chen-Yu Tsai wrote:
> On Mon, Jul 21, 2025 at 4:26 PM Laura Nao <laura.nao@collabora.com> wrote:
>>
>> Add a guard against zero temp_factor in lvts_raw_to_temp() to prevent
>> division by zero and ensure safe conversion.
>>
>> Fixes: 6725a29321e4 ("thermal/drivers/mediatek/lvts_thermal: Make coeff configurable")
>> Signed-off-by: Laura Nao <laura.nao@collabora.com>
>
> Code wise,
>
> Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>
>
> However I assume this would only happen with bad platform data? The
> factor should _never_ be zero. Maybe also issue a warning in the probe
> function?
>
Yes, this should only occur with incorrect platform data. Adding a
warning in the probe function sounds like a good idea to catch
any misconfiguration early. I’ll include that in the next revision.
Thanks,
Laura
> ChenYu
>
>> ---
>> drivers/thermal/mediatek/lvts_thermal.c | 9 ++++++---
>> 1 file changed, 6 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c
>> index 8d5259b9d03b..b80c2929ae74 100644
>> --- a/drivers/thermal/mediatek/lvts_thermal.c
>> +++ b/drivers/thermal/mediatek/lvts_thermal.c
>> @@ -280,11 +280,14 @@ static int lvts_raw_to_temp(u32 raw_temp, int temp_factor)
>>
>> static u32 lvts_temp_to_raw(int temperature, int temp_factor)
>> {
>> - u32 raw_temp = ((s64)(golden_temp_offset - temperature)) << 14;
>> + u32 raw_temp;
>>
>> - raw_temp = div_s64(raw_temp, -temp_factor);
>> + if (temp_factor == 0)
>> + return temperature;
>>
>> - return raw_temp;
>> + raw_temp = ((s64)(golden_temp_offset - temperature)) << 14;
>> +
>> + return div_s64(raw_temp, -temp_factor);
>> }
>>
>> static int lvts_get_temp(struct thermal_zone_device *tz, int *temp)
>> --
>> 2.39.5
>>
>>
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 5/9] thermal/drivers/mediatek/lvts: Add lvts_temp_to_raw variant for positive temp_factor
2025-07-21 11:12 ` Chen-Yu Tsai
@ 2025-07-22 10:26 ` Laura Nao
0 siblings, 0 replies; 21+ messages in thread
From: Laura Nao @ 2025-07-22 10:26 UTC (permalink / raw)
To: wenst
Cc: andrew-ct.chen, angelogioacchino.delregno, arnd, bchihi,
colin.i.king, conor+dt, daniel.lezcano, devicetree, kernel,
krzk+dt, lala.lin, laura.nao, linux-arm-kernel, linux-kernel,
linux-mediatek, linux-pm, lukasz.luba, matthias.bgg, nfraprado,
rafael, robh, rui.zhang, srini, u.kleine-koenig
On 7/21/25 13:12, Chen-Yu Tsai wrote:
> On Mon, Jul 21, 2025 at 4:31 PM Laura Nao <laura.nao@collabora.com> wrote:
>>
>> The current lvts_temp_to_raw() implementation assumes a negative
>> temperature-to-raw slope (temp_factor), which holds for the SoCs
>> currently supported by the driver. However, this assumption breaks on
>> MT8196/MT6991, where the slope is positive.
>
> I don't think that's really a problem. The formula is:
>
> temp = (raw * factor) >> 14 + golden
>
> If we move the terms around we get
>
> ((temp - golden) << 14) / factor = raw
>
> Or
>
> raw = ((golden - temp) << 14) / -factor
>
>
> The calculations should work regardless of whether the factor is positive
> or negative, as long as the intermediate and final values are within
> the range of s64.
>
>> Add a variant of the function that inverts the calculation logic
>> accordingly. This ensures accurate raw value generation for temperature
>> thresholds,avoiding spurious thermal interrupts or unintended hardware
>> resets on MT8196/MT6991.
>>
>> Signed-off-by: Laura Nao <laura.nao@collabora.com>
>> ---
>> drivers/thermal/mediatek/lvts_thermal.c | 12 ++++++++++++
>> 1 file changed, 12 insertions(+)
>>
>> diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c
>> index db83137c7537..3c34956e37c1 100644
>> --- a/drivers/thermal/mediatek/lvts_thermal.c
>> +++ b/drivers/thermal/mediatek/lvts_thermal.c
>> @@ -296,6 +296,18 @@ static u32 lvts_temp_to_raw(int temperature, int temp_factor)
>> return div_s64(raw_temp, -temp_factor);
>> }
>>
>> +static u32 lvts_temp_to_raw_v2(int temperature, int temp_factor)
>> +{
>> + u32 raw_temp;
>> +
>> + if (temp_factor == 0)
>> + return temperature;
>> +
>> + raw_temp = temperature - golden_temp_offset;
>> +
>> + return div_s64((s64)temp_factor << 14, raw_temp);
>> +}
>
> Here you have
>
> raw = (factor << 14) / (temp - golden)
>
> which, barring integer arithmetic limitations, is actually the
> multiplicative inverse of the original version.
>
> So I think the commit message is misleading. It's not negative or
> positive that matters, but that the hardware expects the
> multiplicative inverse in this version.
>
> (or the downstream code is just botched.)
>
Right - the positive temp_factor on MT8196 is one distinction from older
SoCs, and I initially assumed that was the reason a different conversion
formula was needed. That assumption was partly based on the original
lvts_temp_to_raw() implementation, which assigns
((s64)(golden_temp_offset - temperature) << 14) to a u32, losing the
sign when golden_temp_offset is negative. However, even correcting that
to preserve the sign doesn't make the function work on MT8196 as it
still requires using the multiplicative inverse form of the formula.
I'll reword the commit message to clarify this.
Thanks!
Laura
> ChenYu
>
>> +
>> static int lvts_get_temp(struct thermal_zone_device *tz, int *temp)
>> {
>> struct lvts_sensor *lvts_sensor = thermal_zone_device_priv(tz);
>> --
>> 2.39.5
>>
>>
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 9/9] dt-bindings: nvmem: mediatek: efuse: Add support for MT8196
2025-07-22 9:04 ` AngeloGioacchino Del Regno
@ 2025-07-22 10:37 ` Laura Nao
0 siblings, 0 replies; 21+ messages in thread
From: Laura Nao @ 2025-07-22 10:37 UTC (permalink / raw)
To: angelogioacchino.delregno
Cc: andrew-ct.chen, arnd, bchihi, colin.i.king, conor+dt,
daniel.lezcano, devicetree, frank-w, kernel, krzk+dt, lala.lin,
laura.nao, linux-arm-kernel, linux-kernel, linux-mediatek,
linux-pm, lukasz.luba, matthias.bgg, nfraprado, rafael, robh,
rui.zhang, srini, u.kleine-koenig
On 7/22/25 11:04, AngeloGioacchino Del Regno wrote:
> Il 21/07/25 10:14, Laura Nao ha scritto:
>> Add compatible for MT8196 SoC.
>>
>
> This is compatible with MT8186's layout - not with the others - and
> besides: "mediatek,efuse" is deprecated.
>
> Adding something to deprecated bindings is not even really permitted (unless
> there's a *very* good reason to, which you definitely don't have in this case).
>
> Also, this commit has no description - repeating the same as the title adds
> no information and doesn't help at all.
>
> NACK.
>
Got it, thanks both for the feedback - I'll fix this in the next
revision.
Best,
Laura
> Regards,
> Angelo
>
>> Signed-off-by: Laura Nao <laura.nao@collabora.com>
>> ---
>> Documentation/devicetree/bindings/nvmem/mediatek,efuse.yaml | 1 +
>> 1 file changed, 1 insertion(+)
>>
>> diff --git a/Documentation/devicetree/bindings/nvmem/mediatek,efuse.yaml b/Documentation/devicetree/bindings/nvmem/mediatek,efuse.yaml
>> index 32b8c1eb4e80..e209a1132a26 100644
>> --- a/Documentation/devicetree/bindings/nvmem/mediatek,efuse.yaml
>> +++ b/Documentation/devicetree/bindings/nvmem/mediatek,efuse.yaml
>> @@ -37,6 +37,7 @@ properties:
>> - mediatek,mt8188-efuse
>> - mediatek,mt8192-efuse
>> - mediatek,mt8195-efuse
>> + - mediatek,mt8196-efuse
>> - mediatek,mt8516-efuse
>> - const: mediatek,efuse
>> - const: mediatek,mt8173-efuse
>
>
>
^ permalink raw reply [flat|nested] 21+ messages in thread
end of thread, other threads:[~2025-07-22 10:38 UTC | newest]
Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-21 8:14 [PATCH 0/9] Add thermal sensor driver support for Mediatek MT8196 Laura Nao
2025-07-21 8:14 ` [PATCH 1/9] dt-bindings: thermal: mediatek: Add LVTS thermal controller support for MT8196 Laura Nao
2025-07-22 7:20 ` Krzysztof Kozlowski
2025-07-21 8:14 ` [PATCH 2/9] thermal/drivers/mediatek/lvts: Make number of calibration offsets configurable Laura Nao
2025-07-21 8:14 ` [PATCH 3/9] thermal/drivers/mediatek/lvts: Guard against zero temp_factor in lvts_raw_to_temp Laura Nao
2025-07-21 10:08 ` Chen-Yu Tsai
2025-07-22 9:57 ` Laura Nao
2025-07-21 8:14 ` [PATCH 4/9] thermal: mediatek: lvts: Add platform ops to support alternative conversion logic Laura Nao
2025-07-21 8:14 ` [PATCH 5/9] thermal/drivers/mediatek/lvts: Add lvts_temp_to_raw variant for positive temp_factor Laura Nao
2025-07-21 11:12 ` Chen-Yu Tsai
2025-07-22 10:26 ` Laura Nao
2025-07-21 8:14 ` [PATCH 6/9] thermal/drivers/mediatek/lvts: Add support for ATP mode Laura Nao
2025-07-21 11:09 ` Chen-Yu Tsai
2025-07-21 8:14 ` [PATCH 7/9] thermal/drivers/mediatek/lvts: Support MSR offset for 16-bit calibration data Laura Nao
2025-07-21 8:14 ` [PATCH 8/9] thermal/drivers/mediatek/lvts_thermal: Add MT8196 support Laura Nao
2025-07-21 8:14 ` [PATCH 9/9] dt-bindings: nvmem: mediatek: efuse: Add support for MT8196 Laura Nao
2025-07-22 7:23 ` Krzysztof Kozlowski
2025-07-22 9:04 ` AngeloGioacchino Del Regno
2025-07-22 10:37 ` Laura Nao
2025-07-22 7:40 ` [PATCH 0/9] Add thermal sensor driver support for Mediatek MT8196 Chen-Yu Tsai
2025-07-22 9:50 ` Laura Nao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).