blob: 96194cebcd7b0da08c30a2c516cc7e745182567f [file] [log] [blame]
Andrew Davise819fab2024-02-14 10:30:08 -06001// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Copyright (C) 2024 Texas Instruments Incorporated - https://www.ti.com/
4 */
5
6#include <asm/hardware.h>
Tom Rinia9705f02024-06-03 18:42:11 -06007#include "../common_fdt.h"
Andrew Davise819fab2024-02-14 10:30:08 -06008#include <fdt_support.h>
9
Aparna Patra3beefff2025-01-08 10:19:36 +053010static void fdt_fixup_cores_wdt_nodes_am62p(void *blob, int core_nr)
11{
12 char node_path[32];
13
14 if (core_nr < 1)
15 return;
16
17 for (; core_nr < 4; core_nr++) {
18 snprintf(node_path, sizeof(node_path), "/cpus/cpu@%d", core_nr);
19 fdt_del_node_path(blob, node_path);
20 snprintf(node_path, sizeof(node_path), "/cpus/cpu-map/cluster0/core%d", core_nr);
21 fdt_del_node_path(blob, node_path);
22 snprintf(node_path, sizeof(node_path), "/bus@f0000/watchdog@e0%d0000", core_nr);
23 fdt_del_node_path(blob, node_path);
24 }
25}
26
27static void fdt_fixup_video_codec_nodes_am62p(void *blob, bool has_video_codec)
28{
29 if (!has_video_codec)
30 fdt_del_node_path(blob, "/bus@f0000/video-codec@30210000");
31}
32
33static void fdt_fixup_canfd_nodes_am62p(void *blob, bool has_canfd)
34{
35 if (!has_canfd) {
36 fdt_del_node_path(blob, "/bus@f0000/can@20701000");
37 fdt_del_node_path(blob, "/bus@f0000/can@20711000");
38 }
39}
40
Aparna Patra657f1772025-01-08 10:19:37 +053041static int fdt_fixup_trips_node(void *blob, int zoneoffset, int maxc)
42{
43 int node, trip;
44
45 node = fdt_subnode_offset(blob, zoneoffset, "trips");
46 if (node < 0)
47 return -1;
48
49 fdt_for_each_subnode(trip, blob, node) {
50 const char *type = fdt_getprop(blob, trip, "type", NULL);
51
52 if (!type || (strncmp(type, "critical", 8) != 0))
53 continue;
54
55 if (fdt_setprop_u32(blob, trip, "temperature", 1000 * maxc) < 0)
56 return -1;
57 }
58
59 return 0;
60}
61
62static void fdt_fixup_thermal_zone_nodes_am62p(void *blob, int maxc)
63{
64 int node, zone;
65
66 node = fdt_path_offset(blob, "/thermal-zones");
67 if (node < 0)
68 return;
69
70 fdt_for_each_subnode(zone, blob, node) {
71 if (fdt_fixup_trips_node(blob, zone, maxc) < 0)
72 printf("Failed to set temperature in %s critical trips\n",
73 fdt_get_name(blob, zone, NULL));
74 }
75}
76
Andrew Davise819fab2024-02-14 10:30:08 -060077int ft_system_setup(void *blob, struct bd_info *bd)
78{
Aparna Patra3beefff2025-01-08 10:19:36 +053079 fdt_fixup_cores_wdt_nodes_am62p(blob, k3_get_core_nr());
80 fdt_fixup_video_codec_nodes_am62p(blob, k3_has_video_codec());
81 fdt_fixup_canfd_nodes_am62p(blob, k3_has_canfd());
Aparna Patra657f1772025-01-08 10:19:37 +053082 fdt_fixup_thermal_zone_nodes_am62p(blob, k3_get_max_temp());
Andrew Davise819fab2024-02-14 10:30:08 -060083 fdt_fixup_reserved(blob, "tfa", CONFIG_K3_ATF_LOAD_ADDR, 0x80000);
84 fdt_fixup_reserved(blob, "optee", CONFIG_K3_OPTEE_LOAD_ADDR, 0x1800000);
85
86 return 0;
87}