1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2018 Marvell International Ltd.
5 * https://spdx.org/licenses
13 #include <linux/compiler.h>
14 #include <linux/libfdt.h>
16 #include <fdt_support.h>
17 #include <asm/arch/board.h>
18 #include <asm/global_data.h>
20 DECLARE_GLOBAL_DATA_PTR;
22 static int fdt_get_mdio_bus(const void *fdt, int phy_offset)
30 /* obtain mdio node and get the reg prop */
31 node = fdt_parent_offset(fdt, phy_offset);
35 reg = fdt_getprop(fdt, node, "reg", NULL);
36 addr = fdt64_to_cpu(*reg);
37 bus = (addr & (1 << 7)) ? 1 : 0;
41 static int fdt_get_phy_addr(const void *fdt, int phy_offset)
48 reg = fdt_getprop(fdt, phy_offset, "reg", NULL);
49 addr = fdt32_to_cpu(*reg);
53 void fdt_parse_phy_info(void)
55 const void *fdt = gd->fdt_blob;
56 int offset = 0, node, bgx_id = 0, lmacid = 0;
59 int len, rgx_id = 0, eth_id = 0;
60 int phandle, phy_offset;
64 bdknode = fdt_path_offset(fdt, "/cavium,bdk");
66 printf("%s: bdk node is missing from device tree: %s\n",
67 __func__, fdt_strerror(bdknode));
70 offset = fdt_node_offset_by_compatible(fdt, -1, "pci-bridge");
74 for (bgx_id = 0; bgx_id < MAX_BGX_PER_NODE; bgx_id++) {
75 int phy_addr[LMAC_CNT] = {[0 ... LMAC_CNT - 1] = -1};
76 bool autoneg_dis[LMAC_CNT] = {[0 ... LMAC_CNT - 1] = 0};
77 int mdio_bus[LMAC_CNT] = {[0 ... LMAC_CNT - 1] = -1};
78 bool lmac_reg[LMAC_CNT] = {[0 ... LMAC_CNT - 1] = 0};
79 bool lmac_enable[LMAC_CNT] = {[0 ... LMAC_CNT - 1] = 0};
81 snprintf(bgxname, sizeof(bgxname), "bgx%d", bgx_id);
82 node = fdt_subnode_offset(fdt, offset, bgxname);
84 /* check if it is rgx node */
85 snprintf(bgxname, sizeof(bgxname), "rgx%d", rgx_id);
86 node = fdt_subnode_offset(fdt, offset, bgxname);
88 debug("bgx%d/rgx0 node not found\n", bgx_id);
92 debug("bgx%d node found\n", bgx_id);
95 * loop through each of the bgx/rgx nodes
98 fdt_for_each_subnode(subnode, fdt, node) {
99 /* Check for reg property */
100 val = fdt_getprop(fdt, subnode, "reg", &len);
102 debug("lmacid = %d\n", lmacid);
103 lmac_reg[lmacid] = 1;
105 /* check for phy-handle property */
106 val = fdt_getprop(fdt, subnode, "phy-handle", &len);
108 phandle = fdt32_to_cpu(*val);
110 debug("phandle not valid %d\n", lmacid);
112 phy_offset = fdt_node_offset_by_phandle
114 phy_addr[lmacid] = fdt_get_phy_addr
116 mdio_bus[lmacid] = fdt_get_mdio_bus
120 debug("phy-handle prop not found %d\n",
123 /* check for autonegotiation property */
124 val = fdt_getprop(fdt, subnode,
125 "cavium,disable-autonegotiation",
128 autoneg_dis[lmacid] = 1;
134 for (i = 0; i < MAX_LMAC_PER_BGX; i++) {
137 snprintf(bgxname, sizeof(bgxname),
138 "BGX-ENABLE.N0.BGX%d.P%d", bgx_id, i);
140 str = fdt_getprop(fdt, bdknode,
144 simple_strtol(str, NULL,
150 bgx_set_board_info(bgx_id, mdio_bus, phy_addr,
151 autoneg_dis, lmac_reg, lmac_enable);
155 static int fdt_get_bdk_node(void)
158 const void *fdt = gd->fdt_blob;
161 printf("ERROR: %s: no valid device tree found\n", __func__);
165 ret = fdt_check_header(fdt);
167 printf("fdt: %s\n", fdt_strerror(ret));
171 node = fdt_path_offset(fdt, "/cavium,bdk");
173 printf("%s: /cavium,bdk is missing from device tree: %s\n",
174 __func__, fdt_strerror(node));
180 const char *fdt_get_board_serial(void)
182 const void *fdt = gd->fdt_blob;
184 const char *str = NULL;
186 node = fdt_get_bdk_node();
190 str = fdt_getprop(fdt, node, "BOARD-SERIAL", &len);
192 printf("Error: cannot retrieve board serial from fdt\n");
196 const char *fdt_get_board_revision(void)
198 const void *fdt = gd->fdt_blob;
200 const char *str = NULL;
202 node = fdt_get_bdk_node();
206 str = fdt_getprop(fdt, node, "BOARD-REVISION", &len);
208 printf("Error: cannot retrieve board revision from fdt\n");
212 const char *fdt_get_board_model(void)
214 const void *fdt = gd->fdt_blob;
216 const char *str = NULL;
218 node = fdt_get_bdk_node();
222 str = fdt_getprop(fdt, node, "BOARD-MODEL", &len);
224 printf("Error: cannot retrieve board model from fdt\n");
228 void fdt_board_get_ethaddr(int bgx, int lmac, unsigned char *eth)
230 const void *fdt = gd->fdt_blob;
231 const char *mac = NULL;
232 int offset = 0, node, len;
236 offset = fdt_node_offset_by_compatible(fdt, -1, "pci-bridge");
238 printf("%s couldn't find mrml bridge node in fdt\n",
242 if (bgx == 2 && otx_is_soc(CN81XX)) {
243 snprintf(bgxname, sizeof(bgxname), "rgx%d", 0);
246 snprintf(bgxname, sizeof(bgxname), "bgx%d", bgx);
249 node = fdt_subnode_offset(fdt, offset, bgxname);
251 fdt_for_each_subnode(subnode, fdt, node) {
254 /* check for local-mac-address */
255 mac = fdt_getprop(fdt, subnode, "local-mac-address", &len);
257 debug("%s mac %pM\n", __func__, mac);
258 memcpy(eth, mac, ARP_HLEN);
260 memset(eth, 0, ARP_HLEN);
262 debug("%s eth %pM\n", __func__, eth);
267 int arch_fixup_memory_node(void *blob)
272 int ft_board_setup(void *blob, struct bd_info *bd)
274 /* remove "cavium, bdk" node from DT */
277 ret = fdt_check_header(blob);
279 printf("ERROR: %s\n", fdt_strerror(ret));
284 offset = fdt_path_offset(blob, "/cavium,bdk");
286 printf("ERROR: FDT BDK node not found\n");
291 ret = fdt_del_node(blob, offset);
293 printf("WARNING : could not remove bdk node\n");
297 debug("%s deleted bdk node\n", __func__);
304 * Return the FDT base address that was passed by ATF
306 * @return FDT base address received from ATF in x1 register
308 void *board_fdt_blob_setup(void)
310 return (void *)fdt_base_addr;