1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
|
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2018 Marvell International Ltd.
*
* https://spdx.org/licenses
*/
#include <errno.h>
#include <fdtdec.h>
#include <fdt_support.h>
#include <log.h>
#include <linux/compiler.h>
#include <linux/libfdt.h>
#include <asm/arch/board.h>
#include <asm/arch/smc.h>
#include <asm/global_data.h>
#include <asm/io.h>
DECLARE_GLOBAL_DATA_PTR;
static int fdt_get_bdk_node(void)
{
int node, ret;
const void *fdt = gd->fdt_blob;
if (!fdt) {
printf("ERROR: %s: no valid device tree found\n", __func__);
return 0;
}
ret = fdt_check_header(fdt);
if (ret < 0) {
printf("fdt: %s\n", fdt_strerror(ret));
return 0;
}
node = fdt_path_offset(fdt, "/cavium,bdk");
if (node < 0) {
printf("%s: /cavium,bdk is missing from device tree: %s\n",
__func__, fdt_strerror(node));
return 0;
}
return node;
}
u64 fdt_get_board_mac_addr(void)
{
int node, len = 16;
const char *str = NULL;
const void *fdt = gd->fdt_blob;
u64 mac_addr = 0;
node = fdt_get_bdk_node();
if (!node)
return mac_addr;
str = fdt_getprop(fdt, node, "BOARD-MAC-ADDRESS", &len);
if (str)
mac_addr = simple_strtol(str, NULL, 16);
return mac_addr;
}
int fdt_get_board_mac_cnt(void)
{
int node, len = 16;
const char *str = NULL;
const void *fdt = gd->fdt_blob;
int mac_count = 0;
node = fdt_get_bdk_node();
if (!node)
return mac_count;
str = fdt_getprop(fdt, node, "BOARD-MAC-ADDRESS-NUM", &len);
if (str) {
mac_count = simple_strtol(str, NULL, 10);
if (!mac_count)
mac_count = simple_strtol(str, NULL, 16);
debug("fdt: MAC_NUM %d\n", mac_count);
} else {
printf("Error: cannot retrieve mac count prop from fdt\n");
}
str = fdt_getprop(gd->fdt_blob, node, "BOARD-MAC-ADDRESS-NUM-OVERRIDE",
&len);
if (str) {
if (simple_strtol(str, NULL, 10) >= 0)
mac_count = simple_strtol(str, NULL, 10);
debug("fdt: MAC_NUM %d\n", mac_count);
} else {
printf("Error: cannot retrieve mac num override prop\n");
}
return mac_count;
}
const char *fdt_get_board_serial(void)
{
const void *fdt = gd->fdt_blob;
int node, len = 64;
const char *str = NULL;
node = fdt_get_bdk_node();
if (!node)
return NULL;
str = fdt_getprop(fdt, node, "BOARD-SERIAL", &len);
if (!str)
printf("Error: cannot retrieve board serial from fdt\n");
return str;
}
const char *fdt_get_board_revision(void)
{
const void *fdt = gd->fdt_blob;
int node, len = 64;
const char *str = NULL;
node = fdt_get_bdk_node();
if (!node)
return NULL;
str = fdt_getprop(fdt, node, "BOARD-REVISION", &len);
if (!str)
printf("Error: cannot retrieve board revision from fdt\n");
return str;
}
const char *fdt_get_board_model(void)
{
int node, len = 16;
const char *str = NULL;
const void *fdt = gd->fdt_blob;
node = fdt_get_bdk_node();
if (!node)
return NULL;
str = fdt_getprop(fdt, node, "BOARD-MODEL", &len);
if (!str)
printf("Error: cannot retrieve board model from fdt\n");
return str;
}
int arch_fixup_memory_node(void *blob)
{
return 0;
}
int ft_board_setup(void *blob, struct bd_info *bd)
{
int nodeoff, node, ret, i;
const char *temp;
static const char * const
octeontx_brd_nodes[] = {"BOARD-MODEL",
"BOARD-SERIAL",
"BOARD-MAC-ADDRESS",
"BOARD-REVISION",
"BOARD-MAC-ADDRESS-NUM"
};
char nodes[ARRAY_SIZE(octeontx_brd_nodes)][32];
ret = fdt_check_header(blob);
if (ret < 0) {
printf("ERROR: %s\n", fdt_strerror(ret));
return ret;
}
if (blob) {
nodeoff = fdt_path_offset(blob, "/cavium,bdk");
if (nodeoff < 0) {
printf("ERROR: FDT BDK node not found\n");
return nodeoff;
}
/* Read properties in temporary variables */
for (i = 0; i < ARRAY_SIZE(octeontx_brd_nodes); i++) {
temp = fdt_getprop(blob, nodeoff,
octeontx_brd_nodes[i], NULL);
strncpy(nodes[i], temp, sizeof(nodes[i]));
}
/* Delete cavium,bdk node */
ret = fdt_del_node(blob, nodeoff);
if (ret < 0) {
printf("WARNING : could not remove cavium, bdk node\n");
return ret;
}
debug("%s deleted 'cavium,bdk' node\n", __func__);
/*
* Add a new node at root level which would have
* necessary info
*/
node = fdt_add_subnode(blob, 0, "octeontx_brd");
if (node < 0) {
printf("Cannot create node octeontx_brd: %s\n",
fdt_strerror(node));
return -EIO;
}
/* Populate properties in node */
for (i = 0; i < ARRAY_SIZE(octeontx_brd_nodes); i++) {
if (fdt_setprop_string(blob, node,
octeontx_brd_nodes[i],
nodes[i])) {
printf("Can't set %s\n", nodes[i]);
return -EIO;
}
}
}
return 0;
}
/**
* Return the FDT base address that was passed by ATF
*
* Return: FDT base address received from ATF in x1 register
*/
void *board_fdt_blob_setup(int *err)
{
*err = 0;
return (void *)fdt_base_addr;
}
|