1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2018 Marvell International Ltd.
5 * https://spdx.org/licenses
12 #include <dm/uclass-internal.h>
20 #include <linux/compiler.h>
21 #include <linux/delay.h>
22 #include <linux/libfdt.h>
23 #include <fdt_support.h>
24 #include <asm/arch/smc.h>
25 #include <asm/arch/soc.h>
26 #include <asm/arch/board.h>
29 DECLARE_GLOBAL_DATA_PTR;
31 void cleanup_env_ethaddr(void)
35 for (int i = 0; i < 20; i++) {
36 sprintf(ename, i ? "eth%daddr" : "ethaddr", i);
42 void octeontx2_board_get_mac_addr(u8 index, u8 *mac_addr)
44 u64 tmp_mac, board_mac_addr = fdt_get_board_mac_addr();
45 static int board_mac_num;
47 board_mac_num = fdt_get_board_mac_cnt();
48 if ((!is_zero_ethaddr((u8 *)&board_mac_addr)) && board_mac_num) {
49 tmp_mac = board_mac_addr;
51 tmp_mac = swab64(tmp_mac) >> 16;
52 memcpy(mac_addr, (u8 *)&tmp_mac, ARP_HLEN);
55 memset(mac_addr, 0, ARP_HLEN);
57 debug("%s mac %pM\n", __func__, mac_addr);
60 void board_quiesce_devices(void)
62 struct uclass *uc_dev;
65 /* Removes all RVU PF devices */
66 ret = uclass_get(UCLASS_ETH, &uc_dev);
68 ret = uclass_destroy(uc_dev);
70 printf("couldn't remove rvu pf devices\n");
72 if (IS_ENABLED(CONFIG_OCTEONTX2_CGX_INTF)) {
73 /* Bring down all cgx lmac links */
77 /* Removes all CGX and RVU AF devices */
78 ret = uclass_get(UCLASS_MISC, &uc_dev);
80 ret = uclass_destroy(uc_dev);
82 printf("couldn't remove misc (cgx/rvu_af) devices\n");
84 /* SMC call - removes all LF<->PF mappings */
85 smc_disable_rvu_lfs(0);
88 int board_early_init_r(void)
106 gd->ram_size = smc_dram_size(0);
107 gd->ram_size -= CONFIG_SYS_SDRAM_BASE;
114 void board_late_probe_devices(void)
117 int err, cgx_cnt = 3, i;
119 /* Probe MAC(CGX) and NIC AF devices before Network stack init */
120 for (i = 0; i < cgx_cnt; i++) {
121 err = dm_pci_find_device(PCI_VENDOR_ID_CAVIUM,
122 PCI_DEVICE_ID_CAVIUM_CGX, i, &dev);
124 debug("%s CGX%d device not found\n", __func__, i);
126 err = dm_pci_find_device(PCI_VENDOR_ID_CAVIUM,
127 PCI_DEVICE_ID_CAVIUM_RVU_AF, 0, &dev);
129 debug("NIC AF device not found\n");
133 * Board late initialization routine.
135 int board_late_init(void)
138 char boardserial[150], boardrev[150];
140 bool save_env = false;
143 debug("%s()\n", __func__);
146 * Now that pci_init initializes env device.
147 * Try to cleanup ethaddr env variables, this is needed
148 * as with each boot, configuration of QLM can change.
150 cleanup_env_ethaddr();
152 snprintf(boardname, sizeof(boardname), "%s> ", fdt_get_board_model());
153 env_set("prompt", boardname);
154 set_working_fdt_addr(env_get_hex("fdtcontroladdr", fdt_base_addr));
156 str = fdt_get_board_revision();
158 snprintf(boardrev, sizeof(boardrev), "%s", str);
159 if (env_get("boardrev") &&
160 strcmp(boardrev, env_get("boardrev")))
162 env_set("boardrev", boardrev);
165 str = fdt_get_board_serial();
167 snprintf(boardserial, sizeof(boardserial), "%s", str);
168 if (env_get("serial#") &&
169 strcmp(boardserial, env_get("serial#")))
171 env_set("serial#", boardserial);
174 val = env_get_hex("disable_ooo", 0);
175 smc_configure_ooo(val);
177 if (IS_ENABLED(CONFIG_NET_OCTEONTX2))
178 board_late_probe_devices();
187 * Invoked before relocation, so limit to stack variables.
191 printf("Board: %s\n", fdt_get_board_model());
196 void board_acquire_flash_arb(bool acquire)
198 union cpc_boot_ownerx ownerx;
201 ownerx.u = readl(CPC_BOOT_OWNERX(3));
202 ownerx.s.boot_req = 0;
203 writel(ownerx.u, CPC_BOOT_OWNERX(3));
206 ownerx.s.boot_req = 1;
207 writel(ownerx.u, CPC_BOOT_OWNERX(3));
210 ownerx.u = readl(CPC_BOOT_OWNERX(3));
211 } while (ownerx.s.boot_wait);
215 int last_stage_init(void)
217 (void)smc_flsf_fw_booted();
221 static int do_go_uboot(struct cmd_tbl *cmdtp, int flag, int argc,
224 typedef void __noreturn (*uboot_entry_t)(ulong, void *);
230 return CMD_RET_USAGE;
232 addr = simple_strtoul(argv[1], NULL, 16);
233 fdt = board_fdt_blob_setup();
234 entry = (uboot_entry_t)addr;
235 flush_cache((ulong)addr, 1 << 20); /* 1MiB should be enough */
238 printf("## Starting U-Boot at %p (FDT at %p)...\n", entry, fdt);
245 U_BOOT_CMD(go_uboot, 2, 0, do_go_uboot,
246 "Start U-Boot from RAM (pass FDT via x1 register)",