blob: 8fe200a42318c306fd7ad08a94df3ea1741de636 [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>
8
Andrew Davis336b0792024-05-10 15:21:24 -05009#include "../common_fdt.h"
10
Emanuele Ghidolid7e0b072023-07-14 17:23:10 +020011static void fdt_fixup_cores_nodes_am625(void *blob, int core_nr)
12{
13 char node_path[32];
14
15 if (core_nr < 1)
16 return;
17
18 for (; core_nr < 4; core_nr++) {
19 snprintf(node_path, sizeof(node_path), "/cpus/cpu@%d", core_nr);
20 fdt_del_node_path(blob, node_path);
21 snprintf(node_path, sizeof(node_path), "/cpus/cpu-map/cluster0/core%d", core_nr);
22 fdt_del_node_path(blob, node_path);
23 snprintf(node_path, sizeof(node_path), "/bus@f0000/watchdog@e0%d0000", core_nr);
24 fdt_del_node_path(blob, node_path);
25 }
26}
27
28static void fdt_fixup_gpu_nodes_am625(void *blob, int has_gpu)
29{
30 if (!has_gpu) {
31 fdt_del_node_path(blob, "/bus@f0000/gpu@fd00000");
32 fdt_del_node_path(blob, "/bus@f0000/watchdog@e0f0000");
33 }
34}
35
36static void fdt_fixup_pru_node_am625(void *blob, int has_pru)
37{
38 if (!has_pru)
39 fdt_del_node_path(blob, "/bus@f0000/pruss@30040000");
40}
41
Joao Paulo Goncalves6f6ffd42024-02-08 10:29:51 +010042static int fdt_fixup_trips_node(void *blob, int zoneoffset, int maxc)
43{
44 int node, trip;
45
46 node = fdt_subnode_offset(blob, zoneoffset, "trips");
47 if (node < 0)
48 return -1;
49
50 fdt_for_each_subnode(trip, blob, node) {
51 const char *type = fdt_getprop(blob, trip, "type", NULL);
52
53 if (!type || (strncmp(type, "critical", 8) != 0))
54 continue;
55
56 if (fdt_setprop_u32(blob, trip, "temperature", 1000 * maxc) < 0)
57 return -1;
58 }
59
60 return 0;
61}
62
63static void fdt_fixup_thermal_zone_nodes_am625(void *blob, int maxc)
64{
65 int node, zone;
66
67 node = fdt_path_offset(blob, "/thermal-zones");
68 if (node < 0)
69 return;
70
71 fdt_for_each_subnode(zone, blob, node) {
72 if (fdt_fixup_trips_node(blob, zone, maxc) < 0)
73 printf("Failed to set temperature in %s critical trips\n",
74 fdt_get_name(blob, zone, NULL));
75 }
76}
77
Emanuele Ghidolid7e0b072023-07-14 17:23:10 +020078int ft_system_setup(void *blob, struct bd_info *bd)
79{
80 fdt_fixup_cores_nodes_am625(blob, k3_get_core_nr());
81 fdt_fixup_gpu_nodes_am625(blob, k3_has_gpu());
82 fdt_fixup_pru_node_am625(blob, k3_has_pru());
Joao Paulo Goncalves6f6ffd42024-02-08 10:29:51 +010083 fdt_fixup_thermal_zone_nodes_am625(blob, k3_get_max_temp());
Andrew Davis3a7442d2024-02-14 10:30:07 -060084 fdt_fixup_reserved(blob, "tfa", CONFIG_K3_ATF_LOAD_ADDR, 0x80000);
85 fdt_fixup_reserved(blob, "optee", CONFIG_K3_OPTEE_LOAD_ADDR, 0x1800000);
Emanuele Ghidolid7e0b072023-07-14 17:23:10 +020086
87 return 0;
88}