Michal Simek | 2e53eb2 | 2022-09-19 14:21:02 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Copyright (C) 2021 - 2022, Xilinx, Inc. |
| 4 | * Copyright (C) 2022, Advanced Micro Devices, Inc. |
| 5 | * |
| 6 | * Michal Simek <michal.simek@amd.com> |
| 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <cpu_func.h> |
| 11 | #include <fdtdec.h> |
| 12 | #include <init.h> |
| 13 | #include <log.h> |
| 14 | #include <malloc.h> |
| 15 | #include <time.h> |
| 16 | #include <asm/cache.h> |
| 17 | #include <asm/global_data.h> |
| 18 | #include <asm/io.h> |
| 19 | #include <asm/arch/hardware.h> |
| 20 | #include <asm/arch/sys_proto.h> |
| 21 | #include <dm/device.h> |
| 22 | #include <dm/uclass.h> |
| 23 | #include "../common/board.h" |
| 24 | |
| 25 | #include <linux/bitfield.h> |
| 26 | #include <debug_uart.h> |
| 27 | #include <generated/dt.h> |
| 28 | |
| 29 | DECLARE_GLOBAL_DATA_PTR; |
| 30 | |
| 31 | int board_init(void) |
| 32 | { |
| 33 | printf("EL Level:\tEL%d\n", current_el()); |
| 34 | |
| 35 | return 0; |
| 36 | } |
| 37 | |
| 38 | static u32 platform_id, platform_version; |
| 39 | |
| 40 | char *soc_name_decode(void) |
| 41 | { |
| 42 | char *name, *platform_name; |
| 43 | |
| 44 | switch (platform_id) { |
| 45 | case VERSAL_NET_SPP: |
| 46 | platform_name = "ipp"; |
| 47 | break; |
| 48 | case VERSAL_NET_EMU: |
| 49 | platform_name = "emu"; |
| 50 | break; |
| 51 | case VERSAL_NET_QEMU: |
| 52 | platform_name = "qemu"; |
| 53 | break; |
| 54 | default: |
| 55 | return NULL; |
| 56 | } |
| 57 | |
| 58 | /* |
| 59 | * --rev. are 6 chars |
| 60 | * max platform name is qemu which is 4 chars |
| 61 | * platform version number are 1+1 |
| 62 | * Plus 1 char for \n |
| 63 | */ |
| 64 | name = calloc(1, strlen(CONFIG_SYS_BOARD) + 13); |
| 65 | if (!name) |
| 66 | return NULL; |
| 67 | |
| 68 | sprintf(name, "%s-%s-rev%d.%d", CONFIG_SYS_BOARD, |
| 69 | platform_name, platform_version / 10, |
| 70 | platform_version % 10); |
| 71 | |
| 72 | return name; |
| 73 | } |
| 74 | |
| 75 | bool soc_detection(void) |
| 76 | { |
| 77 | u32 version; |
| 78 | |
| 79 | version = readl(PMC_TAP_VERSION); |
| 80 | platform_id = FIELD_GET(PLATFORM_MASK, version); |
| 81 | |
| 82 | debug("idcode %x, version %x, usercode %x\n", |
| 83 | readl(PMC_TAP_IDCODE), version, |
| 84 | readl(PMC_TAP_USERCODE)); |
| 85 | |
| 86 | debug("pmc_ver %lx, ps version %lx, rtl version %lx\n", |
| 87 | FIELD_GET(PMC_VERSION_MASK, version), |
| 88 | FIELD_GET(PS_VERSION_MASK, version), |
| 89 | FIELD_GET(RTL_VERSION_MASK, version)); |
| 90 | |
| 91 | platform_version = FIELD_GET(PLATFORM_VERSION_MASK, version); |
| 92 | |
| 93 | if (platform_id == VERSAL_NET_SPP || |
| 94 | platform_id == VERSAL_NET_EMU) { |
| 95 | /* |
| 96 | * 9 is diff for |
| 97 | * 0 means 0.9 version |
| 98 | * 1 means 1.0 version |
| 99 | * 2 means 1.1 version |
| 100 | * etc, |
| 101 | */ |
| 102 | platform_version += 9; |
| 103 | } |
| 104 | |
| 105 | debug("Platform id: %d version: %d.%d\n", platform_id, |
| 106 | platform_version / 10, platform_version % 10); |
| 107 | |
| 108 | return true; |
| 109 | } |
| 110 | |
| 111 | int board_early_init_f(void) |
| 112 | { |
| 113 | if (IS_ENABLED(CONFIG_DEBUG_UART)) { |
| 114 | /* Uart debug for sure */ |
| 115 | debug_uart_init(); |
| 116 | puts("Debug uart enabled\n"); /* or printch() */ |
| 117 | } |
| 118 | |
| 119 | return 0; |
| 120 | } |
| 121 | |
| 122 | int board_early_init_r(void) |
| 123 | { |
Ashok Reddy Soma | 8162732 | 2023-01-10 08:44:07 +0100 | [diff] [blame] | 124 | u32 val; |
| 125 | |
| 126 | if (current_el() != 3) |
| 127 | return 0; |
| 128 | |
| 129 | debug("iou_switch ctrl div0 %x\n", |
| 130 | readl(&crlapb_base->iou_switch_ctrl)); |
| 131 | |
| 132 | writel(IOU_SWITCH_CTRL_CLKACT_BIT | |
| 133 | (CONFIG_IOU_SWITCH_DIVISOR0 << IOU_SWITCH_CTRL_DIVISOR0_SHIFT), |
| 134 | &crlapb_base->iou_switch_ctrl); |
| 135 | |
| 136 | /* Global timer init - Program time stamp reference clk */ |
| 137 | val = readl(&crlapb_base->timestamp_ref_ctrl); |
| 138 | val |= CRL_APB_TIMESTAMP_REF_CTRL_CLKACT_BIT; |
| 139 | writel(val, &crlapb_base->timestamp_ref_ctrl); |
| 140 | |
| 141 | debug("ref ctrl 0x%x\n", |
| 142 | readl(&crlapb_base->timestamp_ref_ctrl)); |
| 143 | |
| 144 | /* Clear reset of timestamp reg */ |
| 145 | writel(0, &crlapb_base->rst_timestamp); |
| 146 | |
| 147 | /* |
| 148 | * Program freq register in System counter and |
| 149 | * enable system counter. |
| 150 | */ |
| 151 | writel(CONFIG_COUNTER_FREQUENCY, |
| 152 | &iou_scntr_secure->base_frequency_id_register); |
| 153 | |
| 154 | debug("counter val 0x%x\n", |
| 155 | readl(&iou_scntr_secure->base_frequency_id_register)); |
| 156 | |
| 157 | writel(IOU_SCNTRS_CONTROL_EN, |
| 158 | &iou_scntr_secure->counter_control_register); |
| 159 | |
| 160 | debug("scntrs control 0x%x\n", |
| 161 | readl(&iou_scntr_secure->counter_control_register)); |
| 162 | debug("timer 0x%llx\n", get_ticks()); |
| 163 | debug("timer 0x%llx\n", get_ticks()); |
| 164 | |
Michal Simek | 2e53eb2 | 2022-09-19 14:21:02 +0200 | [diff] [blame] | 165 | return 0; |
| 166 | } |
| 167 | |
| 168 | int board_late_init(void) |
| 169 | { |
| 170 | if (!(gd->flags & GD_FLG_ENV_DEFAULT)) { |
| 171 | debug("Saved variables - Skipping\n"); |
| 172 | return 0; |
| 173 | } |
| 174 | |
Simon Glass | 094778f | 2023-02-05 15:39:49 -0700 | [diff] [blame] | 175 | if (!IS_ENABLED(CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG)) |
Michal Simek | 2e53eb2 | 2022-09-19 14:21:02 +0200 | [diff] [blame] | 176 | return 0; |
| 177 | |
| 178 | return board_late_init_xilinx(); |
| 179 | } |
| 180 | |
| 181 | int dram_init_banksize(void) |
| 182 | { |
| 183 | int ret; |
| 184 | |
| 185 | ret = fdtdec_setup_memory_banksize(); |
| 186 | if (ret) |
| 187 | return ret; |
| 188 | |
| 189 | mem_map_fill(); |
| 190 | |
| 191 | return 0; |
| 192 | } |
| 193 | |
| 194 | int dram_init(void) |
| 195 | { |
| 196 | int ret; |
| 197 | |
Simon Glass | ea0ada3 | 2023-02-05 15:40:57 -0700 | [diff] [blame] | 198 | if (IS_ENABLED(CONFIG_SYS_MEM_RSVD_FOR_MMU)) |
Michal Simek | 2e53eb2 | 2022-09-19 14:21:02 +0200 | [diff] [blame] | 199 | ret = fdtdec_setup_mem_size_base(); |
| 200 | else |
| 201 | ret = fdtdec_setup_mem_size_base_lowest(); |
| 202 | |
| 203 | if (ret) |
| 204 | return -EINVAL; |
| 205 | |
| 206 | return 0; |
| 207 | } |
| 208 | |
| 209 | void reset_cpu(void) |
| 210 | { |
| 211 | } |