diff mbox series

[1/1] imx: imx9: fixup thermal trips from fuses

Message ID 20240111125625.2815180-2-primoz.fiser@norik.com
State Accepted
Commit 3233349fa6e2f64ae7f03d9d0ccce3df7a5e7721
Delegated to: Fabio Estevam
Headers show
Series i.MX9 thermal trip fixups | expand

Commit Message

Primoz Fiser Jan. 11, 2024, 12:56 p.m. UTC
Read i.MX9 CPU temp grade from fuses and fixup thermal trips in Linux
device-tree accordingly.

Based on commit 0543a1ed2787 ("imx8m: fixup thermal trips")

Signed-off-by: Primoz Fiser <primoz.fiser@norik.com>
---
 arch/arm/mach-imx/imx9/soc.c | 45 ++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

Comments

Fabio Estevam Jan. 12, 2024, 9 p.m. UTC | #1
On Thu, Jan 11, 2024 at 9:56 AM Primoz Fiser <primoz.fiser@norik.com> wrote:
>
> Read i.MX9 CPU temp grade from fuses and fixup thermal trips in Linux
> device-tree accordingly.
>
> Based on commit 0543a1ed2787 ("imx8m: fixup thermal trips")
>
> Signed-off-by: Primoz Fiser <primoz.fiser@norik.com>

Applied, thanks.
diff mbox series

Patch

diff --git a/arch/arm/mach-imx/imx9/soc.c b/arch/arm/mach-imx/imx9/soc.c
index 86b45be3d804..f06339f13880 100644
--- a/arch/arm/mach-imx/imx9/soc.c
+++ b/arch/arm/mach-imx/imx9/soc.c
@@ -507,8 +507,53 @@  int print_cpuinfo(void)
 	return 0;
 }
 
+static int fixup_thermal_trips(void *blob, const char *name)
+{
+	int minc, maxc;
+	int node, trip;
+
+	node = fdt_path_offset(blob, "/thermal-zones");
+	if (node < 0)
+		return node;
+
+	node = fdt_subnode_offset(blob, node, name);
+	if (node < 0)
+		return node;
+
+	node = fdt_subnode_offset(blob, node, "trips");
+	if (node < 0)
+		return node;
+
+	get_cpu_temp_grade(&minc, &maxc);
+
+	fdt_for_each_subnode(trip, blob, node) {
+		const char *type;
+		int temp, ret;
+
+		type = fdt_getprop(blob, trip, "type", NULL);
+		if (!type)
+			continue;
+
+		temp = 0;
+		if (!strcmp(type, "critical"))
+			temp = 1000 * (maxc - 5);
+		else if (!strcmp(type, "passive"))
+			temp = 1000 * (maxc - 10);
+		if (temp) {
+			ret = fdt_setprop_u32(blob, trip, "temperature", temp);
+			if (ret)
+				return ret;
+		}
+	}
+
+	return 0;
+}
+
 int ft_system_setup(void *blob, struct bd_info *bd)
 {
+	if (fixup_thermal_trips(blob, "cpu-thermal"))
+		printf("Failed to update cpu-thermal trip(s)");
+
 	return 0;
 }