Emanuele Ghidoli | d7e0b07 | 2023-07-14 17:23:10 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | /* |
| 3 | * Copyright 2023 Toradex - https://www.toradex.com/ |
| 4 | */ |
| 5 | |
| 6 | #include <asm/hardware.h> |
| 7 | #include "common_fdt.h" |
| 8 | #include <fdt_support.h> |
| 9 | |
| 10 | static void fdt_fixup_cores_nodes_am625(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 | |
| 27 | static void fdt_fixup_gpu_nodes_am625(void *blob, int has_gpu) |
| 28 | { |
| 29 | if (!has_gpu) { |
| 30 | fdt_del_node_path(blob, "/bus@f0000/gpu@fd00000"); |
| 31 | fdt_del_node_path(blob, "/bus@f0000/watchdog@e0f0000"); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | static void fdt_fixup_pru_node_am625(void *blob, int has_pru) |
| 36 | { |
| 37 | if (!has_pru) |
| 38 | fdt_del_node_path(blob, "/bus@f0000/pruss@30040000"); |
| 39 | } |
| 40 | |
Joao Paulo Goncalves | 6f6ffd4 | 2024-02-08 10:29:51 +0100 | [diff] [blame] | 41 | static 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 | |
| 62 | static void fdt_fixup_thermal_zone_nodes_am625(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 | |
Emanuele Ghidoli | d7e0b07 | 2023-07-14 17:23:10 +0200 | [diff] [blame] | 77 | int ft_system_setup(void *blob, struct bd_info *bd) |
| 78 | { |
| 79 | fdt_fixup_cores_nodes_am625(blob, k3_get_core_nr()); |
| 80 | fdt_fixup_gpu_nodes_am625(blob, k3_has_gpu()); |
| 81 | fdt_fixup_pru_node_am625(blob, k3_has_pru()); |
Joao Paulo Goncalves | 6f6ffd4 | 2024-02-08 10:29:51 +0100 | [diff] [blame] | 82 | fdt_fixup_thermal_zone_nodes_am625(blob, k3_get_max_temp()); |
Andrew Davis | 3a7442d | 2024-02-14 10:30:07 -0600 | [diff] [blame] | 83 | fdt_fixup_reserved(blob, "tfa", CONFIG_K3_ATF_LOAD_ADDR, 0x80000); |
| 84 | fdt_fixup_reserved(blob, "optee", CONFIG_K3_OPTEE_LOAD_ADDR, 0x1800000); |
Emanuele Ghidoli | d7e0b07 | 2023-07-14 17:23:10 +0200 | [diff] [blame] | 85 | |
| 86 | return 0; |
| 87 | } |