[PATCH 2/4] thermal/drivers/mediatek: Add support for setting sampling mode per SoC

Ben Grisdale via B4 Relay devnull+bengris32.protonmail.ch at kernel.org
Thu Dec 3 04:03:25 PST 2026


From: Ben Grisdale <bengris32 at 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 at 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





More information about the linux-arm-kernel mailing list