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> |
Ashok Reddy Soma | a7a5a1b | 2023-05-16 08:47:53 -0600 | [diff] [blame] | 13 | #include <env_internal.h> |
Michal Simek | 2e53eb2 | 2022-09-19 14:21:02 +0200 | [diff] [blame] | 14 | #include <log.h> |
| 15 | #include <malloc.h> |
| 16 | #include <time.h> |
| 17 | #include <asm/cache.h> |
| 18 | #include <asm/global_data.h> |
| 19 | #include <asm/io.h> |
| 20 | #include <asm/arch/hardware.h> |
| 21 | #include <asm/arch/sys_proto.h> |
| 22 | #include <dm/device.h> |
| 23 | #include <dm/uclass.h> |
| 24 | #include "../common/board.h" |
| 25 | |
| 26 | #include <linux/bitfield.h> |
| 27 | #include <debug_uart.h> |
| 28 | #include <generated/dt.h> |
| 29 | |
| 30 | DECLARE_GLOBAL_DATA_PTR; |
| 31 | |
| 32 | int board_init(void) |
| 33 | { |
| 34 | printf("EL Level:\tEL%d\n", current_el()); |
| 35 | |
| 36 | return 0; |
| 37 | } |
| 38 | |
| 39 | static u32 platform_id, platform_version; |
| 40 | |
| 41 | char *soc_name_decode(void) |
| 42 | { |
| 43 | char *name, *platform_name; |
| 44 | |
| 45 | switch (platform_id) { |
| 46 | case VERSAL_NET_SPP: |
| 47 | platform_name = "ipp"; |
| 48 | break; |
| 49 | case VERSAL_NET_EMU: |
| 50 | platform_name = "emu"; |
| 51 | break; |
| 52 | case VERSAL_NET_QEMU: |
| 53 | platform_name = "qemu"; |
| 54 | break; |
| 55 | default: |
| 56 | return NULL; |
| 57 | } |
| 58 | |
| 59 | /* |
| 60 | * --rev. are 6 chars |
| 61 | * max platform name is qemu which is 4 chars |
| 62 | * platform version number are 1+1 |
| 63 | * Plus 1 char for \n |
| 64 | */ |
| 65 | name = calloc(1, strlen(CONFIG_SYS_BOARD) + 13); |
| 66 | if (!name) |
| 67 | return NULL; |
| 68 | |
| 69 | sprintf(name, "%s-%s-rev%d.%d", CONFIG_SYS_BOARD, |
| 70 | platform_name, platform_version / 10, |
| 71 | platform_version % 10); |
| 72 | |
| 73 | return name; |
| 74 | } |
| 75 | |
| 76 | bool soc_detection(void) |
| 77 | { |
Michal Simek | ba73d6e | 2023-05-17 10:21:32 +0200 | [diff] [blame] | 78 | u32 version, ps_version; |
Michal Simek | 2e53eb2 | 2022-09-19 14:21:02 +0200 | [diff] [blame] | 79 | |
| 80 | version = readl(PMC_TAP_VERSION); |
| 81 | platform_id = FIELD_GET(PLATFORM_MASK, version); |
Michal Simek | ba73d6e | 2023-05-17 10:21:32 +0200 | [diff] [blame] | 82 | ps_version = FIELD_GET(PS_VERSION_MASK, version); |
Michal Simek | 2e53eb2 | 2022-09-19 14:21:02 +0200 | [diff] [blame] | 83 | |
| 84 | debug("idcode %x, version %x, usercode %x\n", |
| 85 | readl(PMC_TAP_IDCODE), version, |
| 86 | readl(PMC_TAP_USERCODE)); |
| 87 | |
Michal Simek | ba73d6e | 2023-05-17 10:21:32 +0200 | [diff] [blame] | 88 | debug("pmc_ver %lx, ps version %x, rtl version %lx\n", |
Michal Simek | 2e53eb2 | 2022-09-19 14:21:02 +0200 | [diff] [blame] | 89 | FIELD_GET(PMC_VERSION_MASK, version), |
Michal Simek | ba73d6e | 2023-05-17 10:21:32 +0200 | [diff] [blame] | 90 | ps_version, |
Michal Simek | 2e53eb2 | 2022-09-19 14:21:02 +0200 | [diff] [blame] | 91 | FIELD_GET(RTL_VERSION_MASK, version)); |
| 92 | |
| 93 | platform_version = FIELD_GET(PLATFORM_VERSION_MASK, version); |
| 94 | |
| 95 | if (platform_id == VERSAL_NET_SPP || |
| 96 | platform_id == VERSAL_NET_EMU) { |
Michal Simek | ba73d6e | 2023-05-17 10:21:32 +0200 | [diff] [blame] | 97 | if (ps_version == PS_VERSION_PRODUCTION) { |
| 98 | /* |
| 99 | * ES1 version ends at 1.9 version where there was +9 |
| 100 | * used because of IPP/SPP conversion. Production |
| 101 | * version have platform_version started from 0 again |
| 102 | * that's why adding +20 to continue with the same line. |
| 103 | * It means the last ES1 version ends at 1.9 version and |
| 104 | * new PRODUCTION line starts at 2.0. |
| 105 | */ |
| 106 | platform_version += 20; |
| 107 | } else { |
| 108 | /* |
| 109 | * 9 is diff for |
| 110 | * 0 means 0.9 version |
| 111 | * 1 means 1.0 version |
| 112 | * 2 means 1.1 version |
| 113 | * etc, |
| 114 | */ |
| 115 | platform_version += 9; |
| 116 | } |
Michal Simek | 2e53eb2 | 2022-09-19 14:21:02 +0200 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | debug("Platform id: %d version: %d.%d\n", platform_id, |
| 120 | platform_version / 10, platform_version % 10); |
| 121 | |
| 122 | return true; |
| 123 | } |
| 124 | |
| 125 | int board_early_init_f(void) |
| 126 | { |
| 127 | if (IS_ENABLED(CONFIG_DEBUG_UART)) { |
| 128 | /* Uart debug for sure */ |
| 129 | debug_uart_init(); |
| 130 | puts("Debug uart enabled\n"); /* or printch() */ |
| 131 | } |
| 132 | |
| 133 | return 0; |
| 134 | } |
| 135 | |
| 136 | int board_early_init_r(void) |
| 137 | { |
Ashok Reddy Soma | 8162732 | 2023-01-10 08:44:07 +0100 | [diff] [blame] | 138 | u32 val; |
| 139 | |
| 140 | if (current_el() != 3) |
| 141 | return 0; |
| 142 | |
| 143 | debug("iou_switch ctrl div0 %x\n", |
| 144 | readl(&crlapb_base->iou_switch_ctrl)); |
| 145 | |
| 146 | writel(IOU_SWITCH_CTRL_CLKACT_BIT | |
| 147 | (CONFIG_IOU_SWITCH_DIVISOR0 << IOU_SWITCH_CTRL_DIVISOR0_SHIFT), |
| 148 | &crlapb_base->iou_switch_ctrl); |
| 149 | |
| 150 | /* Global timer init - Program time stamp reference clk */ |
| 151 | val = readl(&crlapb_base->timestamp_ref_ctrl); |
| 152 | val |= CRL_APB_TIMESTAMP_REF_CTRL_CLKACT_BIT; |
| 153 | writel(val, &crlapb_base->timestamp_ref_ctrl); |
| 154 | |
| 155 | debug("ref ctrl 0x%x\n", |
| 156 | readl(&crlapb_base->timestamp_ref_ctrl)); |
| 157 | |
| 158 | /* Clear reset of timestamp reg */ |
| 159 | writel(0, &crlapb_base->rst_timestamp); |
| 160 | |
| 161 | /* |
| 162 | * Program freq register in System counter and |
| 163 | * enable system counter. |
| 164 | */ |
| 165 | writel(CONFIG_COUNTER_FREQUENCY, |
| 166 | &iou_scntr_secure->base_frequency_id_register); |
| 167 | |
| 168 | debug("counter val 0x%x\n", |
| 169 | readl(&iou_scntr_secure->base_frequency_id_register)); |
| 170 | |
| 171 | writel(IOU_SCNTRS_CONTROL_EN, |
| 172 | &iou_scntr_secure->counter_control_register); |
| 173 | |
| 174 | debug("scntrs control 0x%x\n", |
| 175 | readl(&iou_scntr_secure->counter_control_register)); |
| 176 | debug("timer 0x%llx\n", get_ticks()); |
| 177 | debug("timer 0x%llx\n", get_ticks()); |
| 178 | |
Michal Simek | 2e53eb2 | 2022-09-19 14:21:02 +0200 | [diff] [blame] | 179 | return 0; |
| 180 | } |
| 181 | |
Ashok Reddy Soma | a7a5a1b | 2023-05-16 08:47:53 -0600 | [diff] [blame] | 182 | static u8 versal_net_get_bootmode(void) |
| 183 | { |
| 184 | u8 bootmode; |
| 185 | u32 reg = 0; |
| 186 | |
| 187 | reg = readl(&crp_base->boot_mode_usr); |
| 188 | |
| 189 | if (reg >> BOOT_MODE_ALT_SHIFT) |
| 190 | reg >>= BOOT_MODE_ALT_SHIFT; |
| 191 | |
| 192 | bootmode = reg & BOOT_MODES_MASK; |
| 193 | |
| 194 | return bootmode; |
| 195 | } |
| 196 | |
Michal Simek | b163476 | 2023-09-05 13:30:07 +0200 | [diff] [blame^] | 197 | static int boot_targets_setup(void) |
Michal Simek | 2e53eb2 | 2022-09-19 14:21:02 +0200 | [diff] [blame] | 198 | { |
Ashok Reddy Soma | a7a5a1b | 2023-05-16 08:47:53 -0600 | [diff] [blame] | 199 | u8 bootmode; |
| 200 | struct udevice *dev; |
| 201 | int bootseq = -1; |
| 202 | int bootseq_len = 0; |
| 203 | int env_targets_len = 0; |
Venkatesh Yadav Abbarapu | 2c81c1d | 2023-09-04 08:50:33 +0530 | [diff] [blame] | 204 | const char *mode = NULL; |
Ashok Reddy Soma | a7a5a1b | 2023-05-16 08:47:53 -0600 | [diff] [blame] | 205 | char *new_targets; |
| 206 | char *env_targets; |
| 207 | |
Ashok Reddy Soma | a7a5a1b | 2023-05-16 08:47:53 -0600 | [diff] [blame] | 208 | bootmode = versal_net_get_bootmode(); |
| 209 | |
| 210 | puts("Bootmode: "); |
| 211 | switch (bootmode) { |
| 212 | case USB_MODE: |
| 213 | puts("USB_MODE\n"); |
| 214 | mode = "usb_dfu0 usb_dfu1"; |
| 215 | break; |
| 216 | case JTAG_MODE: |
| 217 | puts("JTAG_MODE\n"); |
| 218 | mode = "jtag pxe dhcp"; |
| 219 | break; |
| 220 | case QSPI_MODE_24BIT: |
| 221 | puts("QSPI_MODE_24\n"); |
Ashok Reddy Soma | 4c16d32 | 2023-06-14 03:30:58 -0600 | [diff] [blame] | 222 | if (uclass_get_device_by_name(UCLASS_SPI, |
| 223 | "spi@f1030000", &dev)) { |
Venkatesh Yadav Abbarapu | 2c81c1d | 2023-09-04 08:50:33 +0530 | [diff] [blame] | 224 | debug("QSPI driver for QSPI device is not present\n"); |
| 225 | break; |
Ashok Reddy Soma | 4c16d32 | 2023-06-14 03:30:58 -0600 | [diff] [blame] | 226 | } |
| 227 | mode = "xspi"; |
| 228 | bootseq = dev_seq(dev); |
Ashok Reddy Soma | a7a5a1b | 2023-05-16 08:47:53 -0600 | [diff] [blame] | 229 | break; |
| 230 | case QSPI_MODE_32BIT: |
| 231 | puts("QSPI_MODE_32\n"); |
Ashok Reddy Soma | 4c16d32 | 2023-06-14 03:30:58 -0600 | [diff] [blame] | 232 | if (uclass_get_device_by_name(UCLASS_SPI, |
| 233 | "spi@f1030000", &dev)) { |
Venkatesh Yadav Abbarapu | 2c81c1d | 2023-09-04 08:50:33 +0530 | [diff] [blame] | 234 | debug("QSPI driver for QSPI device is not present\n"); |
| 235 | break; |
Ashok Reddy Soma | 4c16d32 | 2023-06-14 03:30:58 -0600 | [diff] [blame] | 236 | } |
| 237 | mode = "xspi"; |
| 238 | bootseq = dev_seq(dev); |
Ashok Reddy Soma | a7a5a1b | 2023-05-16 08:47:53 -0600 | [diff] [blame] | 239 | break; |
| 240 | case OSPI_MODE: |
| 241 | puts("OSPI_MODE\n"); |
Ashok Reddy Soma | 4c16d32 | 2023-06-14 03:30:58 -0600 | [diff] [blame] | 242 | if (uclass_get_device_by_name(UCLASS_SPI, |
| 243 | "spi@f1010000", &dev)) { |
Venkatesh Yadav Abbarapu | 2c81c1d | 2023-09-04 08:50:33 +0530 | [diff] [blame] | 244 | debug("OSPI driver for OSPI device is not present\n"); |
| 245 | break; |
Ashok Reddy Soma | 4c16d32 | 2023-06-14 03:30:58 -0600 | [diff] [blame] | 246 | } |
| 247 | mode = "xspi"; |
| 248 | bootseq = dev_seq(dev); |
Ashok Reddy Soma | a7a5a1b | 2023-05-16 08:47:53 -0600 | [diff] [blame] | 249 | break; |
| 250 | case EMMC_MODE: |
| 251 | puts("EMMC_MODE\n"); |
| 252 | mode = "mmc"; |
| 253 | bootseq = dev_seq(dev); |
| 254 | break; |
| 255 | case SD_MODE: |
| 256 | puts("SD_MODE\n"); |
| 257 | if (uclass_get_device_by_name(UCLASS_MMC, |
| 258 | "mmc@f1040000", &dev)) { |
Venkatesh Yadav Abbarapu | 2c81c1d | 2023-09-04 08:50:33 +0530 | [diff] [blame] | 259 | debug("SD0 driver for SD0 device is not present\n"); |
| 260 | break; |
Ashok Reddy Soma | a7a5a1b | 2023-05-16 08:47:53 -0600 | [diff] [blame] | 261 | } |
| 262 | debug("mmc0 device found at %p, seq %d\n", dev, dev_seq(dev)); |
| 263 | |
| 264 | mode = "mmc"; |
| 265 | bootseq = dev_seq(dev); |
| 266 | break; |
| 267 | case SD1_LSHFT_MODE: |
| 268 | puts("LVL_SHFT_"); |
| 269 | fallthrough; |
| 270 | case SD_MODE1: |
| 271 | puts("SD_MODE1\n"); |
| 272 | if (uclass_get_device_by_name(UCLASS_MMC, |
| 273 | "mmc@f1050000", &dev)) { |
Venkatesh Yadav Abbarapu | 2c81c1d | 2023-09-04 08:50:33 +0530 | [diff] [blame] | 274 | debug("SD1 driver for SD1 device is not present\n"); |
| 275 | break; |
Ashok Reddy Soma | a7a5a1b | 2023-05-16 08:47:53 -0600 | [diff] [blame] | 276 | } |
| 277 | debug("mmc1 device found at %p, seq %d\n", dev, dev_seq(dev)); |
| 278 | |
| 279 | mode = "mmc"; |
| 280 | bootseq = dev_seq(dev); |
| 281 | break; |
| 282 | default: |
Ashok Reddy Soma | a7a5a1b | 2023-05-16 08:47:53 -0600 | [diff] [blame] | 283 | printf("Invalid Boot Mode:0x%x\n", bootmode); |
| 284 | break; |
| 285 | } |
| 286 | |
Venkatesh Yadav Abbarapu | 2c81c1d | 2023-09-04 08:50:33 +0530 | [diff] [blame] | 287 | if (mode) { |
| 288 | if (bootseq >= 0) { |
| 289 | bootseq_len = snprintf(NULL, 0, "%i", bootseq); |
| 290 | debug("Bootseq len: %x\n", bootseq_len); |
| 291 | } |
Ashok Reddy Soma | a7a5a1b | 2023-05-16 08:47:53 -0600 | [diff] [blame] | 292 | |
Venkatesh Yadav Abbarapu | 2c81c1d | 2023-09-04 08:50:33 +0530 | [diff] [blame] | 293 | /* |
| 294 | * One terminating char + one byte for space between mode |
| 295 | * and default boot_targets |
| 296 | */ |
| 297 | env_targets = env_get("boot_targets"); |
| 298 | if (env_targets) |
| 299 | env_targets_len = strlen(env_targets); |
Ashok Reddy Soma | a7a5a1b | 2023-05-16 08:47:53 -0600 | [diff] [blame] | 300 | |
Venkatesh Yadav Abbarapu | 2c81c1d | 2023-09-04 08:50:33 +0530 | [diff] [blame] | 301 | new_targets = calloc(1, strlen(mode) + env_targets_len + 2 + |
| 302 | bootseq_len); |
| 303 | if (!new_targets) |
| 304 | return -ENOMEM; |
Ashok Reddy Soma | a7a5a1b | 2023-05-16 08:47:53 -0600 | [diff] [blame] | 305 | |
Venkatesh Yadav Abbarapu | 2c81c1d | 2023-09-04 08:50:33 +0530 | [diff] [blame] | 306 | if (bootseq >= 0) |
| 307 | sprintf(new_targets, "%s%x %s", mode, bootseq, |
| 308 | env_targets ? env_targets : ""); |
| 309 | else |
| 310 | sprintf(new_targets, "%s %s", mode, |
| 311 | env_targets ? env_targets : ""); |
Ashok Reddy Soma | a7a5a1b | 2023-05-16 08:47:53 -0600 | [diff] [blame] | 312 | |
Venkatesh Yadav Abbarapu | 2c81c1d | 2023-09-04 08:50:33 +0530 | [diff] [blame] | 313 | env_set("boot_targets", new_targets); |
| 314 | } |
Michal Simek | b163476 | 2023-09-05 13:30:07 +0200 | [diff] [blame^] | 315 | |
| 316 | return 0; |
| 317 | } |
| 318 | |
| 319 | int board_late_init(void) |
| 320 | { |
| 321 | int ret; |
| 322 | |
| 323 | if (!(gd->flags & GD_FLG_ENV_DEFAULT)) { |
| 324 | debug("Saved variables - Skipping\n"); |
| 325 | return 0; |
| 326 | } |
| 327 | |
| 328 | if (!IS_ENABLED(CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG)) |
| 329 | return 0; |
| 330 | |
| 331 | if (IS_ENABLED(CONFIG_DISTRO_DEFAULTS)) { |
| 332 | ret = boot_targets_setup(); |
| 333 | if (ret) |
| 334 | return ret; |
| 335 | } |
| 336 | |
Michal Simek | 2e53eb2 | 2022-09-19 14:21:02 +0200 | [diff] [blame] | 337 | return board_late_init_xilinx(); |
| 338 | } |
| 339 | |
| 340 | int dram_init_banksize(void) |
| 341 | { |
| 342 | int ret; |
| 343 | |
| 344 | ret = fdtdec_setup_memory_banksize(); |
| 345 | if (ret) |
| 346 | return ret; |
| 347 | |
| 348 | mem_map_fill(); |
| 349 | |
| 350 | return 0; |
| 351 | } |
| 352 | |
| 353 | int dram_init(void) |
| 354 | { |
| 355 | int ret; |
| 356 | |
Simon Glass | ea0ada3 | 2023-02-05 15:40:57 -0700 | [diff] [blame] | 357 | if (IS_ENABLED(CONFIG_SYS_MEM_RSVD_FOR_MMU)) |
Michal Simek | 2e53eb2 | 2022-09-19 14:21:02 +0200 | [diff] [blame] | 358 | ret = fdtdec_setup_mem_size_base(); |
| 359 | else |
| 360 | ret = fdtdec_setup_mem_size_base_lowest(); |
| 361 | |
| 362 | if (ret) |
| 363 | return -EINVAL; |
| 364 | |
| 365 | return 0; |
| 366 | } |
| 367 | |
| 368 | void reset_cpu(void) |
| 369 | { |
| 370 | } |