* [PATCH 0/4] thermal/drivers/mediatek: Sampling mode, mobile calibration & MT6797 support
@ 2026-12-03 12:03 Ben Grisdale via B4 Relay
2026-12-03 12:03 ` [PATCH 1/4] thermal/drivers/mediatek: Add efuse calibration support for mobile SoCs Ben Grisdale via B4 Relay
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Ben Grisdale via B4 Relay @ 2026-12-03 12:03 UTC (permalink / raw)
To: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
Matthias Brugger, AngeloGioacchino Del Regno, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Sascha Hauer
Cc: Roman Vivchar, linux-pm, linux-kernel, linux-arm-kernel,
linux-mediatek, devicetree, Ben Grisdale
This patch series adds support to the MediaTek auxadc thermal driver
for adjusting the sampling mode of sensors, mobile (MT67xx) efuse
calibration support and support for the auxadc thermal sensors
of the MT6797 SoC.
Currently, the auxadc thermal driver classifies "versions" of
thermal sensors as V1 - V3. For MT67xx, a new "V1.5" version is
added with the mobile specific efuse calibration handling. Aside
from the differences in efuse layout, the hardware seems closer
to V1 than V2 / V3.
Though, I myself am not at all sure if "V1.5" is a real version
that is formally defined by MediaTek. I only named it V1.5
since it is mostly V1 with a close to V2 efuse layout.
In the future it may be worth getting rid of the whole "versions"
classification altogether. Instead, move each existing version's
behaviour into an explicit field in platform data, i.e.
if (mt->conf->version != MTK_THERMAL_V1 &&
mt->conf->version != MTK_THERMAL_V1_5)
mtk_thermal_release_periodic_ts(mt, auxadc_base);
Would become
if (mt->conf->release_periodic_ts)
mtk_thermal_release_periodic_ts(mt, auxadc_base);
And the same would be done for efuse value extraction / raw_to_mcelsius,
that way, there would be no debate over which versions actually exist
and the driver would be able to support an arbitrary combination of
thermal characteristics for any platforms which are outliers from the
rest.
The associated device tree updates (adding the thermal controller
node) will be submitted in a later series that includes many fixups
for the existing MT6797 device tree.
This series has been tested on a 96boards Helio X20 development board.
Signed-off-by: Ben Grisdale <bengris32@protonmail.ch>
---
Ben Grisdale (2):
thermal/drivers/mediatek: Add efuse calibration support for mobile SoCs
thermal/drivers/mediatek: Add support for setting sampling mode per SoC
Roman Vivchar (2):
dt-bindings: thermal: mediatek,thermal: Add MT6797
thermal/drivers/mediatek: Add MT6797 support
.../bindings/thermal/mediatek,thermal.yaml | 1 +
drivers/thermal/mediatek/auxadc_thermal.c | 205 ++++++++++++++++++++-
2 files changed, 202 insertions(+), 4 deletions(-)
---
base-commit: 799dd936553182df5770dde7f38d94c8337df75a
change-id: 20261203-mt6797-thermal-support-b5dde780a7f8
Best regards,
--
Ben Grisdale <bengris32@protonmail.ch>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/4] thermal/drivers/mediatek: Add efuse calibration support for mobile SoCs
2026-12-03 12:03 [PATCH 0/4] thermal/drivers/mediatek: Sampling mode, mobile calibration & MT6797 support Ben Grisdale via B4 Relay
@ 2026-12-03 12:03 ` Ben Grisdale via B4 Relay
2026-12-03 12:28 ` sashiko-bot
2026-12-03 12:03 ` [PATCH 2/4] thermal/drivers/mediatek: Add support for setting sampling mode per SoC Ben Grisdale via B4 Relay
` (2 subsequent siblings)
3 siblings, 1 reply; 7+ messages in thread
From: Ben Grisdale via B4 Relay @ 2026-12-03 12:03 UTC (permalink / raw)
To: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
Matthias Brugger, AngeloGioacchino Del Regno, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Sascha Hauer
Cc: Roman Vivchar, linux-pm, linux-kernel, linux-arm-kernel,
linux-mediatek, devicetree, Ben Grisdale
From: Ben Grisdale <bengris32@protonmail.ch>
The efuse calibration layout on mobile MediaTek SoCs (MT67xx / MT68xx)
seems to sit in between the V1 and V2 layout. Whilst it overall is
mostly V1, it has additional entries for ADC_OE, which is otherwise
only seen in the V2 efuse layout [1] [2] [3] [4].
The downstream driver's implementation for raw_to_mcelsius uses a modified
version of the V2 calculations, with differences being: VTS value for each
sensor and slightly adjusted constants / slope correction.
Link: https://github.com/helio-x20/linux/blob/helio-x20/drivers/misc/mediatek/thermal/mt6797/src/mtk_tc.c#L326-L659 [1]
Link: https://github.com/NotKit/kernel-4.4-alps/blob/master/drivers/misc/mediatek/thermal/mt6757/src/mtk_tc.c#L257-L570 [2]
Link: https://github.com/LineageOS/android_kernel_xiaomi_mt6768/blob/lineage-24.0/drivers/misc/mediatek/thermal/mt6768/src/mtk_tc.c#L280-L643 [3]
Link: https://github.com/LineageOS/android_kernel_xiaomi_mt6768/blob/lineage-24.0/drivers/misc/mediatek/thermal/mt6873/src/mtk_tc.c#L212-L584 [4]
[rva333: select calibration value from the struct field instead]
Signed-off-by: Roman Vivchar <rva333@protonmail.com>
Signed-off-by: Ben Grisdale <bengris32@protonmail.ch>
---
drivers/thermal/mediatek/auxadc_thermal.c | 93 ++++++++++++++++++++++++++++++-
1 file changed, 91 insertions(+), 2 deletions(-)
diff --git a/drivers/thermal/mediatek/auxadc_thermal.c b/drivers/thermal/mediatek/auxadc_thermal.c
index 434f856c0f04..5b116cbb0af9 100644
--- a/drivers/thermal/mediatek/auxadc_thermal.c
+++ b/drivers/thermal/mediatek/auxadc_thermal.c
@@ -140,6 +140,12 @@
#define CALIB_BUF0_O_SLOPE_SIGN_V1(x) (((x) >> 7) & 0x1)
#define CALIB_BUF1_ID_V1(x) (((x) >> 9) & 0x1)
+/*
+ * Layout of the fuses providing the calibration data
+ * These macros could be used for MT67XX and MT68XX.
+ */
+#define CALIB_BUF1_ADC_OE_V1_5(x) (((x) >> 12) & 0x3ff)
+
/*
* Layout of the fuses providing the calibration data
* These macros could be used for MT7622.
@@ -180,6 +186,7 @@ enum {
enum mtk_thermal_version {
MTK_THERMAL_V1 = 1,
+ MTK_THERMAL_V1_5,
MTK_THERMAL_V2,
MTK_THERMAL_V3,
};
@@ -724,6 +731,37 @@ static int raw_to_mcelsius_v1(struct mtk_thermal *mt, int sensno, s32 raw)
return mt->degc_cali * 500 - tmp;
}
+static int raw_to_mcelsius_v1_5(struct mtk_thermal *mt, int sensno, s32 raw)
+{
+ s32 format_1;
+ s32 format_2;
+ s32 g_oe;
+ s32 g_gain;
+ s32 g_x_roomt;
+ s32 tmp;
+
+ if (raw == 0)
+ return 0;
+
+ raw &= 0xfff;
+ g_gain = 10000 + (((mt->adc_ge - 512) * 10000) >> 12);
+ g_oe = mt->adc_oe - 512;
+ format_1 = mt->vts[sensno] + 3350 - g_oe;
+ format_2 = (mt->degc_cali * 10) >> 1;
+ g_x_roomt = (((format_1 * 10000) >> 12) * 10000) / g_gain;
+
+ tmp = (((((raw - g_oe) * 10000) >> 12) * 10000) / g_gain) - g_x_roomt;
+ tmp = tmp * 15 / 18;
+
+ if (mt->o_slope_sign == 0)
+ tmp = (tmp * 1000) / (mt->conf->cali_val + mt->o_slope * 10);
+ else
+ tmp = (tmp * 1000) / (mt->conf->cali_val - mt->o_slope * 10);
+
+ tmp = tmp - (tmp << 1);
+ return (format_2 + tmp) * 100;
+}
+
static int raw_to_mcelsius_v2(struct mtk_thermal *mt, int sensno, s32 raw)
{
s32 format_1;
@@ -930,7 +968,8 @@ static void mtk_thermal_init_bank(struct mtk_thermal *mt, int num,
writel(auxadc_phys_base + AUXADC_CON1_CLR_V,
controller_base + TEMP_ADCMUXADDR);
- if (mt->conf->version == MTK_THERMAL_V1) {
+ if (mt->conf->version == MTK_THERMAL_V1 ||
+ mt->conf->version == MTK_THERMAL_V1_5) {
/* AHB address for pnp sensor mux selection */
writel(apmixed_phys_base + APMIXED_SYS_TS_CON1,
controller_base + TEMP_PNPMUXADDR);
@@ -1034,6 +1073,50 @@ static int mtk_thermal_extract_efuse_v1(struct mtk_thermal *mt, u32 *buf)
return 0;
}
+static int mtk_thermal_extract_efuse_v1_5(struct mtk_thermal *mt, u32 *buf)
+{
+ int i;
+
+ if (!(buf[0] & CALIB_BUF0_VALID_V1))
+ return -EINVAL;
+
+ mt->adc_ge = CALIB_BUF1_ADC_GE_V1(buf[1]);
+ mt->adc_oe = CALIB_BUF1_ADC_OE_V1_5(buf[1]);
+
+ for (i = 0; i < mt->conf->num_sensors; i++) {
+ switch (mt->conf->vts_index[i]) {
+ case VTS1:
+ mt->vts[VTS1] = CALIB_BUF0_VTS_TS1_V1(buf[0]);
+ break;
+ case VTS2:
+ mt->vts[VTS2] = CALIB_BUF0_VTS_TS2_V1(buf[0]);
+ break;
+ case VTS3:
+ mt->vts[VTS3] = CALIB_BUF1_VTS_TS3_V1(buf[1]);
+ break;
+ case VTS4:
+ mt->vts[VTS4] = CALIB_BUF2_VTS_TS4_V1(buf[2]);
+ break;
+ case VTS5:
+ mt->vts[VTS5] = CALIB_BUF2_VTS_TS5_V1(buf[2]);
+ break;
+ case VTSABB:
+ mt->vts[VTSABB] =
+ CALIB_BUF2_VTS_TSABB_V1(buf[2]);
+ break;
+ default:
+ break;
+ }
+ }
+
+ mt->degc_cali = CALIB_BUF0_DEGC_CALI_V1(buf[0]);
+ mt->o_slope_sign = CALIB_BUF0_O_SLOPE_SIGN_V1(buf[0]);
+ if (CALIB_BUF1_ID_V1(buf[1]))
+ mt->o_slope = CALIB_BUF0_O_SLOPE_V1(buf[0]);
+
+ return 0;
+}
+
static int mtk_thermal_extract_efuse_v2(struct mtk_thermal *mt, u32 *buf)
{
if (!CALIB_BUF1_VALID_V2(buf[1]))
@@ -1110,6 +1193,9 @@ static int mtk_thermal_get_calibration_data(struct device *dev,
case MTK_THERMAL_V1:
ret = mtk_thermal_extract_efuse_v1(mt, buf);
break;
+ case MTK_THERMAL_V1_5:
+ ret = mtk_thermal_extract_efuse_v1_5(mt, buf);
+ break;
case MTK_THERMAL_V2:
ret = mtk_thermal_extract_efuse_v2(mt, buf);
break;
@@ -1270,11 +1356,14 @@ static int mtk_thermal_probe(struct platform_device *pdev)
mtk_thermal_turn_on_buffer(mt, apmixed_base);
- if (mt->conf->version != MTK_THERMAL_V1)
+ if (mt->conf->version != MTK_THERMAL_V1 &&
+ mt->conf->version != MTK_THERMAL_V1_5)
mtk_thermal_release_periodic_ts(mt, auxadc_base);
if (mt->conf->version == MTK_THERMAL_V1)
mt->raw_to_mcelsius = raw_to_mcelsius_v1;
+ else if (mt->conf->version == MTK_THERMAL_V1_5)
+ mt->raw_to_mcelsius = raw_to_mcelsius_v1_5;
else if (mt->conf->version == MTK_THERMAL_V2)
mt->raw_to_mcelsius = raw_to_mcelsius_v2;
else
--
2.56.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/4] thermal/drivers/mediatek: Add support for setting sampling mode per SoC
2026-12-03 12:03 [PATCH 0/4] thermal/drivers/mediatek: Sampling mode, mobile calibration & MT6797 support Ben Grisdale via B4 Relay
2026-12-03 12:03 ` [PATCH 1/4] thermal/drivers/mediatek: Add efuse calibration support for mobile SoCs Ben Grisdale via B4 Relay
@ 2026-12-03 12:03 ` Ben Grisdale via B4 Relay
2026-12-03 12:03 ` [PATCH 3/4] dt-bindings: thermal: mediatek,thermal: Add MT6797 Ben Grisdale via B4 Relay
2026-12-03 12:03 ` [PATCH 4/4] thermal/drivers/mediatek: Add MT6797 support Ben Grisdale via B4 Relay
3 siblings, 0 replies; 7+ messages in thread
From: Ben Grisdale via B4 Relay @ 2026-12-03 12:03 UTC (permalink / raw)
To: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
Matthias Brugger, AngeloGioacchino Del Regno, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Sascha Hauer
Cc: Roman Vivchar, linux-pm, linux-kernel, linux-arm-kernel,
linux-mediatek, devicetree, Ben Grisdale
From: Ben Grisdale <bengris32@protonmail.ch>
The auxadc thermal controllers on MediaTek SoCs support hardware
sampling, controlled via the TEMP_MSRCTL0 register.
The sensors on some SoCs may suffer from a certain amount of
jitter between readings. To mitigate this, especially on mobile
SoCs, MediaTek usually enables this sampling functionality [1].
Add a new member msr_sample to the compatible data for configuring
this on a per-SoC basis. No functional change intended for existing
SoCs as the default remains 0.
Link: https://github.com/helio-x20/linux/blob/helio-x20/drivers/misc/mediatek/thermal/mt6797/src/mtk_tc.c#L898 [1]
Signed-off-by: Ben Grisdale <bengris32@protonmail.ch>
---
drivers/thermal/mediatek/auxadc_thermal.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/drivers/thermal/mediatek/auxadc_thermal.c b/drivers/thermal/mediatek/auxadc_thermal.c
index 5b116cbb0af9..319ab741e325 100644
--- a/drivers/thermal/mediatek/auxadc_thermal.c
+++ b/drivers/thermal/mediatek/auxadc_thermal.c
@@ -84,6 +84,14 @@
#define TEMP_AHBPOLL_ADC_POLL_INTERVAL(x) (x)
+#define TEMP_MSRCTL0_SAMPLE(x) ((x) | ((x) << 3) | ((x) << 6) | ((x) << 9))
+#define TEMP_MSRCTL0_1_SAMPLE 0
+#define TEMP_MSRCTL0_2_SAMPLES 1
+#define TEMP_MSRCTL0_2_OF_4_SAMPLES 2
+#define TEMP_MSRCTL0_4_OF_6_SAMPLES 3
+#define TEMP_MSRCTL0_8_OF_10_SAMPLES 4
+#define TEMP_MSRCTL0_16_OF_18_SAMPLES 5
+
#define TEMP_ADCWRITECTRL_ADC_PNP_WRITE BIT(0)
#define TEMP_ADCWRITECTRL_ADC_MUX_WRITE BIT(1)
@@ -332,6 +340,7 @@ struct mtk_thermal_data {
u32 apmixed_buffer_ctl_reg;
u32 apmixed_buffer_ctl_mask;
u32 apmixed_buffer_ctl_set;
+ u32 msr_sample;
};
struct mtk_thermal {
@@ -939,8 +948,9 @@ static void mtk_thermal_init_bank(struct mtk_thermal *mt, int num,
writel(TEMP_AHBPOLL_ADC_POLL_INTERVAL(768),
controller_base + TEMP_AHBPOLL);
- /* temperature sampling control, 1 sample */
- writel(0x0, controller_base + TEMP_MSRCTL0);
+ /* temperature sampling control */
+ writel(TEMP_MSRCTL0_SAMPLE(conf->msr_sample),
+ controller_base + TEMP_MSRCTL0);
/* exceed this polling time, IRQ would be inserted */
writel(0xffffffff, controller_base + TEMP_AHBTO);
--
2.56.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/4] dt-bindings: thermal: mediatek,thermal: Add MT6797
2026-12-03 12:03 [PATCH 0/4] thermal/drivers/mediatek: Sampling mode, mobile calibration & MT6797 support Ben Grisdale via B4 Relay
2026-12-03 12:03 ` [PATCH 1/4] thermal/drivers/mediatek: Add efuse calibration support for mobile SoCs Ben Grisdale via B4 Relay
2026-12-03 12:03 ` [PATCH 2/4] thermal/drivers/mediatek: Add support for setting sampling mode per SoC Ben Grisdale via B4 Relay
@ 2026-12-03 12:03 ` Ben Grisdale via B4 Relay
2026-12-03 12:03 ` [PATCH 4/4] thermal/drivers/mediatek: Add MT6797 support Ben Grisdale via B4 Relay
3 siblings, 0 replies; 7+ messages in thread
From: Ben Grisdale via B4 Relay @ 2026-12-03 12:03 UTC (permalink / raw)
To: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
Matthias Brugger, AngeloGioacchino Del Regno, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Sascha Hauer
Cc: Roman Vivchar, linux-pm, linux-kernel, linux-arm-kernel,
linux-mediatek, devicetree, Ben Grisdale
From: Roman Vivchar <rva333@protonmail.com>
Add a compatible string for the mt6797 SoC.
Signed-off-by: Roman Vivchar <rva333@protonmail.com>
Signed-off-by: Ben Grisdale <bengris32@protonmail.ch>
---
Documentation/devicetree/bindings/thermal/mediatek,thermal.yaml | 1 +
1 file changed, 1 insertion(+)
diff --git a/Documentation/devicetree/bindings/thermal/mediatek,thermal.yaml b/Documentation/devicetree/bindings/thermal/mediatek,thermal.yaml
index 7bd0955e6d04..9f85d37d925a 100644
--- a/Documentation/devicetree/bindings/thermal/mediatek,thermal.yaml
+++ b/Documentation/devicetree/bindings/thermal/mediatek,thermal.yaml
@@ -24,6 +24,7 @@ properties:
- enum:
- mediatek,mt2701-thermal
- mediatek,mt2712-thermal
+ - mediatek,mt6797-thermal
- mediatek,mt7622-thermal
- mediatek,mt7986-thermal
- mediatek,mt8173-thermal
--
2.56.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 4/4] thermal/drivers/mediatek: Add MT6797 support
2026-12-03 12:03 [PATCH 0/4] thermal/drivers/mediatek: Sampling mode, mobile calibration & MT6797 support Ben Grisdale via B4 Relay
` (2 preceding siblings ...)
2026-12-03 12:03 ` [PATCH 3/4] dt-bindings: thermal: mediatek,thermal: Add MT6797 Ben Grisdale via B4 Relay
@ 2026-12-03 12:03 ` Ben Grisdale via B4 Relay
2026-12-03 12:53 ` sashiko-bot
3 siblings, 1 reply; 7+ messages in thread
From: Ben Grisdale via B4 Relay @ 2026-12-03 12:03 UTC (permalink / raw)
To: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
Matthias Brugger, AngeloGioacchino Del Regno, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Sascha Hauer
Cc: Roman Vivchar, linux-pm, linux-kernel, linux-arm-kernel,
linux-mediatek, devicetree, Ben Grisdale
From: Roman Vivchar <rva333@protonmail.com>
The mt6797 includes 4 thermal sensors for CPU, GPU, CCI and overall SoC
temperature measurements and uses v1.5 formula for temperature
conversion.
Signed-off-by: Roman Vivchar <rva333@protonmail.com>
[bengris32: set msr_sample to TEMP_MSRCTL0_2_OF_4_SAMPLES]
Signed-off-by: Ben Grisdale <bengris32@protonmail.ch>
---
drivers/thermal/mediatek/auxadc_thermal.c | 98 +++++++++++++++++++++++++++++++
1 file changed, 98 insertions(+)
diff --git a/drivers/thermal/mediatek/auxadc_thermal.c b/drivers/thermal/mediatek/auxadc_thermal.c
index 319ab741e325..a8d22af7d4ea 100644
--- a/drivers/thermal/mediatek/auxadc_thermal.c
+++ b/drivers/thermal/mediatek/auxadc_thermal.c
@@ -240,6 +240,30 @@ enum mtk_thermal_version {
/* The calibration coefficient of sensor */
#define MT2712_CALIBRATION 165
+/* MT6797 thermal sensors */
+#define MT6797_TS1 0
+#define MT6797_TS2 1
+#define MT6797_TS3 2
+#define MT6797_TS4 3
+
+/* AUXADC channel 11 is used for the temperature sensors */
+#define MT6797_TEMP_AUXADC_CHANNEL 11
+
+/* The total number of temperature sensors in the MT6797 */
+#define MT6797_NUM_SENSORS 4
+
+/* The number of banks in the MT6797 */
+#define MT6797_NUM_ZONES 6
+
+/* The number of sensing points per bank */
+#define MT6797_NUM_SENSORS_PER_ZONE 4
+
+/* The number of controller in the MT6797 */
+#define MT6797_NUM_CONTROLLER 1
+
+/* The calibration coefficient of sensor */
+#define MT6797_CALIBRATION 1663
+
#define MT7622_TEMP_AUXADC_CHANNEL 11
#define MT7622_NUM_SENSORS 1
#define MT7622_NUM_ZONES 1
@@ -450,6 +474,31 @@ static const int mt2712_vts_index[MT2712_NUM_SENSORS] = {
VTS1, VTS2, VTS3, VTS4
};
+/* MT6797 thermal sensor data */
+static const int mt6797_bank_data[MT6797_NUM_ZONES][2] = {
+ { MT6797_TS1 },
+ { MT6797_TS4 },
+ { MT6797_TS2, MT6797_TS3 },
+ { MT6797_TS2 },
+ { MT6797_TS2 },
+ { MT6797_TS2 },
+};
+
+static const int mt6797_msr[MT6797_NUM_SENSORS_PER_ZONE] = {
+ TEMP_MSR0, TEMP_MSR1, TEMP_MSR2, TEMP_MSR3
+};
+
+static const int mt6797_adcpnp[MT6797_NUM_SENSORS_PER_ZONE] = {
+ TEMP_ADCPNP0, TEMP_ADCPNP1, TEMP_ADCPNP2, TEMP_ADCPNP3
+};
+
+static const int mt6797_mux_values[MT6797_NUM_SENSORS] = { 0, 1, 2, 3 };
+static const int mt6797_tc_offset[MT6797_NUM_CONTROLLER] = { 0x0, };
+
+static const int mt6797_vts_index[MT6797_NUM_SENSORS] = {
+ VTS1, VTS2, VTS3, VTS4
+};
+
/* MT7622 thermal sensor data */
static const int mt7622_bank_data[MT7622_NUM_SENSORS] = { MT7622_TS1, };
static const int mt7622_msr[MT7622_NUM_SENSORS_PER_ZONE] = { TEMP_MSR0, };
@@ -623,6 +672,51 @@ static const struct mtk_thermal_data mt2712_thermal_data = {
.version = MTK_THERMAL_V1,
};
+/*
+ * The MT6797 thermal controller has six banks. Each bank can read up to
+ * four temperature sensors simultaneously. It has a total of 4
+ * temperature sensors used across its banks.
+ */
+static const struct mtk_thermal_data mt6797_thermal_data = {
+ .auxadc_channel = MT6797_TEMP_AUXADC_CHANNEL,
+ .num_banks = MT6797_NUM_ZONES,
+ .num_sensors = MT6797_NUM_SENSORS,
+ .vts_index = mt6797_vts_index,
+ .cali_val = MT6797_CALIBRATION,
+ .num_controller = MT6797_NUM_CONTROLLER,
+ .controller_offset = mt6797_tc_offset,
+ .need_switch_bank = true,
+ .bank_data = {
+ {
+ .num_sensors = 1,
+ .sensors = mt6797_bank_data[0],
+ }, {
+ .num_sensors = 1,
+ .sensors = mt6797_bank_data[1],
+ }, {
+ .num_sensors = 2,
+ .sensors = mt6797_bank_data[2],
+ }, {
+ .num_sensors = 1,
+ .sensors = mt6797_bank_data[3],
+ }, {
+ .num_sensors = 1,
+ .sensors = mt6797_bank_data[4],
+ }, {
+ .num_sensors = 1,
+ .sensors = mt6797_bank_data[5],
+ },
+ },
+ .msr = mt6797_msr,
+ .adcpnp = mt6797_adcpnp,
+ .sensor_mux_values = mt6797_mux_values,
+ .version = MTK_THERMAL_V1_5,
+ .apmixed_buffer_ctl_reg = APMIXED_SYS_TS_CON1,
+ .apmixed_buffer_ctl_mask = (u32)~GENMASK(5, 4),
+ .apmixed_buffer_ctl_set = 0,
+ .msr_sample = TEMP_MSRCTL0_2_OF_4_SAMPLES,
+};
+
/*
* MT7622 have only one sensing point which uses AUXADC Channel 11 for raw data
* access.
@@ -1241,6 +1335,10 @@ static const struct of_device_id mtk_thermal_of_match[] = {
.compatible = "mediatek,mt2712-thermal",
.data = (void *)&mt2712_thermal_data,
},
+ {
+ .compatible = "mediatek,mt6797-thermal",
+ .data = (void *)&mt6797_thermal_data,
+ },
{
.compatible = "mediatek,mt7622-thermal",
.data = (void *)&mt7622_thermal_data,
--
2.56.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/4] thermal/drivers/mediatek: Add efuse calibration support for mobile SoCs
2026-12-03 12:03 ` [PATCH 1/4] thermal/drivers/mediatek: Add efuse calibration support for mobile SoCs Ben Grisdale via B4 Relay
@ 2026-12-03 12:28 ` sashiko-bot
0 siblings, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-12-03 12:28 UTC (permalink / raw)
To: Ben Grisdale; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] thermal: mediatek: negative signed left shift in
raw_to_mcelsius_v1_5()
- [Medium] thermal: mediatek: raw == 0 returns 0 mC in
raw_to_mcelsius_v1_5()
- [Low] thermal: mediatek: duplicated efuse logic in
mtk_thermal_extract_efuse_v1_5()
--
commit c3dd11d0a97055e44df1e363ad510a84e28f5420
Author: Ben Grisdale <bengris32@protonmail.ch>
thermal/drivers/mediatek: Add efuse calibration support for mobile SoCs
This commit adds MTK_THERMAL_V1_5 support to the MediaTek AUXADC thermal
driver for mobile SoCs, including efuse calibration extraction with
ADC_OE and a corresponding raw-to-millicelsius conversion helper.
Link: https://github.com/helio-x20/linux/blob/helio-x20/drivers/misc/mediatek/thermal/mt6797/src/mtk_tc.c#L326-L659 [1]
Link: https://github.com/NotKit/kernel-4.4-alps/blob/master/drivers/misc/mediatek/thermal/mt6757/src/mtk_tc.c#L257-L570 [2]
Link: https://github.com/LineageOS/android_kernel_xiaomi_mt6768/blob/lineage-24.0/drivers/misc/mediatek/thermal/mt6768/src/mtk_tc.c#L280-L643 [3]
Link: https://github.com/LineageOS/android_kernel_xiaomi_mt6768/blob/lineage-24.0/drivers/misc/mediatek/thermal/mt6873/src/mtk_tc.c#L212-L584 [4]
> diff --git a/drivers/thermal/mediatek/auxadc_thermal.c b/drivers/thermal/mediatek/auxadc_thermal.c
> index 434f856c0f045..5b116cbb0af95 100644
> --- a/drivers/thermal/mediatek/auxadc_thermal.c
> +++ b/drivers/thermal/mediatek/auxadc_thermal.c
[ ... ]
> @@ -724,6 +731,37 @@ static int raw_to_mcelsius_v1(struct mtk_thermal *mt, int sensno, s32 raw)
> return mt->degc_cali * 500 - tmp;
> }
>
> +static int raw_to_mcelsius_v1_5(struct mtk_thermal *mt, int sensno, s32 raw)
> +{
> + s32 format_1;
> + s32 format_2;
> + s32 g_oe;
> + s32 g_gain;
> + s32 g_x_roomt;
> + s32 tmp;
> +
> + if (raw == 0)
> + return 0;
[Severity: Medium]
Should raw == 0 return THERMAL_TEMP_INVALID here instead of 0?
Before the first AUXADC conversion completes after controller init, the
TEMP_MSR register can read 0. Since mtk_thermal_temp_is_valid() accepts
[-20000, 150000], returning 0 passes validation and reports a bogus 0 C
temperature instead of THERMAL_TEMP_INVALID.
> +
> + raw &= 0xfff;
> + g_gain = 10000 + (((mt->adc_ge - 512) * 10000) >> 12);
> + g_oe = mt->adc_oe - 512;
> + format_1 = mt->vts[sensno] + 3350 - g_oe;
> + format_2 = (mt->degc_cali * 10) >> 1;
> + g_x_roomt = (((format_1 * 10000) >> 12) * 10000) / g_gain;
> +
> + tmp = (((((raw - g_oe) * 10000) >> 12) * 10000) / g_gain) - g_x_roomt;
> + tmp = tmp * 15 / 18;
> +
> + if (mt->o_slope_sign == 0)
> + tmp = (tmp * 1000) / (mt->conf->cali_val + mt->o_slope * 10);
> + else
> + tmp = (tmp * 1000) / (mt->conf->cali_val - mt->o_slope * 10);
> +
> + tmp = tmp - (tmp << 1);
> + return (format_2 + tmp) * 100;
> +}
[Severity: Medium]
Can tmp << 1 left-shift a negative signed s32 here?
Because raw decreases as temperature rises, tmp is negative on every
reading above degc_cali / 2 (around 20 C with defaults). Left-shifting a
negative signed integer is C11 undefined behavior and triggers
CONFIG_UBSAN_SHIFT splats (or a trap under CONFIG_UBSAN_TRAP).
Returning (format_2 - tmp) * 100, as raw_to_mcelsius_v2() does, avoids
the shift.
[ ... ]
> @@ -1034,6 +1073,50 @@ static int mtk_thermal_extract_efuse_v1(struct mtk_thermal *mt, u32 *buf)
> return 0;
> }
>
> +static int mtk_thermal_extract_efuse_v1_5(struct mtk_thermal *mt, u32 *buf)
> +{
> + int i;
> +
> + if (!(buf[0] & CALIB_BUF0_VALID_V1))
> + return -EINVAL;
> +
> + mt->adc_ge = CALIB_BUF1_ADC_GE_V1(buf[1]);
> + mt->adc_oe = CALIB_BUF1_ADC_OE_V1_5(buf[1]);
> +
> + for (i = 0; i < mt->conf->num_sensors; i++) {
> + switch (mt->conf->vts_index[i]) {
> + case VTS1:
> + mt->vts[VTS1] = CALIB_BUF0_VTS_TS1_V1(buf[0]);
> + break;
> + case VTS2:
> + mt->vts[VTS2] = CALIB_BUF0_VTS_TS2_V1(buf[0]);
> + break;
> + case VTS3:
> + mt->vts[VTS3] = CALIB_BUF1_VTS_TS3_V1(buf[1]);
> + break;
> + case VTS4:
> + mt->vts[VTS4] = CALIB_BUF2_VTS_TS4_V1(buf[2]);
> + break;
> + case VTS5:
> + mt->vts[VTS5] = CALIB_BUF2_VTS_TS5_V1(buf[2]);
> + break;
> + case VTSABB:
> + mt->vts[VTSABB] =
> + CALIB_BUF2_VTS_TSABB_V1(buf[2]);
> + break;
> + default:
> + break;
> + }
> + }
> +
> + mt->degc_cali = CALIB_BUF0_DEGC_CALI_V1(buf[0]);
> + mt->o_slope_sign = CALIB_BUF0_O_SLOPE_SIGN_V1(buf[0]);
> + if (CALIB_BUF1_ID_V1(buf[1]))
> + mt->o_slope = CALIB_BUF0_O_SLOPE_V1(buf[0]);
> +
> + return 0;
> +}
[Severity: Low]
Could this share the common efuse decoding with
mtk_thermal_extract_efuse_v1()?
The validity check, adc_ge, degc_cali, and the VTS extraction loop are
identical between V1 and V1_5, differing only in adc_oe and o_slope
handling. Sharing the common decoding or branching on mt->conf->version
in mtk_thermal_extract_efuse_v1() would avoid maintaining two copies.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-mt6797-thermal-support-v1-0-19595fe11814@protonmail.ch?part=1
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 4/4] thermal/drivers/mediatek: Add MT6797 support
2026-12-03 12:03 ` [PATCH 4/4] thermal/drivers/mediatek: Add MT6797 support Ben Grisdale via B4 Relay
@ 2026-12-03 12:53 ` sashiko-bot
0 siblings, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-12-03 12:53 UTC (permalink / raw)
To: Ben Grisdale; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] thermal/mediatek: negative signed left shift in
raw_to_mcelsius_v1_5()
- [Medium] thermal/mediatek: raw_to_mcelsius_v1_5() returns 0 instead of
invalid temp
--
commit f202360240c2d8c5a36415fdb23e266d0c8c9198
Author: Roman Vivchar <rva333@protonmail.com>
thermal/drivers/mediatek: Add MT6797 support
This commit adds MT6797 thermal controller support to the MediaTek
AUXADC thermal driver, wiring it to the v1.5 temperature conversion
formula and registering the mediatek,mt6797-thermal compatible.
> diff --git a/drivers/thermal/mediatek/auxadc_thermal.c b/drivers/thermal/mediatek/auxadc_thermal.c
> index 319ab741e325b..a8d22af7d4ea6 100644
> --- a/drivers/thermal/mediatek/auxadc_thermal.c
> +++ b/drivers/thermal/mediatek/auxadc_thermal.c
[ ... ]
> @@ -623,6 +672,51 @@ static const struct mtk_thermal_data mt2712_thermal_data = {
> .version = MTK_THERMAL_V1,
> };
>
> +/*
> + * The MT6797 thermal controller has six banks. Each bank can read up to
> + * four temperature sensors simultaneously. It has a total of 4
> + * temperature sensors used across its banks.
> + */
> +static const struct mtk_thermal_data mt6797_thermal_data = {
[ ... ]
> + .version = MTK_THERMAL_V1_5,
[Severity: Medium]
Does selecting MTK_THERMAL_V1_5 trigger undefined behavior from a
negative signed left shift in raw_to_mcelsius_v1_5()?
Because MediaTek thermal sensors have a negative temperature
coefficient, s32 tmp is negative at normal operating temperatures above
the calibration room temperature (default 20 C). MT6797 is the first
SoC to use raw_to_mcelsius_v1_5():
drivers/thermal/mediatek/auxadc_thermal.c:raw_to_mcelsius_v1_5() {
...
tmp = tmp - (tmp << 1);
return (format_2 + tmp) * 100;
}
Left-shifting a negative signed integer triggers UBSAN
shift-out-of-bounds splats (or traps under CONFIG_UBSAN_TRAP) on every
temperature read. Returning (format_2 - tmp) * 100, matching
raw_to_mcelsius_v2(), avoids the shift.
[Severity: Medium]
Can raw_to_mcelsius_v1_5() also report a bogus 0 C reading instead of
-ENODATA when an MSR register reads 0?
Right after mtk_thermal_probe() registers the thermal zone, TEMP_MSR0..3
can read 0 until the first AUXADC conversion completes (up to 60 ms).
raw_to_mcelsius_v1_5() short-circuits raw == 0 to return 0 mC, which
passes mtk_thermal_temp_is_valid() in mtk_thermal_bank_temperature()
instead of being converted to THERMAL_TEMP_INVALID.
That causes thermal_zone_get_temp() to return 0 C rather than -ENODATA,
and max() across banks will mask valid sub-zero temperatures with 0 C.
Returning THERMAL_TEMP_INVALID when raw == 0 (or dropping the early
return so mtk_thermal_temp_is_valid() rejects it) would prevent this.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-mt6797-thermal-support-v1-0-19595fe11814@protonmail.ch?part=4
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-12-03 12:53 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 12:03 [PATCH 0/4] thermal/drivers/mediatek: Sampling mode, mobile calibration & MT6797 support Ben Grisdale via B4 Relay
2026-12-03 12:03 ` [PATCH 1/4] thermal/drivers/mediatek: Add efuse calibration support for mobile SoCs Ben Grisdale via B4 Relay
2026-12-03 12:28 ` sashiko-bot
2026-12-03 12:03 ` [PATCH 2/4] thermal/drivers/mediatek: Add support for setting sampling mode per SoC Ben Grisdale via B4 Relay
2026-12-03 12:03 ` [PATCH 3/4] dt-bindings: thermal: mediatek,thermal: Add MT6797 Ben Grisdale via B4 Relay
2026-12-03 12:03 ` [PATCH 4/4] thermal/drivers/mediatek: Add MT6797 support Ben Grisdale via B4 Relay
2026-12-03 12:53 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox