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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
|
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2018 Marvell International Ltd.
*
* https://spdx.org/licenses
*/
#include <errno.h>
#include <env.h>
#include <log.h>
#include <net.h>
#include <asm/io.h>
#include <linux/compiler.h>
#include <linux/libfdt.h>
#include <fdtdec.h>
#include <fdt_support.h>
#include <asm/arch/board.h>
#include <asm/global_data.h>
DECLARE_GLOBAL_DATA_PTR;
static int fdt_get_mdio_bus(const void *fdt, int phy_offset)
{
int node, bus = -1;
const u64 *reg;
u64 addr;
if (phy_offset < 0)
return -1;
/* obtain mdio node and get the reg prop */
node = fdt_parent_offset(fdt, phy_offset);
if (node < 0)
return -1;
reg = fdt_getprop(fdt, node, "reg", NULL);
addr = fdt64_to_cpu(*reg);
bus = (addr & (1 << 7)) ? 1 : 0;
return bus;
}
static int fdt_get_phy_addr(const void *fdt, int phy_offset)
{
const u32 *reg;
int addr = -1;
if (phy_offset < 0)
return -1;
reg = fdt_getprop(fdt, phy_offset, "reg", NULL);
addr = fdt32_to_cpu(*reg);
return addr;
}
void fdt_parse_phy_info(void)
{
const void *fdt = gd->fdt_blob;
int offset = 0, node, bgx_id = 0, lmacid = 0;
const u32 *val;
char bgxname[24];
int len, rgx_id = 0, eth_id = 0;
int phandle, phy_offset;
int subnode, i;
int bdknode;
bdknode = fdt_path_offset(fdt, "/cavium,bdk");
if (bdknode < 0) {
printf("%s: bdk node is missing from device tree: %s\n",
__func__, fdt_strerror(bdknode));
}
offset = fdt_node_offset_by_compatible(fdt, -1, "pci-bridge");
if (offset < 1)
return;
for (bgx_id = 0; bgx_id < MAX_BGX_PER_NODE; bgx_id++) {
int phy_addr[LMAC_CNT] = {[0 ... LMAC_CNT - 1] = -1};
bool autoneg_dis[LMAC_CNT] = {[0 ... LMAC_CNT - 1] = 0};
int mdio_bus[LMAC_CNT] = {[0 ... LMAC_CNT - 1] = -1};
bool lmac_reg[LMAC_CNT] = {[0 ... LMAC_CNT - 1] = 0};
bool lmac_enable[LMAC_CNT] = {[0 ... LMAC_CNT - 1] = 0};
snprintf(bgxname, sizeof(bgxname), "bgx%d", bgx_id);
node = fdt_subnode_offset(fdt, offset, bgxname);
if (node < 0) {
/* check if it is rgx node */
snprintf(bgxname, sizeof(bgxname), "rgx%d", rgx_id);
node = fdt_subnode_offset(fdt, offset, bgxname);
if (node < 0) {
debug("bgx%d/rgx0 node not found\n", bgx_id);
return;
}
}
debug("bgx%d node found\n", bgx_id);
/*
* loop through each of the bgx/rgx nodes
* to find PHY nodes
*/
fdt_for_each_subnode(subnode, fdt, node) {
/* Check for reg property */
val = fdt_getprop(fdt, subnode, "reg", &len);
if (val) {
debug("lmacid = %d\n", lmacid);
lmac_reg[lmacid] = 1;
}
/* check for phy-handle property */
val = fdt_getprop(fdt, subnode, "phy-handle", &len);
if (val) {
phandle = fdt32_to_cpu(*val);
if (!phandle) {
debug("phandle not valid %d\n", lmacid);
} else {
phy_offset = fdt_node_offset_by_phandle
(fdt, phandle);
phy_addr[lmacid] = fdt_get_phy_addr
(fdt, phy_offset);
mdio_bus[lmacid] = fdt_get_mdio_bus
(fdt, phy_offset);
}
} else {
debug("phy-handle prop not found %d\n",
lmacid);
}
/* check for autonegotiation property */
val = fdt_getprop(fdt, subnode,
"cavium,disable-autonegotiation",
&len);
if (val)
autoneg_dis[lmacid] = 1;
eth_id++;
lmacid++;
}
for (i = 0; i < MAX_LMAC_PER_BGX; i++) {
const char *str;
snprintf(bgxname, sizeof(bgxname),
"BGX-ENABLE.N0.BGX%d.P%d", bgx_id, i);
if (bdknode >= 0) {
str = fdt_getprop(fdt, bdknode,
bgxname, &len);
if (str)
lmac_enable[i] =
simple_strtol(str, NULL,
10);
}
}
lmacid = 0;
bgx_set_board_info(bgx_id, mdio_bus, phy_addr,
autoneg_dis, lmac_reg, lmac_enable);
}
}
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;
}
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)
{
const void *fdt = gd->fdt_blob;
int node, len = 16;
const char *str = NULL;
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;
}
void fdt_board_get_ethaddr(int bgx, int lmac, unsigned char *eth)
{
const void *fdt = gd->fdt_blob;
const char *mac = NULL;
int offset = 0, node, len;
int subnode, i = 0;
char bgxname[24];
offset = fdt_node_offset_by_compatible(fdt, -1, "pci-bridge");
if (offset < 0) {
printf("%s couldn't find mrml bridge node in fdt\n",
__func__);
return;
}
if (bgx == 2 && otx_is_soc(CN81XX)) {
snprintf(bgxname, sizeof(bgxname), "rgx%d", 0);
lmac = 0;
} else {
snprintf(bgxname, sizeof(bgxname), "bgx%d", bgx);
}
node = fdt_subnode_offset(fdt, offset, bgxname);
fdt_for_each_subnode(subnode, fdt, node) {
if (i++ != lmac)
continue;
/* check for local-mac-address */
mac = fdt_getprop(fdt, subnode, "local-mac-address", &len);
if (mac) {
debug("%s mac %pM\n", __func__, mac);
memcpy(eth, mac, ARP_HLEN);
} else {
memset(eth, 0, ARP_HLEN);
}
debug("%s eth %pM\n", __func__, eth);
return;
}
}
int arch_fixup_memory_node(void *blob)
{
return 0;
}
int ft_board_setup(void *blob, struct bd_info *bd)
{
/* remove "cavium, bdk" node from DT */
int ret = 0, offset;
ret = fdt_check_header(blob);
if (ret < 0) {
printf("ERROR: %s\n", fdt_strerror(ret));
return ret;
}
if (blob) {
/* delete cavium,bdk node if it exists */
offset = fdt_path_offset(blob, "/cavium,bdk");
if (offset >= 0) {
ret = fdt_del_node(blob, offset);
if (ret < 0) {
printf("WARNING : could not remove bdk node\n");
return ret;
}
debug("%s deleted bdk node\n", __func__);
}
}
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;
}
|