From ad73611d2c42815d123e81f8f89fb42b3c6f24fd Mon Sep 17 00:00:00 2001
From: Esteban Blanc <eblanc@baylibre.com>
Date: Fri, 21 Mar 2025 09:21:04 +0000
Subject: [PATCH 1/2] BL_INTERNAL: arm64: dts: mediatek: mt8365: add thermal
 zone support

This adds the thermal-zones and thermal sensor nodes for mt8365

Signed-off-by: Esteban Blanc <eblanc@baylibre.com>
---
 arch/arm64/boot/dts/mediatek/mt8365.dtsi | 133 +++++++++++++++++++++++
 1 file changed, 133 insertions(+)

diff --git a/arch/arm64/boot/dts/mediatek/mt8365.dtsi b/arch/arm64/boot/dts/mediatek/mt8365.dtsi
index fdd570ca2d209..d016fe1f6c0f6 100644
--- a/arch/arm64/boot/dts/mediatek/mt8365.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt8365.dtsi
@@ -13,6 +13,7 @@
 #include <dt-bindings/memory/mediatek,mt8365-larb-port.h>
 #include <dt-bindings/phy/phy.h>
 #include <dt-bindings/power/mediatek,mt8365-power.h>
+#include <dt-bindings/thermal/thermal.h>
 
 / {
 	compatible = "mediatek,mt8365";
@@ -267,6 +268,96 @@ clk26m: oscillator {
 		clock-output-names = "clk26m";
 	};
 
+	thermal-zones {
+		cpu_thermal: cpu-thermal {
+			polling-delay-passive = <1000>; /* milliseconds */
+			polling-delay = <1000>; /* milliseconds */
+			thermal-sensors = <&thermal 0>;
+
+			trips {
+				threshold: trip-point0 {
+					temperature = <65000>;
+					hysteresis = <2000>;
+					type = "passive";
+				};
+
+				target: trip-point1 {
+					temperature = <80000>;
+					hysteresis = <2000>;
+					type = "passive";
+				};
+
+				cpu_crit: cpu_crit0 {
+					temperature = <95000>;
+					hysteresis = <2000>;
+					type = "critical";
+				};
+			};
+
+			cooling-maps {
+				map0 {
+					trip = <&threshold>;
+					cooling-device =
+						<&cpu0
+						 THERMAL_NO_LIMIT
+						 THERMAL_NO_LIMIT>,
+						<&cpu1
+						 THERMAL_NO_LIMIT
+						 THERMAL_NO_LIMIT>,
+						<&cpu2
+						 THERMAL_NO_LIMIT
+						 THERMAL_NO_LIMIT>,
+						<&cpu3
+						 THERMAL_NO_LIMIT
+						 THERMAL_NO_LIMIT>;
+					contribution = <100>;
+				};
+
+				map1 {
+					trip = <&target>;
+					cooling-device =
+						<&cpu0
+						 THERMAL_NO_LIMIT
+						 THERMAL_NO_LIMIT>,
+						<&cpu1
+						 THERMAL_NO_LIMIT
+						 THERMAL_NO_LIMIT>,
+						<&cpu2
+						 THERMAL_NO_LIMIT
+						 THERMAL_NO_LIMIT>,
+						<&cpu3
+						 THERMAL_NO_LIMIT
+						 THERMAL_NO_LIMIT>;
+					contribution = <100>;
+				};
+			};
+		};
+
+		tzts1: tzts1 {
+			polling-delay-passive = <0>;
+			polling-delay = <0>;
+			thermal-sensors = <&thermal 1>;
+			trips {};
+			cooling-maps {};
+		};
+
+		tzts2: tzts2 {
+			polling-delay-passive = <0>;
+			polling-delay = <0>;
+			thermal-sensors = <&thermal 2>;
+			trips {};
+			cooling-maps {};
+		};
+
+		tzts3: tzts3 {
+			polling-delay-passive = <0>;
+			polling-delay = <0>;
+			thermal-sensors = <&thermal 3>;
+			trips {};
+			cooling-maps {};
+		};
+	};
+
 	psci {
 		compatible = "arm,psci-1.0";
 		method = "smc";
@@ -560,6 +651,48 @@ uart2: serial@11004000 {
 			status = "disabled";
 		};
 
+		efuse: efuse@11c50000 {
+			compatible = "mediatek,mt8365-efuse", "mediatek,efuse";
+			reg = <0 0x11c50000 0 0x1000>;
+			#address-cells = <1>;
+			#size-cells = <1>;
+
+			svs_calibration: calib@580 {
+				reg = <0x580 0x20>;
+			};
+
+			power_leakage: leakage@cd4 {
+				reg = <0xcd4 0x4>;
+			};
+
+			thermal_calibration: calib@180 {
+				reg = <0x180 0xc>;
+			};
+		};
+
+		auxadc: adc@11001000 {
+			compatible = "mediatek,mt8365-auxadc",
+				     "mediatek,mt8173-auxadc";
+			reg = <0 0x11001000 0 0x1000>;
+			clocks = <&infracfg CLK_IFR_AUXADC>;
+			clock-names = "main";
+			#io-channel-cells = <1>;
+		};
+
+		thermal: thermal@1100b000 {
+			compatible = "mediatek,mt8365-thermal";
+			reg = <0 0x1100b000 0 0x1000>;
+			interrupts = <GIC_SPI 22 IRQ_TYPE_LEVEL_LOW>;
+			clocks = <&infracfg CLK_IFR_THERM>,
+				 <&infracfg CLK_IFR_AUXADC>;
+			clock-names = "therm", "auxadc";
+			mediatek,auxadc = <&auxadc>;
+			mediatek,apmixedsys = <&apmixedsys>;
+			nvmem-cells = <&thermal_calibration>;
+			nvmem-cell-names = "calibration-data";
+			#thermal-sensor-cells = <1>;
+		};
+
 		pwm: pwm@11006000 {
 			compatible = "mediatek,mt8365-pwm";
 			reg = <0 0x11006000 0 0x1000>;
-- 
GitLab


From 3a06341853d43cd8c69aa2328da86815f3fbd0c6 Mon Sep 17 00:00:00 2001
From: Esteban Blanc <eblanc@baylibre.com>
Date: Fri, 21 Mar 2025 09:23:45 +0000
Subject: [PATCH 2/2] ANDROID: add support for thermal on mt8365

Adds the MT6577_AUXADC and MTK_SOC_THERMAL drivers used by mt8365.

Signed-off-by: Esteban Blanc <eblanc@baylibre.com>
---
 BUILD.bazel                         | 2 ++
 arch/arm64/configs/mtk_gki.fragment | 7 +++++++
 2 files changed, 9 insertions(+)

diff --git a/BUILD.bazel b/BUILD.bazel
index 2ca2e085fa60e..7b20970472410 100644
--- a/BUILD.bazel
+++ b/BUILD.bazel
@@ -1364,6 +1364,7 @@ _MTK_MODULE_OUTS = [
     "drivers/gpu/drm/vkms/vkms.ko",
     "drivers/i2c/busses/i2c-mt65xx.ko",
     "drivers/iio/adc/mt6359-auxadc.ko",
+    "drivers/iio/adc/mt6577_auxadc.ko",
     "drivers/input/touchscreen/goodix_ts.ko",
     "drivers/iommu/mtk_iommu.ko",
     "drivers/irqchip/irq-mtk-sysirq.ko",
@@ -1406,6 +1407,7 @@ _MTK_MODULE_OUTS = [
     "drivers/spmi/spmi-mtk-pmif.ko",
     "drivers/tee/optee/optee.ko",
     "drivers/tee/tee.ko",
+    "drivers/thermal/mediatek/auxadc_thermal.ko",
     "drivers/tty/serial/8250/8250_mtk.ko",
     "drivers/usb/common/usb-conn-gpio.ko",
     "drivers/usb/host/xhci-mtk-hcd.ko",
diff --git a/arch/arm64/configs/mtk_gki.fragment b/arch/arm64/configs/mtk_gki.fragment
index d8754612a07e4..107a9169b9a18 100644
--- a/arch/arm64/configs/mtk_gki.fragment
+++ b/arch/arm64/configs/mtk_gki.fragment
@@ -113,6 +113,7 @@ CONFIG_DMABUF_HEAPS_SYSTEM=m
 # Analog to digital converters
 #
 CONFIG_MEDIATEK_MT6359_AUXADC=m
+CONFIG_MEDIATEK_MT6577_AUXADC=m
 
 #
 # Clock driver for MediaTek SoC
@@ -136,6 +137,12 @@ CONFIG_MTK_SOCINFO=m
 #
 CONFIG_NVMEM_MTK_EFUSE=m
 
+#
+# Thermal
+#
+CONFIG_MTK_THERMAL=m
+CONFIG_MTK_SOC_THERMAL=m
+
 #
 # MediaTek PM Domains
 #
-- 
GitLab