Skip to contentSkip to conversation

Add Mediatek thermal dirver and dtsi

PATCH Superseded michael.kao 4 participants 16 messages May 10, 2019 – Dec 6, 2019

Subsystems (3)

v2 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v2 cover Add Mediatek thermal dirver and dtsi

This patchset supports for MT8183 chip to mtk_thermal.c. Add thermal zone of all the thermal sensor in SoC for another get temperatrue. They don't need to thermal throttle. And we bind coolers for thermal zone nodes of cpu_thermal.

This patch series base on these patches [1][2][3][4].

[1]support for reading chip ID and efuse (https://patchwork.kernel.org/patch/10902131/)
[2]arm64: dts: mt8183: Add reset-cells in infracfg (https://patchwork.kernel.org/patch/10908653/)
[3]clk: reset: Modify reset-controller driver (https://patchwork.kernel.org/patch/10908657/)
[4]PM / AVS: SVS: Introduce SVS engine (https://patchwork.kernel.org/patch/10923289/)

Matthias Kaehlcke (2):
arm64: dts: mt8183: Configure CPU cooling
arm64: dts: mt8183: Increase polling frequency for CPU thermal zone

Michael Kao (6):
arm64: dts: mt8183: add thermal zone node
arm64: dts: mt8183: add/update dynamic power coefficients
arm64: dts: mt8183: Add #cooling-cells to CPU nodes
thermal: mediatek: mt8183: fix bank number settings
thermal: mediatek: add another get_temp ops for thermal sensors
thermal: mediatek: use spinlock to protect PTPCORESEL

arch/arm64/boot/dts/mediatek/mt8183.dtsi | 158 +++++++++++++++++++++++++++++++
drivers/thermal/mtk_thermal.c | 82 +++++++++++++---

2 files changed, 226 insertions(+), 14 deletions(-)
#1 lore raw

PATCH v2 1/8 arm64: dts: mt8183: add thermal zone node

Add thermal zone node to Mediatek MT8183 dts file.

---
 arch/arm64/boot/dts/mediatek/mt8183.dtsi | 85 ++++++++++++++++++++++++++++++++
 1 file changed, 85 insertions(+)
arch/arm64/boot/dts/mediatek/mt8183.dtsi +85 -0
index 926df75..52ad47e 100644
@@ -334,6 +334,88 @@
 			status = "disabled";
 		};
 
+		thermal: thermal@1100b000 {
+			#thermal-sensor-cells = <1>;
+			compatible = "mediatek,mt8183-thermal";
+			reg = <0 0x1100b000 0 0x1000>;
+			interrupts = <0 76 IRQ_TYPE_LEVEL_LOW>;
+			clocks = <&infracfg CLK_INFRA_THERM>,
+				 <&infracfg CLK_INFRA_AUXADC>;
+			clock-names = "therm", "auxadc";
+			resets = <&infracfg  MT8183_INFRACFG_AO_THERM_SW_RST>;
+			mediatek,auxadc = <&auxadc>;
+			mediatek,apmixedsys = <&apmixedsys>;
+			mediatek,hw-reset-temp = <117000>;
+			nvmem-cells = <&thermal_calibration>;
+			nvmem-cell-names = "calibration-data";
+		};
+
+		thermal-zones {
+			cpu_thermal: cpu_thermal {
+				polling-delay-passive = <1000>;
+				polling-delay = <1000>;
+				thermal-sensors = <&thermal 0>;
+				sustainable-power = <1500>;
+			};
+
+			/* The tzts1 ~ tzts6 don't need to polling */
+			/* The tzts1 ~ tzts6 don't need to thermal throttle */
+
+			tzts1: tzts1 {
+				polling-delay-passive = <0>;
+				polling-delay = <0>;
+				thermal-sensors = <&thermal 1>;
+				sustainable-power = <0>;
+				trips {};
+				cooling-maps {};
+			};
+
+			tzts2: tzts2 {
+				polling-delay-passive = <0>;
+				polling-delay = <0>;
+				thermal-sensors = <&thermal 2>;
+				sustainable-power = <0>;
+				trips {};
+				cooling-maps {};
+			};
+
+			tzts3: tzts3 {
+				polling-delay-passive = <0>;
+				polling-delay = <0>;
+				thermal-sensors = <&thermal 3>;
+				sustainable-power = <0>;
+				trips {};
+				cooling-maps {};
+			};
+
+			tzts4: tzts4 {
+				polling-delay-passive = <0>;
+				polling-delay = <0>;
+				thermal-sensors = <&thermal 4>;
+				sustainable-power = <0>;
+				trips {};
+				cooling-maps {};
+			};
+
+			tzts5: tzts5 {
+				polling-delay-passive = <0>;
+				polling-delay = <0>;
+				thermal-sensors = <&thermal 5>;
+				sustainable-power = <0>;
+				trips {};
+				cooling-maps {};
+			};
+
+			tztsABB: tztsABB {
+				polling-delay-passive = <0>;
+				polling-delay = <0>;
+				thermal-sensors = <&thermal 6>;
+				sustainable-power = <0>;
+				trips {};
+				cooling-maps {};
+			};
+		};
+
 		audiosys: syscon@11220000 {
 			compatible = "mediatek,mt8183-audiosys", "syscon";
 			reg = <0 0x11220000 0 0x1000>;
@@ -368,6 +450,9 @@
 			compatible = "mediatek,mt8183-efuse",
 				     "mediatek,efuse";
 			reg = <0 0x11f10000 0 0x1000>;
+			thermal_calibration: calib@180 {
+				reg = <0x180 0xc>;
+			};
 		};
 
 		mfgcfg: syscon@13000000 {
Signature · 1 line
2.6.4
#2 lore raw

Re: [PATCH v2 1/8] arm64: dts: mt8183: add thermal zone node

arch/arm64/boot/dts/mediatek/mt8183.dtsi line 372

Quoted 10 lines · michael.kao
arch/arm64/boot/dts/mediatek/mt8183.dtsi +10 -0
+
+                       tzts1: tzts1 {
+                               polling-delay-passive = <0>;
+                               polling-delay = <0>;
+                               thermal-sensors = <&thermal 1>;
+                               sustainable-power = <0>;
+                               trips {};
+                               cooling-maps {};
+                       };
+

Is 0 a valid initial sustainable-power setting? Since we'll still get warning[1] about this, though it might not be harmful.

If 0 is a valid setting, maybe we should consider showing the warning of not setting this property in [2]?

[1] https://elixir.bootlin.com/linux/latest/source/drivers/thermal/power_allocator.c#L570
[2] https://elixir.bootlin.com/linux/latest/source/drivers/thermal/of-thermal.c#L1049

#3 lore raw

Re: [PATCH v2 1/8] arm64: dts: mt8183: add thermal zone node

Quoted 15 lines · Hsin-Yi Wang

arch/arm64/boot/dts/mediatek/mt8183.dtsi line 372

Quoted 10 lines · michael.kao
arch/arm64/boot/dts/mediatek/mt8183.dtsi +10 -0
+
+                       tzts1: tzts1 {
+                               polling-delay-passive = <0>;
+                               polling-delay = <0>;
+                               thermal-sensors = <&thermal 1>;
+                               sustainable-power = <0>;
+                               trips {};
+                               cooling-maps {};
+                       };
+

Is 0 a valid initial sustainable-power setting? Since we'll still get warning[1] about this, though it might not be harmful.

Quoted 5 lines

If 0 is a valid setting, maybe we should consider showing the warning of not setting this property in [2]?

[1] https://elixir.bootlin.com/linux/latest/source/drivers/thermal/power_allocator.c#L570
[2] https://elixir.bootlin.com/linux/latest/source/drivers/thermal/of-thermal.c#L1049

IIUC a value of 0 is pointless, the thermal framework will still use an estimated value:

https://elixir.bootlin.com/linux/v5.1.5/source/drivers/thermal/power_allocator.c#L203

As commented on v1 (https://patchwork.kernel.org/patch/10926519/#22620905)
the value of the property may depend on the thermal characteristics of the device, there is not one correct value per SoC/core. If it is specified at SoC level device makers should be aware that they might have to override it for 'optimal' behavior on their device.

#4 lore raw

RE: [PATCH v2 1/8] arm64: dts: mt8183: add thermal zone node

-----Original Message-----
From: Matthias Kaehlcke [mailto:[email protected]]
Sent: Friday, May 31, 2019 12:08 AM
To: Hsin-Yi Wang <[email protected]>
Cc: Michael Kao (高振翔) <[email protected]>; Zhang Rui <[email protected]>; Eduardo Valentin <[email protected]>; Daniel Lezcano <[email protected]>; Rob Herring <[email protected]>; Mark Rutland <[email protected]>; Matthias Brugger <[email protected]>; [email protected]; [email protected]; lkml <[email protected]>; moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE <[email protected]>; [email protected]
Subject: Re: [PATCH v2 1/8] arm64: dts: mt8183: add thermal zone node

Quoted 15 lines · Hsin-Yi Wang

arch/arm64/boot/dts/mediatek/mt8183.dtsi line 372

Quoted 10 lines · michael.kao
arch/arm64/boot/dts/mediatek/mt8183.dtsi +10 -0
+
+                       tzts1: tzts1 {
+                               polling-delay-passive = <0>;
+                               polling-delay = <0>;
+                               thermal-sensors = <&thermal 1>;
+                               sustainable-power = <0>;
+                               trips {};
+                               cooling-maps {};
+                       };
+

Is 0 a valid initial sustainable-power setting? Since we'll still get warning[1] about this, though it might not be harmful.

Quoted 8 lines

If 0 is a valid setting, maybe we should consider showing the warning of not setting this property in [2]?

[1]
https://elixir.bootlin.com/linux/latest/source/drivers/thermal/power_a
llocator.c#L570 [2]
https://elixir.bootlin.com/linux/latest/source/drivers/thermal/of-ther
mal.c#L1049

IIUC a value of 0 is pointless, the thermal framework will still use an estimated value:

https://elixir.bootlin.com/linux/v5.1.5/source/drivers/thermal/power_allocator.c#L203

As commented on v1 (https://patchwork.kernel.org/patch/10926519/#22620905)
the value of the property may depend on the thermal characteristics of the device, there is not one correct value per SoC/core. If it is specified at SoC level device makers should be aware that they might have to override it for 'optimal' behavior on their device.

I think there is no need to set sustainable-power for tzts1~6.
They don't bind thermal instance and will not thermal throttle.
So it will be also zero if we don't set sustainable-power and let it use estimate value.
For the purpose of preventing warning, I think I can set sustainable-power of tzts1~6 the same to cpu_thermal.

#5 lore raw

PATCH v2 2/8 arm64: dts: mt8183: add/update dynamic power coefficients

In reply to michael.kao

Add dynamic power coefficients for all cores and update those of CPU0 and CPU4.

---
 arch/arm64/boot/dts/mediatek/mt8183.dtsi | 8 ++++++++
 1 file changed, 8 insertions(+)
arch/arm64/boot/dts/mediatek/mt8183.dtsi +8 -0
index 52ad47e..8f9fd9a 100644
@@ -58,6 +58,7 @@
 			compatible = "arm,cortex-a53";
 			reg = <0x000>;
 			enable-method = "psci";
+			dynamic-power-coefficient = <84>;
 		};
 
 		cpu1: cpu@1 {
@@ -65,6 +66,7 @@
 			compatible = "arm,cortex-a53";
 			reg = <0x001>;
 			enable-method = "psci";
+			dynamic-power-coefficient = <84>;
 		};
 
 		cpu2: cpu@2 {
@@ -72,6 +74,7 @@
 			compatible = "arm,cortex-a53";
 			reg = <0x002>;
 			enable-method = "psci";
+			dynamic-power-coefficient = <84>;
 		};
 
 		cpu3: cpu@3 {
@@ -79,6 +82,7 @@
 			compatible = "arm,cortex-a53";
 			reg = <0x003>;
 			enable-method = "psci";
+			dynamic-power-coefficient = <84>;
 		};
 
 		cpu4: cpu@100 {
@@ -86,6 +90,7 @@
 			compatible = "arm,cortex-a73";
 			reg = <0x100>;
 			enable-method = "psci";
+			dynamic-power-coefficient = <211>;
 		};
 
 		cpu5: cpu@101 {
@@ -93,6 +98,7 @@
 			compatible = "arm,cortex-a73";
 			reg = <0x101>;
 			enable-method = "psci";
+			dynamic-power-coefficient = <211>;
 		};
 
 		cpu6: cpu@102 {
@@ -100,6 +106,7 @@
 			compatible = "arm,cortex-a73";
 			reg = <0x102>;
 			enable-method = "psci";
+			dynamic-power-coefficient = <211>;
 		};
 
 		cpu7: cpu@103 {
@@ -107,6 +114,7 @@
 			compatible = "arm,cortex-a73";
 			reg = <0x103>;
 			enable-method = "psci";
+			dynamic-power-coefficient = <211>;
 		};
 	};
 
Signature · 1 line
2.6.4
#6 lore raw

PATCH v2 3/8 arm64: dts: mt8183: Add #cooling-cells to CPU nodes

In reply to michael.kao

The #cooling-cells property needs to be specified to allow a CPU to be used as cooling device.

---
 arch/arm64/boot/dts/mediatek/mt8183.dtsi | 10 ++++++++++
 1 file changed, 10 insertions(+)
arch/arm64/boot/dts/mediatek/mt8183.dtsi +10 -0
index 8f9fd9a..bf8b0a8 100644
@@ -11,6 +11,8 @@
 #include <dt-bindings/power/mt8183-power.h>
 #include <dt-bindings/reset-controller/mt8183-resets.h>
 #include "mt8183-pinfunc.h"
+#include <dt-bindings/thermal/thermal.h>
+
 / {
 	compatible = "mediatek,mt8183";
 	interrupt-parent = <&sysirq>;
@@ -59,6 +61,7 @@
 			reg = <0x000>;
 			enable-method = "psci";
 			dynamic-power-coefficient = <84>;
+			#cooling-cells = <2>;
 		};
 
 		cpu1: cpu@1 {
@@ -67,6 +70,7 @@
 			reg = <0x001>;
 			enable-method = "psci";
 			dynamic-power-coefficient = <84>;
+			#cooling-cells = <2>;
 		};
 
 		cpu2: cpu@2 {
@@ -75,6 +79,7 @@
 			reg = <0x002>;
 			enable-method = "psci";
 			dynamic-power-coefficient = <84>;
+			#cooling-cells = <2>;
 		};
 
 		cpu3: cpu@3 {
@@ -83,6 +88,7 @@
 			reg = <0x003>;
 			enable-method = "psci";
 			dynamic-power-coefficient = <84>;
+			#cooling-cells = <2>;
 		};
 
 		cpu4: cpu@100 {
@@ -91,6 +97,7 @@
 			reg = <0x100>;
 			enable-method = "psci";
 			dynamic-power-coefficient = <211>;
+			#cooling-cells = <2>;
 		};
 
 		cpu5: cpu@101 {
@@ -99,6 +106,7 @@
 			reg = <0x101>;
 			enable-method = "psci";
 			dynamic-power-coefficient = <211>;
+			#cooling-cells = <2>;
 		};
 
 		cpu6: cpu@102 {
@@ -107,6 +115,7 @@
 			reg = <0x102>;
 			enable-method = "psci";
 			dynamic-power-coefficient = <211>;
+			#cooling-cells = <2>;
 		};
 
 		cpu7: cpu@103 {
@@ -115,6 +124,7 @@
 			reg = <0x103>;
 			enable-method = "psci";
 			dynamic-power-coefficient = <211>;
+			#cooling-cells = <2>;
 		};
 	};
 
Signature · 1 line
2.6.4
#7 lore raw

PATCH v2 4/8 arm64: dts: mt8183: Configure CPU cooling

In reply to michael.kao

From: Matthias Kaehlcke <[email protected]>

Add two passive trip points at 68°C and 85°C for the CPU temperature.

---
 arch/arm64/boot/dts/mediatek/mt8183.dtsi | 55 ++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)
arch/arm64/boot/dts/mediatek/mt8183.dtsi +55 -0
index bf8b0a8..29ad660 100644
@@ -374,6 +374,61 @@
 				polling-delay = <1000>;
 				thermal-sensors = <&thermal 0>;
 				sustainable-power = <1500>;
+
+				trips {
+					threshold: trip-point@0 {
+						temperature = <68000>;
+						hysteresis = <2000>;
+						type = "passive";
+					};
+
+					target: trip-point@1 {
+						temperature = <85000>;
+						hysteresis = <2000>;
+						type = "passive";
+					};
+
+					cpu_crit: cpu-crit {
+						temperature = <115000>;
+						hysteresis = <2000>;
+						type = "critical";
+					};
+				};
+
+				cooling-maps {
+					map0 {
+						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 = <3072>;
+					};
+					map1 {
+						trip = <&target>;
+						cooling-device = <&cpu4
+							THERMAL_NO_LIMIT
+							THERMAL_NO_LIMIT>,
+								 <&cpu5
+							THERMAL_NO_LIMIT
+							THERMAL_NO_LIMIT>,
+								 <&cpu6
+							THERMAL_NO_LIMIT
+							THERMAL_NO_LIMIT>,
+								 <&cpu7
+							THERMAL_NO_LIMIT
+							THERMAL_NO_LIMIT>;
+						contribution = <1024>;
+					};
+				};
 			};
 
 			/* The tzts1 ~ tzts6 don't need to polling */
Signature · 7 lines
2.6.4


_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
#8 lore raw

PATCH v2 5/8 arm64: dts: mt8183: Increase polling frequency for CPU thermal zone

In reply to michael.kao

From: Matthias Kaehlcke <[email protected]>

Evaluate the thermal zone every 500ms while not cooling and every 100ms when passive cooling is performed.

---
 arch/arm64/boot/dts/mediatek/mt8183.dtsi | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/mediatek/mt8183.dtsi +2 -2
index 29ad660..2c4e014 100644
@@ -370,8 +370,8 @@
 
 		thermal-zones {
 			cpu_thermal: cpu_thermal {
-				polling-delay-passive = <1000>;
-				polling-delay = <1000>;
+				polling-delay-passive = <100>;
+				polling-delay = <500>;
 				thermal-sensors = <&thermal 0>;
 				sustainable-power = <1500>;
 
Signature · 1 line
2.6.4
#9 lore raw

PATCH v2 6/8 thermal: mediatek: mt8183: fix bank number settings

In reply to michael.kao

From: Michael Kao <michael.kao-NuS5LvNUpcJWk0Htik3J/[email protected]>

MT8183_NUM_ZONES should be set to 1
because MT8183 doesn't have multiple banks.

Fixes a4ffe6b52d27 ("thermal: mediatek: add support for MT8183")
---
 drivers/thermal/mtk_thermal.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/thermal/mtk_thermal.c +4 -1
index 5c07a61..cb41e46 100644
@@ -216,6 +216,9 @@ enum {
 /* The total number of temperature sensors in the MT8183 */
 #define MT8183_NUM_SENSORS	6
 
+/* The number of banks in the MT8183 */
+#define MT8183_NUM_ZONES               1
+
 /* The number of sensing points per bank */
 #define MT8183_NUM_SENSORS_PER_ZONE	 6
 
@@ -503,7 +506,7 @@ static const struct mtk_thermal_data mt7622_thermal_data = {
 
 static const struct mtk_thermal_data mt8183_thermal_data = {
 	.auxadc_channel = MT8183_TEMP_AUXADC_CHANNEL,
-	.num_banks = MT8183_NUM_SENSORS_PER_ZONE,
+	.num_banks = MT8183_NUM_ZONES,
 	.num_sensors = MT8183_NUM_SENSORS,
 	.vts_index = mt8183_vts_index,
 	.cali_val = MT8183_CALIBRATION,
Signature · 1 line
2.6.4
#10 lore raw

PATCH v2 7/8 thermal: mediatek: add another get_temp ops for thermal sensors

In reply to michael.kao

From: Michael Kao <[email protected]>

Provide thermal zone to read thermal sensor
in the SoC. We can read all the thermal sensors
value in the SoC by the node /sys/class/thermal/

---
 drivers/thermal/mtk_thermal.c | 68 ++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 60 insertions(+), 8 deletions(-)
drivers/thermal/mtk_thermal.c +60 -8
index cb41e46..d5c78b0 100644
@@ -230,6 +230,11 @@ enum {
 
 struct mtk_thermal;
 
+struct mtk_thermal_zone {
+	struct mtk_thermal *mt;
+	int id;
+};
+
 struct thermal_bank_cfg {
 	unsigned int num_sensors;
 	const int *sensors;
@@ -612,7 +617,7 @@ static int mtk_thermal_bank_temperature(struct mtk_thermal_bank *bank)
 		 * not immediately shut down.
 		 */
 		if (temp > 200000)
-			temp = 0;
+			temp = -EACCES;
 
 		if (temp > max)
 			max = temp;
@@ -623,7 +628,8 @@ static int mtk_thermal_bank_temperature(struct mtk_thermal_bank *bank)
 
 static int mtk_read_temp(void *data, int *temperature)
 {
-	struct mtk_thermal *mt = data;
+	struct mtk_thermal_zone *tz = data;
+	struct mtk_thermal *mt = tz->mt;
 	int i;
 	int tempmax = INT_MIN;
 
@@ -636,16 +642,48 @@ static int mtk_read_temp(void *data, int *temperature)
 
 		mtk_thermal_put_bank(bank);
 	}
-
 	*temperature = tempmax;
 
 	return 0;
 }
 
+static int mtk_read_sensor_temp(void *data, int *temperature)
+{
+	struct mtk_thermal_zone *tz = data;
+	struct mtk_thermal *mt = tz->mt;
+	const struct mtk_thermal_data *conf = mt->conf;
+	int id = tz->id - 1;
+	int temp = INT_MIN;
+	u32 raw;
+
+	if (id < 0)
+		return  -EACCES;
+
+	raw = readl(mt->thermal_base + conf->msr[id]);
+
+	temp = raw_to_mcelsius(mt, id, raw);
+
+	/*
+	 * The first read of a sensor often contains very high bogus
+	 * temperature value. Filter these out so that the system does
+	 * not immediately shut down.
+	 */
+
+	if (temp > 200000)
+		return  -EACCES;
+
+	*temperature = temp;
+	return 0;
+}
+
 static const struct thermal_zone_of_device_ops mtk_thermal_ops = {
 	.get_temp = mtk_read_temp,
 };
 
+static const struct thermal_zone_of_device_ops mtk_thermal_sensor_ops = {
+	.get_temp = mtk_read_sensor_temp,
+};
+
 static void mtk_thermal_init_bank(struct mtk_thermal *mt, int num,
 				  u32 apmixed_phys_base, u32 auxadc_phys_base,
 				  int ctrl_id)
@@ -878,6 +916,7 @@ static int mtk_thermal_probe(struct platform_device *pdev)
 	struct resource *res;
 	u64 auxadc_phys_base, apmixed_phys_base;
 	struct thermal_zone_device *tzdev;
+	struct mtk_thermal_zone *tz;
 
 	mt = devm_kzalloc(&pdev->dev, sizeof(*mt), GFP_KERNEL);
 	if (!mt)
@@ -959,11 +998,24 @@ static int mtk_thermal_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, mt);
 
-	tzdev = devm_thermal_zone_of_sensor_register(&pdev->dev, 0, mt,
-						     &mtk_thermal_ops);
-	if (IS_ERR(tzdev)) {
-		ret = PTR_ERR(tzdev);
-		goto err_disable_clk_peri_therm;
+	for (i = 0; i < mt->conf->num_sensors + 1; i++) {
+		tz = kmalloc(sizeof(*tz), GFP_KERNEL);
+		if (!tz)
+			return -ENOMEM;
+
+		tz->mt = mt;
+		tz->id = i;
+
+		tzdev = devm_thermal_zone_of_sensor_register(&pdev->dev, i,
+				tz, (i == 0) ?
+				&mtk_thermal_ops : &mtk_thermal_sensor_ops);
+
+		if (IS_ERR(tzdev)) {
+			if (IS_ERR(tzdev) != -EACCES) {
+				ret = PTR_ERR(tzdev);
+				goto err_disable_clk_peri_therm;
+			}
+		}
 	}
 
 	return 0;
Signature · 1 line
2.6.4
#11 lore raw

Re: [PATCH v2 7/8] thermal: mediatek: add another get_temp ops for thermal sensors

Quoted 29 lines · michael.kao

From: Michael Kao <[email protected]>

Provide thermal zone to read thermal sensor
in the SoC. We can read all the thermal sensors
value in the SoC by the node /sys/class/thermal/

---
 drivers/thermal/mtk_thermal.c | 68 ++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 60 insertions(+), 8 deletions(-)
drivers/thermal/mtk_thermal.c +5 -0
index cb41e46..d5c78b0 100644
@@ -230,6 +230,11 @@ enum {
 
 struct mtk_thermal;
 
+struct mtk_thermal_zone {
+       struct mtk_thermal *mt;
+       int id;
+};
+
 struct thermal_bank_cfg {
        unsigned int num_sensors;
        const int *sensors;

drivers/thermal/mtk_thermal.c static int mtk_thermal_bank_temperature(struct mtk_thermal_bank *bank) · line 620

Quoted 5 lines
drivers/thermal/mtk_thermal.c +1 -1
@@ -612,7 +617,7 @@ static int mtk_thermal_bank_temperature(struct mtk_thermal_bank *bank)
                 * not immediately shut down.
                 */
                if (temp > 200000)
-                       temp = 0;
+                       temp = -EACCES;

Should we return -EAGAIN here? Otherwise there would be warning:

[    0.344167] thermal thermal_zone5: failed to read out thermal zone (-13)

Since first read is bogus value, I think EAGAIN also makes sense here.

Quoted 37 lines
drivers/thermal/mtk_thermal.c +16 -2
                if (temp > max)
                        max = temp;
@@ -623,7 +628,8 @@ static int mtk_thermal_bank_temperature(struct mtk_thermal_bank *bank)
 
 static int mtk_read_temp(void *data, int *temperature)
 {
-       struct mtk_thermal *mt = data;
+       struct mtk_thermal_zone *tz = data;
+       struct mtk_thermal *mt = tz->mt;
        int i;
        int tempmax = INT_MIN;
 
@@ -636,16 +642,48 @@ static int mtk_read_temp(void *data, int *temperature)
 
                mtk_thermal_put_bank(bank);
        }
-
        *temperature = tempmax;
 
        return 0;
 }
 
+static int mtk_read_sensor_temp(void *data, int *temperature)
+{
+       struct mtk_thermal_zone *tz = data;
+       struct mtk_thermal *mt = tz->mt;
+       const struct mtk_thermal_data *conf = mt->conf;
+       int id = tz->id - 1;
+       int temp = INT_MIN;
+       u32 raw;
+
+       if (id < 0)
+               return  -EACCES;
+
+       raw = readl(mt->thermal_base + conf->msr[id]);
+

drivers/thermal/mtk_thermal.c static int mtk_read_temp(void *data, int *temperature) · line 673

Quoted 10 lines
drivers/thermal/mtk_thermal.c +10 -0
+       temp = raw_to_mcelsius(mt, id, raw);
+
+       /*
+        * The first read of a sensor often contains very high bogus
+        * temperature value. Filter these out so that the system does
+        * not immediately shut down.
+        */
+
+       if (temp > 200000)
+               return  -EACCES;

Same here.

Quoted 57 lines
drivers/thermal/mtk_thermal.c +28 -6
+
+       *temperature = temp;
+       return 0;
+}
+
 static const struct thermal_zone_of_device_ops mtk_thermal_ops = {
        .get_temp = mtk_read_temp,
 };
 
+static const struct thermal_zone_of_device_ops mtk_thermal_sensor_ops = {
+       .get_temp = mtk_read_sensor_temp,
+};
+
 static void mtk_thermal_init_bank(struct mtk_thermal *mt, int num,
                                  u32 apmixed_phys_base, u32 auxadc_phys_base,
                                  int ctrl_id)
@@ -878,6 +916,7 @@ static int mtk_thermal_probe(struct platform_device *pdev)
        struct resource *res;
        u64 auxadc_phys_base, apmixed_phys_base;
        struct thermal_zone_device *tzdev;
+       struct mtk_thermal_zone *tz;
 
        mt = devm_kzalloc(&pdev->dev, sizeof(*mt), GFP_KERNEL);
        if (!mt)
@@ -959,11 +998,24 @@ static int mtk_thermal_probe(struct platform_device *pdev)
 
        platform_set_drvdata(pdev, mt);
 
-       tzdev = devm_thermal_zone_of_sensor_register(&pdev->dev, 0, mt,
-                                                    &mtk_thermal_ops);
-       if (IS_ERR(tzdev)) {
-               ret = PTR_ERR(tzdev);
-               goto err_disable_clk_peri_therm;
+       for (i = 0; i < mt->conf->num_sensors + 1; i++) {
+               tz = kmalloc(sizeof(*tz), GFP_KERNEL);
+               if (!tz)
+                       return -ENOMEM;
+
+               tz->mt = mt;
+               tz->id = i;
+
+               tzdev = devm_thermal_zone_of_sensor_register(&pdev->dev, i,
+                               tz, (i == 0) ?
+                               &mtk_thermal_ops : &mtk_thermal_sensor_ops);
+
+               if (IS_ERR(tzdev)) {
+                       if (IS_ERR(tzdev) != -EACCES) {
+                               ret = PTR_ERR(tzdev);
+                               goto err_disable_clk_peri_therm;
+                       }
+               }
        }
 
        return 0;
--

2.6.4

#12 lore raw

Re: [PATCH v2 7/8] thermal: mediatek: add another get_temp ops for thermal sensors

In reply to michael.kao
Quoted 9 lines · michael.kao
drivers/thermal/mtk_thermal.c +4 -5
-       tzdev = devm_thermal_zone_of_sensor_register(&pdev->dev, 0, mt,
-                                                    &mtk_thermal_ops);
-       if (IS_ERR(tzdev)) {
-               ret = PTR_ERR(tzdev);
-               goto err_disable_clk_peri_therm;
+       for (i = 0; i < mt->conf->num_sensors + 1; i++) {
+               tz = kmalloc(sizeof(*tz), GFP_KERNEL);
+               if (!tz)
+                       return -ENOMEM;

drivers/thermal/mtk_thermal.c static int mtk_thermal_probe(struct platform_device *pdev) · line 1014

Quoted 10 lines
drivers/thermal/mtk_thermal.c +10 -0
+
+               tz->mt = mt;
+               tz->id = i;
+
+               tzdev = devm_thermal_zone_of_sensor_register(&pdev->dev, i,
+                               tz, (i == 0) ?
+                               &mtk_thermal_ops : &mtk_thermal_sensor_ops);
+
+               if (IS_ERR(tzdev)) {
+                       if (IS_ERR(tzdev) != -EACCES) {

PTR_ERR(tzdev)

drivers/thermal/mtk_thermal.c static int mtk_thermal_probe(struct platform_device *pdev) · line 1018

Quoted 4 lines
drivers/thermal/mtk_thermal.c +4 -0
+                               ret = PTR_ERR(tzdev);
+                               goto err_disable_clk_peri_therm;
+                       }
+               }

This for loop adding thermal zone sensors will not work for mt8173. It assumes that thermal-zones in dts have subnodes (eg. cpu_thermal, tzts..) amount equal to num_sensors+1. Otherwise tzdev would be -ENODEV and thermal failed to be probed.
In mt8183 this is fine, since each thermal zone only has one sensor, but in mt8173, some sensor appears in multiple thermal zones.

In order to let the change also works for 8173, I think if the error is -ENODEV, and the id is not 0 (0 is cpu_thermal), prompt a warning instead of failing. Eg.

                if (IS_ERR(tzdev)) {

+ if (i > 0 && PTR_ERR(tzdev) == -ENODEV) {
+ dev_warn(&pdev->dev, "can't find
thermal sensor %d\n", i);
+ continue;
+ }

                        if (PTR_ERR(tzdev) != -EACCES) {
#13 lore raw

Re: [PATCH v2 7/8] thermal: mediatek: add another get_temp ops for thermal sensors

Quoted 43 lines · Hsin-Yi Wang
Quoted 9 lines · michael.kao
drivers/thermal/mtk_thermal.c +4 -5
-       tzdev = devm_thermal_zone_of_sensor_register(&pdev->dev, 0, mt,
-                                                    &mtk_thermal_ops);
-       if (IS_ERR(tzdev)) {
-               ret = PTR_ERR(tzdev);
-               goto err_disable_clk_peri_therm;
+       for (i = 0; i < mt->conf->num_sensors + 1; i++) {
+               tz = kmalloc(sizeof(*tz), GFP_KERNEL);
+               if (!tz)
+                       return -ENOMEM;

drivers/thermal/mtk_thermal.c static int mtk_thermal_probe(struct platform_device *pdev) · line 1014

Quoted 10 lines
drivers/thermal/mtk_thermal.c +10 -0
+
+               tz->mt = mt;
+               tz->id = i;
+
+               tzdev = devm_thermal_zone_of_sensor_register(&pdev->dev, i,
+                               tz, (i == 0) ?
+                               &mtk_thermal_ops : &mtk_thermal_sensor_ops);
+
+               if (IS_ERR(tzdev)) {
+                       if (IS_ERR(tzdev) != -EACCES) {

PTR_ERR(tzdev)

drivers/thermal/mtk_thermal.c static int mtk_thermal_probe(struct platform_device *pdev) · line 1018

Quoted 4 lines
drivers/thermal/mtk_thermal.c +4 -0
+                               ret = PTR_ERR(tzdev);
+                               goto err_disable_clk_peri_therm;
+                       }
+               }

This for loop adding thermal zone sensors will not work for mt8173. It assumes that thermal-zones in dts have subnodes (eg. cpu_thermal, tzts..) amount equal to num_sensors+1. Otherwise tzdev would be -ENODEV and thermal failed to be probed.
In mt8183 this is fine, since each thermal zone only has one sensor, but in mt8173, some sensor appears in multiple thermal zones.

In order to let the change also works for 8173, I think if the error is -ENODEV, and the id is not 0 (0 is cpu_thermal), prompt a warning instead of failing. Eg.

                if (IS_ERR(tzdev)) {
(quoted diff) +2 -0
+                       if (i > 0 && PTR_ERR(tzdev) == -ENODEV) {
+                               dev_warn(&pdev->dev, "can't find

thermal sensor %d\n", i);

Review

Quoted 3 lines
(quoted diff) +2 -0
+                               continue;
+                       }
                        if (PTR_ERR(tzdev) != -EACCES) {

OK, I will update this patch.

#14 lore raw

PATCH v2 8/8 thermal: mediatek: use spinlock to protect PTPCORESEL

In reply to michael.kao

The driver of thermal and svs will use the
same register for the project which should select
bank before reading sensor value.

---
 drivers/thermal/mtk_thermal.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/thermal/mtk_thermal.c +4 -5
index d5c78b0..6d7e839 100644
@@ -30,6 +30,7 @@
 #include <linux/thermal.h>
 #include <linux/reset.h>
 #include <linux/types.h>
+#include <linux/power/mtk_svs.h>
 
 /* AUXADC Registers */
 #define AUXADC_CON1_SET_V	0x008
@@ -267,7 +268,7 @@ struct mtk_thermal {
 	struct clk *clk_peri_therm;
 	struct clk *clk_auxadc;
 	/* lock: for getting and putting banks */
-	struct mutex lock;
+	unsigned long flags;
 
 	/* Calibration values */
 	s32 adc_ge;
@@ -566,7 +567,7 @@ static void mtk_thermal_get_bank(struct mtk_thermal_bank *bank)
 	u32 val;
 
 	if (mt->conf->need_switch_bank) {
-		mutex_lock(&mt->lock);
+		mt->flags = claim_mtk_svs_lock();
 
 		val = readl(mt->thermal_base + PTPCORESEL);
 		val &= ~0xf;
@@ -586,7 +587,7 @@ static void mtk_thermal_put_bank(struct mtk_thermal_bank *bank)
 	struct mtk_thermal *mt = bank->mt;
 
 	if (mt->conf->need_switch_bank)
-		mutex_unlock(&mt->lock);
+		release_mtk_svs_lock(mt->flags);
 }
 
 /**
@@ -941,8 +942,6 @@ static int mtk_thermal_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	mutex_init(&mt->lock);
-
 	mt->dev = &pdev->dev;
 
 	auxadc = of_parse_phandle(np, "mediatek,auxadc", 0);
Signature · 1 line
2.6.4
#15 lore raw
In reply to michael.kao

What is the status of this series? Shouldn't we have a V3?

Quoted 28 lines · michael.kao

This patchset supports for MT8183 chip to mtk_thermal.c. Add thermal zone of all the thermal sensor in SoC for another get temperatrue. They don't need to thermal throttle. And we bind coolers for thermal zone nodes of cpu_thermal.

This patch series base on these patches [1][2][3][4].

[1]support for reading chip ID and efuse (https://patchwork.kernel.org/patch/10902131/)
[2]arm64: dts: mt8183: Add reset-cells in infracfg (https://patchwork.kernel.org/patch/10908653/)
[3]clk: reset: Modify reset-controller driver (https://patchwork.kernel.org/patch/10908657/)
[4]PM / AVS: SVS: Introduce SVS engine (https://patchwork.kernel.org/patch/10923289/)

Matthias Kaehlcke (2):
arm64: dts: mt8183: Configure CPU cooling
arm64: dts: mt8183: Increase polling frequency for CPU thermal zone

Michael Kao (6):
arm64: dts: mt8183: add thermal zone node
arm64: dts: mt8183: add/update dynamic power coefficients
arm64: dts: mt8183: Add #cooling-cells to CPU nodes
thermal: mediatek: mt8183: fix bank number settings
thermal: mediatek: add another get_temp ops for thermal sensors
thermal: mediatek: use spinlock to protect PTPCORESEL

arch/arm64/boot/dts/mediatek/mt8183.dtsi | 158 +++++++++++++++++++++++++++++++
drivers/thermal/mtk_thermal.c | 82 +++++++++++++---

2 files changed, 226 insertions(+), 14 deletions(-)
Signature · 5 lines
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog