blob: ab9b573f3cff3d6a341d688b703f16a31ca65494 [file] [log] [blame]
Emanuele Ghidolid7e0b072023-07-14 17:23:10 +02001// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Copyright 2023 Toradex - https://www.toradex.com/
4 */
5
6#include <asm/hardware.h>
Emanuele Ghidolid7e0b072023-07-14 17:23:10 +02007#include <fdt_support.h>
Parth Pancholid4c4f4f2024-10-02 09:41:33 +02008#include <fdtdec.h>
Emanuele Ghidolid7e0b072023-07-14 17:23:10 +02009
Andrew Davis336b0792024-05-10 15:21:24 -050010#include "../common_fdt.h"
11
Emanuele Ghidolid7e0b072023-07-14 17:23:10 +020012static void fdt_fixup_cores_nodes_am625(void *blob, int core_nr)
13{
14 char node_path[32];
15
16 if (core_nr < 1)
17 return;
18
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);
26 }
27}
28
29static void fdt_fixup_gpu_nodes_am625(void *blob, int has_gpu)
30{
31 if (!has_gpu) {
32 fdt_del_node_path(blob, "/bus@f0000/gpu@fd00000");
33 fdt_del_node_path(blob, "/bus@f0000/watchdog@e0f0000");
34 }
35}
36
37static void fdt_fixup_pru_node_am625(void *blob, int has_pru)
38{
39 if (!has_pru)
40 fdt_del_node_path(blob, "/bus@f0000/pruss@30040000");
41}
42
Joao Paulo Goncalves6f6ffd42024-02-08 10:29:51 +010043static int fdt_fixup_trips_node(void *blob, int zoneoffset, int maxc)
44{
45 int node, trip;
46
47 node = fdt_subnode_offset(blob, zoneoffset, "trips");
48 if (node < 0)
49 return -1;
50
51 fdt_for_each_subnode(trip, blob, node) {
52 const char *type = fdt_getprop(blob, trip, "type", NULL);
53
54 if (!type || (strncmp(type, "critical", 8) != 0))
55 continue;
56
57 if (fdt_setprop_u32(blob, trip, "temperature", 1000 * maxc) < 0)
58 return -1;
59 }
60
61 return 0;
62}
63
64static void fdt_fixup_thermal_zone_nodes_am625(void *blob, int maxc)
65{
66 int node, zone;
67
68 node = fdt_path_offset(blob, "/thermal-zones");
69 if (node < 0)
70 return;
71
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));
76 }
77}
78
Parth Pancholid4c4f4f2024-10-02 09:41:33 +020079static void fdt_fixup_thermal_cooling_device_cpus_am625(void *blob, int core_nr)
80{
81 static const char * const thermal_path[] = {
82 "/thermal-zones/main0-thermal/cooling-maps/map0",
83 "/thermal-zones/main1-thermal/cooling-maps/map0"
84 };
85
86 int node, cnt, i, ret;
87 u32 cooling_dev[12];
88
89 for (i = 0; i < ARRAY_SIZE(thermal_path); i++) {
90 int new_count = core_nr * 3; /* Each CPU has 3 entries */
91 int j;
92
93 node = fdt_path_offset(blob, thermal_path[i]);
94 if (node < 0)
95 continue; /* Not found, skip it */
96
97 cnt = fdtdec_get_int_array_count(blob, node, "cooling-device",
98 cooling_dev, ARRAY_SIZE(cooling_dev));
99 if (cnt < 0)
100 continue;
101
102 for (j = 0; j < new_count; j++)
103 cooling_dev[j] = cpu_to_fdt32(cooling_dev[j]);
104
105 ret = fdt_setprop(blob, node, "cooling-device", cooling_dev,
106 new_count * sizeof(u32));
107 if (ret < 0)
108 printf("Error %s, cooling-device setprop failed %d\n",
109 thermal_path[i], ret);
110 }
111}
112
Emanuele Ghidolid7e0b072023-07-14 17:23:10 +0200113int ft_system_setup(void *blob, struct bd_info *bd)
114{
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());
Joao Paulo Goncalves6f6ffd42024-02-08 10:29:51 +0100118 fdt_fixup_thermal_zone_nodes_am625(blob, k3_get_max_temp());
Parth Pancholid4c4f4f2024-10-02 09:41:33 +0200119 fdt_fixup_thermal_cooling_device_cpus_am625(blob, k3_get_core_nr());
Andrew Davis3a7442d2024-02-14 10:30:07 -0600120 fdt_fixup_reserved(blob, "tfa", CONFIG_K3_ATF_LOAD_ADDR, 0x80000);
121 fdt_fixup_reserved(blob, "optee", CONFIG_K3_OPTEE_LOAD_ADDR, 0x1800000);
Emanuele Ghidolid7e0b072023-07-14 17:23:10 +0200122
123 return 0;
124}