]> Git Repo - J-u-boot.git/blob - arch/arm/mach-k3/am62x/am625_fdt.c
arm: mach-k3: am62: fixup thermal cooling device cpus
[J-u-boot.git] / arch / arm / mach-k3 / am62x / am625_fdt.c
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 <fdt_support.h>
8 #include <fdtdec.h>
9
10 #include "../common_fdt.h"
11
12 static 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
29 static 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
37 static 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
43 static 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
64 static 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
79 static 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
113 int 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());
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);
122
123         return 0;
124 }
This page took 0.031615 seconds and 4 git commands to generate.