From 6b020e53c02f064ca0b932679abf2619a9049995 Mon Sep 17 00:00:00 2001 From: Andrejs Cainikovs Date: Tue, 10 May 2022 14:41:45 +0200 Subject: imx8m: fixup thermal trips Fixup thermal trips in Linux device tree according to SoC thermal grade. Signed-off-by: Andrejs Cainikovs --- arch/arm/mach-imx/imx8m/soc.c | 50 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/arch/arm/mach-imx/imx8m/soc.c b/arch/arm/mach-imx/imx8m/soc.c index e93ecd2846..b451ece91f 100644 --- a/arch/arm/mach-imx/imx8m/soc.c +++ b/arch/arm/mach-imx/imx8m/soc.c @@ -1001,6 +1001,49 @@ static int disable_cpu_nodes(void *blob, u32 disabled_cores) return 0; } +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; + } 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, bd_t *bd) { #ifdef CONFIG_IMX8MQ @@ -1128,6 +1171,13 @@ usb_modify_speed: disable_cpu_nodes(blob, 2); #endif + if (fixup_thermal_trips(blob, "cpu-thermal")) + printf("Failed to update cpu-thermal trip(s)"); +#ifdef CONFIG_IMX8MP + if (fixup_thermal_trips(blob, "soc-thermal")) + printf("Failed to update soc-thermal trip(s)"); +#endif + return ft_add_optee_node(blob, bd); } #endif -- cgit v1.2.3