1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright 2023 Toradex - https://www.toradex.com/
6 #include <asm/hardware.h>
7 #include <fdt_support.h>
10 #include "../common_fdt.h"
12 static void fdt_fixup_cores_nodes_am625(void *blob, int core_nr)
19 for (; core_nr < 4; core_nr++) {
20 snprintf(node_path, sizeof(node_path), "/cpus/cpu@%d", core_nr);
21 fdt_del_node_path(blob, node_path);
22 snprintf(node_path, sizeof(node_path), "/cpus/cpu-map/cluster0/core%d", core_nr);
23 fdt_del_node_path(blob, node_path);
24 snprintf(node_path, sizeof(node_path), "/bus@f0000/watchdog@e0%d0000", core_nr);
25 fdt_del_node_path(blob, node_path);
29 static void fdt_fixup_gpu_nodes_am625(void *blob, int has_gpu)
32 fdt_del_node_path(blob, "/bus@f0000/gpu@fd00000");
33 fdt_del_node_path(blob, "/bus@f0000/watchdog@e0f0000");
37 static void fdt_fixup_pru_node_am625(void *blob, int has_pru)
40 fdt_del_node_path(blob, "/bus@f0000/pruss@30040000");
43 static int fdt_fixup_trips_node(void *blob, int zoneoffset, int maxc)
47 node = fdt_subnode_offset(blob, zoneoffset, "trips");
51 fdt_for_each_subnode(trip, blob, node) {
52 const char *type = fdt_getprop(blob, trip, "type", NULL);
54 if (!type || (strncmp(type, "critical", 8) != 0))
57 if (fdt_setprop_u32(blob, trip, "temperature", 1000 * maxc) < 0)
64 static void fdt_fixup_thermal_zone_nodes_am625(void *blob, int maxc)
68 node = fdt_path_offset(blob, "/thermal-zones");
72 fdt_for_each_subnode(zone, blob, node) {
73 if (fdt_fixup_trips_node(blob, zone, maxc) < 0)
74 printf("Failed to set temperature in %s critical trips\n",
75 fdt_get_name(blob, zone, NULL));
79 static void fdt_fixup_thermal_cooling_device_cpus_am625(void *blob, int core_nr)
81 static const char * const thermal_path[] = {
82 "/thermal-zones/main0-thermal/cooling-maps/map0",
83 "/thermal-zones/main1-thermal/cooling-maps/map0"
86 int node, cnt, i, ret;
89 for (i = 0; i < ARRAY_SIZE(thermal_path); i++) {
90 int new_count = core_nr * 3; /* Each CPU has 3 entries */
93 node = fdt_path_offset(blob, thermal_path[i]);
95 continue; /* Not found, skip it */
97 cnt = fdtdec_get_int_array_count(blob, node, "cooling-device",
98 cooling_dev, ARRAY_SIZE(cooling_dev));
102 for (j = 0; j < new_count; j++)
103 cooling_dev[j] = cpu_to_fdt32(cooling_dev[j]);
105 ret = fdt_setprop(blob, node, "cooling-device", cooling_dev,
106 new_count * sizeof(u32));
108 printf("Error %s, cooling-device setprop failed %d\n",
109 thermal_path[i], ret);
113 int ft_system_setup(void *blob, struct bd_info *bd)
115 fdt_fixup_cores_nodes_am625(blob, k3_get_core_nr());
116 fdt_fixup_gpu_nodes_am625(blob, k3_has_gpu());
117 fdt_fixup_pru_node_am625(blob, k3_has_pru());
118 fdt_fixup_thermal_zone_nodes_am625(blob, k3_get_max_temp());
119 fdt_fixup_thermal_cooling_device_cpus_am625(blob, k3_get_core_nr());
120 fdt_fixup_reserved(blob, "tfa", CONFIG_K3_ATF_LOAD_ADDR, 0x80000);
121 fdt_fixup_reserved(blob, "optee", CONFIG_K3_OPTEE_LOAD_ADDR, 0x1800000);