Suneel Garapati | 03c2288 | 2019-10-19 18:37:55 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Copyright (C) 2018 Marvell International Ltd. |
| 4 | * |
| 5 | * https://spdx.org/licenses |
| 6 | */ |
| 7 | |
| 8 | #include <dm.h> |
| 9 | #include <malloc.h> |
| 10 | #include <errno.h> |
| 11 | #include <env.h> |
| 12 | #include <init.h> |
| 13 | #include <log.h> |
| 14 | #include <netdev.h> |
| 15 | #include <pci_ids.h> |
| 16 | #include <asm/io.h> |
| 17 | #include <linux/compiler.h> |
| 18 | #include <linux/libfdt.h> |
| 19 | #include <fdt_support.h> |
| 20 | #include <asm/arch/smc.h> |
| 21 | #include <asm/arch/soc.h> |
| 22 | #include <asm/arch/board.h> |
| 23 | #include <dm/util.h> |
| 24 | |
| 25 | DECLARE_GLOBAL_DATA_PTR; |
| 26 | |
| 27 | void octeontx_cleanup_ethaddr(void) |
| 28 | { |
| 29 | char ename[32]; |
| 30 | |
| 31 | for (int i = 0; i < 20; i++) { |
| 32 | sprintf(ename, i ? "eth%daddr" : "ethaddr", i); |
| 33 | if (env_get(ename)) |
| 34 | env_set(ename, NULL); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | int octeontx_board_has_pmp(void) |
| 39 | { |
| 40 | return (otx_is_board("sff8104") || otx_is_board("nas8104")); |
| 41 | } |
| 42 | |
| 43 | int board_early_init_r(void) |
| 44 | { |
| 45 | pci_init(); |
| 46 | return 0; |
| 47 | } |
| 48 | |
| 49 | int board_init(void) |
| 50 | { |
| 51 | if (IS_ENABLED(CONFIG_NET_OCTEONTX)) |
| 52 | fdt_parse_phy_info(); |
| 53 | |
| 54 | return 0; |
| 55 | } |
| 56 | |
| 57 | int timer_init(void) |
| 58 | { |
| 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | int dram_init(void) |
| 63 | { |
| 64 | gd->ram_size = smc_dram_size(0); |
| 65 | gd->ram_size -= CONFIG_SYS_SDRAM_BASE; |
| 66 | mem_map_fill(); |
| 67 | |
| 68 | return 0; |
| 69 | } |
| 70 | |
| 71 | void board_late_probe_devices(void) |
| 72 | { |
| 73 | struct udevice *dev; |
| 74 | int err, bgx_cnt, i; |
| 75 | |
| 76 | /* Probe MAC(BGX) and NIC PF devices before Network stack init */ |
| 77 | bgx_cnt = otx_is_soc(CN81XX) ? 2 : 4; |
| 78 | for (i = 0; i < bgx_cnt; i++) { |
| 79 | err = dm_pci_find_device(PCI_VENDOR_ID_CAVIUM, |
| 80 | PCI_DEVICE_ID_CAVIUM_BGX, i, &dev); |
| 81 | if (err) |
| 82 | debug("%s BGX%d device not found\n", __func__, i); |
| 83 | } |
| 84 | if (otx_is_soc(CN81XX)) { |
| 85 | err = dm_pci_find_device(PCI_VENDOR_ID_CAVIUM, |
| 86 | PCI_DEVICE_ID_CAVIUM_RGX, 0, &dev); |
| 87 | if (err) |
| 88 | debug("%s RGX device not found\n", __func__); |
| 89 | } |
| 90 | err = dm_pci_find_device(PCI_VENDOR_ID_CAVIUM, |
| 91 | PCI_DEVICE_ID_CAVIUM_NIC, 0, &dev); |
| 92 | if (err) |
| 93 | debug("NIC PF device not found\n"); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Board late initialization routine. |
| 98 | */ |
| 99 | int board_late_init(void) |
| 100 | { |
| 101 | char boardname[32]; |
| 102 | char boardserial[150], boardrev[150]; |
| 103 | bool save_env = false; |
| 104 | const char *str; |
| 105 | |
| 106 | /* |
| 107 | * Try to cleanup ethaddr env variables, this is needed |
| 108 | * as with each boot, configuration of network interfaces can change. |
| 109 | */ |
| 110 | octeontx_cleanup_ethaddr(); |
| 111 | |
| 112 | snprintf(boardname, sizeof(boardname), "%s> ", fdt_get_board_model()); |
| 113 | env_set("prompt", boardname); |
| 114 | |
| 115 | set_working_fdt_addr(env_get_hex("fdtcontroladdr", fdt_base_addr)); |
| 116 | |
| 117 | str = fdt_get_board_revision(); |
| 118 | if (str) { |
| 119 | snprintf(boardrev, sizeof(boardrev), "%s", str); |
| 120 | if (env_get("boardrev") && |
| 121 | strcmp(boardrev, env_get("boardrev"))) |
| 122 | save_env = true; |
| 123 | env_set("boardrev", boardrev); |
| 124 | } |
| 125 | |
| 126 | str = fdt_get_board_serial(); |
| 127 | if (str) { |
| 128 | snprintf(boardserial, sizeof(boardserial), "%s", str); |
| 129 | if (env_get("serial#") && |
| 130 | strcmp(boardserial, env_get("serial#"))) |
| 131 | save_env = true; |
| 132 | env_set("serial#", boardserial); |
| 133 | } |
| 134 | |
| 135 | if (IS_ENABLED(CONFIG_NET_OCTEONTX)) |
| 136 | board_late_probe_devices(); |
| 137 | |
| 138 | if (save_env) |
| 139 | env_save(); |
| 140 | |
| 141 | return 0; |
| 142 | } |
| 143 | |
| 144 | /* |
| 145 | * Invoked before relocation, so limit to stack variables. |
| 146 | */ |
| 147 | int checkboard(void) |
| 148 | { |
| 149 | printf("Board: %s\n", fdt_get_board_model()); |
| 150 | |
| 151 | return 0; |
| 152 | } |