1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2018 Marvell International Ltd.
5 * https://spdx.org/licenses
10 #include <fdt_support.h>
13 #include <linux/compiler.h>
14 #include <linux/libfdt.h>
16 #include <asm/arch/board.h>
17 #include <asm/arch/smc.h>
18 #include <asm/global_data.h>
21 DECLARE_GLOBAL_DATA_PTR;
23 static int fdt_get_bdk_node(void)
26 const void *fdt = gd->fdt_blob;
29 printf("ERROR: %s: no valid device tree found\n", __func__);
33 ret = fdt_check_header(fdt);
35 printf("fdt: %s\n", fdt_strerror(ret));
39 node = fdt_path_offset(fdt, "/cavium,bdk");
41 printf("%s: /cavium,bdk is missing from device tree: %s\n",
42 __func__, fdt_strerror(node));
48 u64 fdt_get_board_mac_addr(void)
51 const char *str = NULL;
52 const void *fdt = gd->fdt_blob;
55 node = fdt_get_bdk_node();
58 str = fdt_getprop(fdt, node, "BOARD-MAC-ADDRESS", &len);
60 mac_addr = simple_strtol(str, NULL, 16);
64 int fdt_get_board_mac_cnt(void)
67 const char *str = NULL;
68 const void *fdt = gd->fdt_blob;
71 node = fdt_get_bdk_node();
74 str = fdt_getprop(fdt, node, "BOARD-MAC-ADDRESS-NUM", &len);
76 mac_count = simple_strtol(str, NULL, 10);
78 mac_count = simple_strtol(str, NULL, 16);
79 debug("fdt: MAC_NUM %d\n", mac_count);
81 printf("Error: cannot retrieve mac count prop from fdt\n");
83 str = fdt_getprop(gd->fdt_blob, node, "BOARD-MAC-ADDRESS-NUM-OVERRIDE",
86 if (simple_strtol(str, NULL, 10) >= 0)
87 mac_count = simple_strtol(str, NULL, 10);
88 debug("fdt: MAC_NUM %d\n", mac_count);
90 printf("Error: cannot retrieve mac num override prop\n");
95 const char *fdt_get_board_serial(void)
97 const void *fdt = gd->fdt_blob;
99 const char *str = NULL;
101 node = fdt_get_bdk_node();
105 str = fdt_getprop(fdt, node, "BOARD-SERIAL", &len);
107 printf("Error: cannot retrieve board serial from fdt\n");
111 const char *fdt_get_board_revision(void)
113 const void *fdt = gd->fdt_blob;
115 const char *str = NULL;
117 node = fdt_get_bdk_node();
121 str = fdt_getprop(fdt, node, "BOARD-REVISION", &len);
123 printf("Error: cannot retrieve board revision from fdt\n");
127 const char *fdt_get_board_model(void)
130 const char *str = NULL;
131 const void *fdt = gd->fdt_blob;
133 node = fdt_get_bdk_node();
136 str = fdt_getprop(fdt, node, "BOARD-MODEL", &len);
138 printf("Error: cannot retrieve board model from fdt\n");
142 int arch_fixup_memory_node(void *blob)
147 int ft_board_setup(void *blob, struct bd_info *bd)
149 int nodeoff, node, ret, i;
152 static const char * const
153 octeontx_brd_nodes[] = {"BOARD-MODEL",
157 "BOARD-MAC-ADDRESS-NUM"
159 char nodes[ARRAY_SIZE(octeontx_brd_nodes)][32];
161 ret = fdt_check_header(blob);
163 printf("ERROR: %s\n", fdt_strerror(ret));
168 nodeoff = fdt_path_offset(blob, "/cavium,bdk");
170 printf("ERROR: FDT BDK node not found\n");
174 /* Read properties in temporary variables */
175 for (i = 0; i < ARRAY_SIZE(octeontx_brd_nodes); i++) {
176 temp = fdt_getprop(blob, nodeoff,
177 octeontx_brd_nodes[i], NULL);
178 strncpy(nodes[i], temp, sizeof(nodes[i]));
181 /* Delete cavium,bdk node */
182 ret = fdt_del_node(blob, nodeoff);
184 printf("WARNING : could not remove cavium, bdk node\n");
187 debug("%s deleted 'cavium,bdk' node\n", __func__);
189 * Add a new node at root level which would have
192 node = fdt_add_subnode(blob, 0, "octeontx_brd");
194 printf("Cannot create node octeontx_brd: %s\n",
199 /* Populate properties in node */
200 for (i = 0; i < ARRAY_SIZE(octeontx_brd_nodes); i++) {
201 if (fdt_setprop_string(blob, node,
202 octeontx_brd_nodes[i],
204 printf("Can't set %s\n", nodes[i]);
214 * Return the FDT base address that was passed by ATF
216 * @return FDT base address received from ATF in x1 register
218 void *board_fdt_blob_setup(void)
220 return (void *)fdt_base_addr;