1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2018 Marvell International Ltd.
5 * https://spdx.org/licenses
12 #include <asm/global_data.h>
13 #include <dm/uclass-internal.h>
21 #include <linux/compiler.h>
22 #include <linux/delay.h>
23 #include <linux/libfdt.h>
24 #include <fdt_support.h>
25 #include <asm/arch/smc.h>
26 #include <asm/arch/soc.h>
27 #include <asm/arch/board.h>
30 DECLARE_GLOBAL_DATA_PTR;
32 void cleanup_env_ethaddr(void)
36 for (int i = 0; i < 20; i++) {
37 sprintf(ename, i ? "eth%daddr" : "ethaddr", i);
43 void octeontx2_board_get_mac_addr(u8 index, u8 *mac_addr)
45 u64 tmp_mac, board_mac_addr = fdt_get_board_mac_addr();
46 static int board_mac_num;
48 board_mac_num = fdt_get_board_mac_cnt();
49 if ((!is_zero_ethaddr((u8 *)&board_mac_addr)) && board_mac_num) {
50 tmp_mac = board_mac_addr;
52 tmp_mac = swab64(tmp_mac) >> 16;
53 memcpy(mac_addr, (u8 *)&tmp_mac, ARP_HLEN);
56 memset(mac_addr, 0, ARP_HLEN);
58 debug("%s mac %pM\n", __func__, mac_addr);
61 void board_quiesce_devices(void)
63 struct uclass *uc_dev;
66 /* Removes all RVU PF devices */
67 ret = uclass_get(UCLASS_ETH, &uc_dev);
69 ret = uclass_destroy(uc_dev);
71 printf("couldn't remove rvu pf devices\n");
73 if (IS_ENABLED(CONFIG_OCTEONTX2_CGX_INTF)) {
74 /* Bring down all cgx lmac links */
78 /* Removes all CGX and RVU AF devices */
79 ret = uclass_get(UCLASS_MISC, &uc_dev);
81 ret = uclass_destroy(uc_dev);
83 printf("couldn't remove misc (cgx/rvu_af) devices\n");
85 /* SMC call - removes all LF<->PF mappings */
86 smc_disable_rvu_lfs(0);
89 int board_early_init_r(void)
107 gd->ram_size = smc_dram_size(0);
108 gd->ram_size -= CONFIG_SYS_SDRAM_BASE;
115 void board_late_probe_devices(void)
118 int err, cgx_cnt = 3, i;
120 /* Probe MAC(CGX) and NIC AF devices before Network stack init */
121 for (i = 0; i < cgx_cnt; i++) {
122 err = dm_pci_find_device(PCI_VENDOR_ID_CAVIUM,
123 PCI_DEVICE_ID_CAVIUM_CGX, i, &dev);
125 debug("%s CGX%d device not found\n", __func__, i);
127 err = dm_pci_find_device(PCI_VENDOR_ID_CAVIUM,
128 PCI_DEVICE_ID_CAVIUM_RVU_AF, 0, &dev);
130 debug("NIC AF device not found\n");
134 * Board late initialization routine.
136 int board_late_init(void)
139 char boardserial[150], boardrev[150];
141 bool save_env = false;
144 debug("%s()\n", __func__);
147 * Now that pci_init initializes env device.
148 * Try to cleanup ethaddr env variables, this is needed
149 * as with each boot, configuration of QLM can change.
151 cleanup_env_ethaddr();
153 snprintf(boardname, sizeof(boardname), "%s> ", fdt_get_board_model());
154 env_set("prompt", boardname);
155 set_working_fdt_addr(env_get_hex("fdtcontroladdr", fdt_base_addr));
157 str = fdt_get_board_revision();
159 snprintf(boardrev, sizeof(boardrev), "%s", str);
160 if (env_get("boardrev") &&
161 strcmp(boardrev, env_get("boardrev")))
163 env_set("boardrev", boardrev);
166 str = fdt_get_board_serial();
168 snprintf(boardserial, sizeof(boardserial), "%s", str);
169 if (env_get("serial#") &&
170 strcmp(boardserial, env_get("serial#")))
172 env_set("serial#", boardserial);
175 val = env_get_hex("disable_ooo", 0);
176 smc_configure_ooo(val);
178 if (IS_ENABLED(CONFIG_NET_OCTEONTX2))
179 board_late_probe_devices();
188 * Invoked before relocation, so limit to stack variables.
192 printf("Board: %s\n", fdt_get_board_model());
197 void board_acquire_flash_arb(bool acquire)
199 union cpc_boot_ownerx ownerx;
202 ownerx.u = readl(CPC_BOOT_OWNERX(3));
203 ownerx.s.boot_req = 0;
204 writel(ownerx.u, CPC_BOOT_OWNERX(3));
207 ownerx.s.boot_req = 1;
208 writel(ownerx.u, CPC_BOOT_OWNERX(3));
211 ownerx.u = readl(CPC_BOOT_OWNERX(3));
212 } while (ownerx.s.boot_wait);
216 int last_stage_init(void)
218 (void)smc_flsf_fw_booted();
222 static int do_go_uboot(struct cmd_tbl *cmdtp, int flag, int argc,
225 typedef void __noreturn (*uboot_entry_t)(ulong, void *);
231 return CMD_RET_USAGE;
233 addr = simple_strtoul(argv[1], NULL, 16);
234 fdt = board_fdt_blob_setup();
235 entry = (uboot_entry_t)addr;
236 flush_cache((ulong)addr, 1 << 20); /* 1MiB should be enough */
239 printf("## Starting U-Boot at %p (FDT at %p)...\n", entry, fdt);
246 U_BOOT_CMD(go_uboot, 2, 0, do_go_uboot,
247 "Start U-Boot from RAM (pass FDT via x1 register)",