Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * (C) Copyright 2014 - 2018 Xilinx, Inc. |
| 4 | * Michal Simek <michal.simek@xilinx.com> |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | afb0215 | 2019-12-28 10:45:01 -0700 | [diff] [blame] | 8 | #include <cpu_func.h> |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 9 | #include <env.h> |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 10 | #include <fdtdec.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 11 | #include <init.h> |
Michal Simek | 04e99ce | 2022-03-17 15:25:31 +0100 | [diff] [blame] | 12 | #include <image.h> |
Ashok Reddy Soma | fb6b3cd | 2021-02-23 08:07:46 -0700 | [diff] [blame] | 13 | #include <env_internal.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 14 | #include <log.h> |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 15 | #include <malloc.h> |
Simon Glass | 495a5dc | 2019-11-14 12:57:30 -0700 | [diff] [blame] | 16 | #include <time.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 17 | #include <asm/cache.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 18 | #include <asm/global_data.h> |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 19 | #include <asm/io.h> |
| 20 | #include <asm/arch/hardware.h> |
Michal Simek | 21eb5cc | 2019-04-29 09:39:09 -0700 | [diff] [blame] | 21 | #include <asm/arch/sys_proto.h> |
Siva Durga Prasad Paladugu | 37c2ff8 | 2019-01-31 17:28:14 +0530 | [diff] [blame] | 22 | #include <dm/device.h> |
| 23 | #include <dm/uclass.h> |
Siva Durga Prasad Paladugu | b739897 | 2019-08-05 15:54:59 +0530 | [diff] [blame] | 24 | #include <versalpl.h> |
Michal Simek | 705d44a | 2020-03-31 12:39:37 +0200 | [diff] [blame] | 25 | #include "../common/board.h" |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 26 | |
| 27 | DECLARE_GLOBAL_DATA_PTR; |
| 28 | |
Siva Durga Prasad Paladugu | b739897 | 2019-08-05 15:54:59 +0530 | [diff] [blame] | 29 | #if defined(CONFIG_FPGA_VERSALPL) |
| 30 | static xilinx_desc versalpl = XILINX_VERSAL_DESC; |
| 31 | #endif |
| 32 | |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 33 | int board_init(void) |
| 34 | { |
| 35 | printf("EL Level:\tEL%d\n", current_el()); |
| 36 | |
Siva Durga Prasad Paladugu | b739897 | 2019-08-05 15:54:59 +0530 | [diff] [blame] | 37 | #if defined(CONFIG_FPGA_VERSALPL) |
| 38 | fpga_init(); |
| 39 | fpga_add(fpga_xilinx, &versalpl); |
| 40 | #endif |
| 41 | |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 42 | if (CONFIG_IS_ENABLED(DM_I2C) && CONFIG_IS_ENABLED(I2C_EEPROM)) |
| 43 | xilinx_read_eeprom(); |
| 44 | |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 45 | return 0; |
| 46 | } |
| 47 | |
| 48 | int board_early_init_r(void) |
| 49 | { |
Michal Simek | 19f6c97 | 2019-01-28 11:08:00 +0100 | [diff] [blame] | 50 | u32 val; |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 51 | |
Michal Simek | 19f6c97 | 2019-01-28 11:08:00 +0100 | [diff] [blame] | 52 | if (current_el() != 3) |
| 53 | return 0; |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 54 | |
Michal Simek | f56f7d1 | 2019-01-28 11:12:41 +0100 | [diff] [blame] | 55 | debug("iou_switch ctrl div0 %x\n", |
| 56 | readl(&crlapb_base->iou_switch_ctrl)); |
| 57 | |
Michal Simek | 19f6c97 | 2019-01-28 11:08:00 +0100 | [diff] [blame] | 58 | writel(IOU_SWITCH_CTRL_CLKACT_BIT | |
Michal Simek | f56f7d1 | 2019-01-28 11:12:41 +0100 | [diff] [blame] | 59 | (CONFIG_IOU_SWITCH_DIVISOR0 << IOU_SWITCH_CTRL_DIVISOR0_SHIFT), |
Michal Simek | 19f6c97 | 2019-01-28 11:08:00 +0100 | [diff] [blame] | 60 | &crlapb_base->iou_switch_ctrl); |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 61 | |
Michal Simek | 19f6c97 | 2019-01-28 11:08:00 +0100 | [diff] [blame] | 62 | /* Global timer init - Program time stamp reference clk */ |
| 63 | val = readl(&crlapb_base->timestamp_ref_ctrl); |
| 64 | val |= CRL_APB_TIMESTAMP_REF_CTRL_CLKACT_BIT; |
| 65 | writel(val, &crlapb_base->timestamp_ref_ctrl); |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 66 | |
Michal Simek | 19f6c97 | 2019-01-28 11:08:00 +0100 | [diff] [blame] | 67 | debug("ref ctrl 0x%x\n", |
| 68 | readl(&crlapb_base->timestamp_ref_ctrl)); |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 69 | |
Michal Simek | 19f6c97 | 2019-01-28 11:08:00 +0100 | [diff] [blame] | 70 | /* Clear reset of timestamp reg */ |
| 71 | writel(0, &crlapb_base->rst_timestamp); |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 72 | |
Michal Simek | 19f6c97 | 2019-01-28 11:08:00 +0100 | [diff] [blame] | 73 | /* |
| 74 | * Program freq register in System counter and |
| 75 | * enable system counter. |
| 76 | */ |
Peng Fan | 4b3a182 | 2022-04-13 17:47:17 +0800 | [diff] [blame] | 77 | writel(CONFIG_COUNTER_FREQUENCY, |
Michal Simek | 19f6c97 | 2019-01-28 11:08:00 +0100 | [diff] [blame] | 78 | &iou_scntr_secure->base_frequency_id_register); |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 79 | |
Michal Simek | 19f6c97 | 2019-01-28 11:08:00 +0100 | [diff] [blame] | 80 | debug("counter val 0x%x\n", |
| 81 | readl(&iou_scntr_secure->base_frequency_id_register)); |
| 82 | |
| 83 | writel(IOU_SCNTRS_CONTROL_EN, |
| 84 | &iou_scntr_secure->counter_control_register); |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 85 | |
Michal Simek | 19f6c97 | 2019-01-28 11:08:00 +0100 | [diff] [blame] | 86 | debug("scntrs control 0x%x\n", |
| 87 | readl(&iou_scntr_secure->counter_control_register)); |
| 88 | debug("timer 0x%llx\n", get_ticks()); |
| 89 | debug("timer 0x%llx\n", get_ticks()); |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 90 | |
| 91 | return 0; |
| 92 | } |
| 93 | |
Michal Simek | 9c91e61 | 2020-04-08 11:04:41 +0200 | [diff] [blame] | 94 | static u8 versal_get_bootmode(void) |
Siva Durga Prasad Paladugu | 37c2ff8 | 2019-01-31 17:28:14 +0530 | [diff] [blame] | 95 | { |
Michal Simek | 9c91e61 | 2020-04-08 11:04:41 +0200 | [diff] [blame] | 96 | u8 bootmode; |
Siva Durga Prasad Paladugu | 37c2ff8 | 2019-01-31 17:28:14 +0530 | [diff] [blame] | 97 | u32 reg = 0; |
Michal Simek | 9c91e61 | 2020-04-08 11:04:41 +0200 | [diff] [blame] | 98 | |
| 99 | reg = readl(&crp_base->boot_mode_usr); |
| 100 | |
| 101 | if (reg >> BOOT_MODE_ALT_SHIFT) |
| 102 | reg >>= BOOT_MODE_ALT_SHIFT; |
| 103 | |
| 104 | bootmode = reg & BOOT_MODES_MASK; |
| 105 | |
| 106 | return bootmode; |
| 107 | } |
| 108 | |
| 109 | int board_late_init(void) |
| 110 | { |
Siva Durga Prasad Paladugu | 37c2ff8 | 2019-01-31 17:28:14 +0530 | [diff] [blame] | 111 | u8 bootmode; |
| 112 | struct udevice *dev; |
| 113 | int bootseq = -1; |
| 114 | int bootseq_len = 0; |
| 115 | int env_targets_len = 0; |
| 116 | const char *mode; |
| 117 | char *new_targets; |
| 118 | char *env_targets; |
| 119 | |
| 120 | if (!(gd->flags & GD_FLG_ENV_DEFAULT)) { |
| 121 | debug("Saved variables - Skipping\n"); |
| 122 | return 0; |
| 123 | } |
| 124 | |
Michal Simek | bab07b6 | 2020-07-28 12:45:47 +0200 | [diff] [blame] | 125 | if (!CONFIG_IS_ENABLED(ENV_VARS_UBOOT_RUNTIME_CONFIG)) |
| 126 | return 0; |
| 127 | |
Michal Simek | 9c91e61 | 2020-04-08 11:04:41 +0200 | [diff] [blame] | 128 | bootmode = versal_get_bootmode(); |
Siva Durga Prasad Paladugu | 37c2ff8 | 2019-01-31 17:28:14 +0530 | [diff] [blame] | 129 | |
| 130 | puts("Bootmode: "); |
| 131 | switch (bootmode) { |
T Karthik Reddy | facca9a | 2019-07-11 16:07:57 +0530 | [diff] [blame] | 132 | case USB_MODE: |
| 133 | puts("USB_MODE\n"); |
T Karthik Reddy | 1104faf | 2021-03-30 23:24:57 -0600 | [diff] [blame] | 134 | mode = "usb_dfu0 usb_dfu1"; |
T Karthik Reddy | facca9a | 2019-07-11 16:07:57 +0530 | [diff] [blame] | 135 | break; |
Siva Durga Prasad Paladugu | 37c2ff8 | 2019-01-31 17:28:14 +0530 | [diff] [blame] | 136 | case JTAG_MODE: |
| 137 | puts("JTAG_MODE\n"); |
Siva Durga Prasad Paladugu | 00784e0 | 2019-06-25 17:13:14 +0530 | [diff] [blame] | 138 | mode = "jtag pxe dhcp"; |
Siva Durga Prasad Paladugu | 37c2ff8 | 2019-01-31 17:28:14 +0530 | [diff] [blame] | 139 | break; |
| 140 | case QSPI_MODE_24BIT: |
| 141 | puts("QSPI_MODE_24\n"); |
| 142 | mode = "xspi0"; |
| 143 | break; |
| 144 | case QSPI_MODE_32BIT: |
| 145 | puts("QSPI_MODE_32\n"); |
| 146 | mode = "xspi0"; |
| 147 | break; |
| 148 | case OSPI_MODE: |
| 149 | puts("OSPI_MODE\n"); |
| 150 | mode = "xspi0"; |
| 151 | break; |
| 152 | case EMMC_MODE: |
| 153 | puts("EMMC_MODE\n"); |
T Karthik Reddy | bc2b964 | 2019-12-16 04:44:26 -0700 | [diff] [blame] | 154 | if (uclass_get_device_by_name(UCLASS_MMC, |
T Karthik Reddy | a12445f | 2021-11-18 12:57:20 +0100 | [diff] [blame] | 155 | "mmc@f1050000", &dev) && |
| 156 | uclass_get_device_by_name(UCLASS_MMC, |
T Karthik Reddy | bc2b964 | 2019-12-16 04:44:26 -0700 | [diff] [blame] | 157 | "sdhci@f1050000", &dev)) { |
| 158 | puts("Boot from EMMC but without SD1 enabled!\n"); |
| 159 | return -1; |
| 160 | } |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 161 | debug("mmc1 device found at %p, seq %d\n", dev, dev_seq(dev)); |
T Karthik Reddy | bc2b964 | 2019-12-16 04:44:26 -0700 | [diff] [blame] | 162 | mode = "mmc"; |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 163 | bootseq = dev_seq(dev); |
Siva Durga Prasad Paladugu | 37c2ff8 | 2019-01-31 17:28:14 +0530 | [diff] [blame] | 164 | break; |
| 165 | case SD_MODE: |
| 166 | puts("SD_MODE\n"); |
| 167 | if (uclass_get_device_by_name(UCLASS_MMC, |
T Karthik Reddy | a12445f | 2021-11-18 12:57:20 +0100 | [diff] [blame] | 168 | "mmc@f1040000", &dev) && |
| 169 | uclass_get_device_by_name(UCLASS_MMC, |
Siva Durga Prasad Paladugu | 37c2ff8 | 2019-01-31 17:28:14 +0530 | [diff] [blame] | 170 | "sdhci@f1040000", &dev)) { |
| 171 | puts("Boot from SD0 but without SD0 enabled!\n"); |
| 172 | return -1; |
| 173 | } |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 174 | debug("mmc0 device found at %p, seq %d\n", dev, dev_seq(dev)); |
Siva Durga Prasad Paladugu | 37c2ff8 | 2019-01-31 17:28:14 +0530 | [diff] [blame] | 175 | |
| 176 | mode = "mmc"; |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 177 | bootseq = dev_seq(dev); |
Siva Durga Prasad Paladugu | 37c2ff8 | 2019-01-31 17:28:14 +0530 | [diff] [blame] | 178 | break; |
| 179 | case SD1_LSHFT_MODE: |
| 180 | puts("LVL_SHFT_"); |
| 181 | /* fall through */ |
| 182 | case SD_MODE1: |
| 183 | puts("SD_MODE1\n"); |
| 184 | if (uclass_get_device_by_name(UCLASS_MMC, |
T Karthik Reddy | a12445f | 2021-11-18 12:57:20 +0100 | [diff] [blame] | 185 | "mmc@f1050000", &dev) && |
| 186 | uclass_get_device_by_name(UCLASS_MMC, |
Siva Durga Prasad Paladugu | 37c2ff8 | 2019-01-31 17:28:14 +0530 | [diff] [blame] | 187 | "sdhci@f1050000", &dev)) { |
| 188 | puts("Boot from SD1 but without SD1 enabled!\n"); |
| 189 | return -1; |
| 190 | } |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 191 | debug("mmc1 device found at %p, seq %d\n", dev, dev_seq(dev)); |
Siva Durga Prasad Paladugu | 37c2ff8 | 2019-01-31 17:28:14 +0530 | [diff] [blame] | 192 | |
| 193 | mode = "mmc"; |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 194 | bootseq = dev_seq(dev); |
Siva Durga Prasad Paladugu | 37c2ff8 | 2019-01-31 17:28:14 +0530 | [diff] [blame] | 195 | break; |
| 196 | default: |
| 197 | mode = ""; |
| 198 | printf("Invalid Boot Mode:0x%x\n", bootmode); |
| 199 | break; |
| 200 | } |
| 201 | |
| 202 | if (bootseq >= 0) { |
| 203 | bootseq_len = snprintf(NULL, 0, "%i", bootseq); |
| 204 | debug("Bootseq len: %x\n", bootseq_len); |
| 205 | } |
| 206 | |
| 207 | /* |
| 208 | * One terminating char + one byte for space between mode |
| 209 | * and default boot_targets |
| 210 | */ |
| 211 | env_targets = env_get("boot_targets"); |
| 212 | if (env_targets) |
| 213 | env_targets_len = strlen(env_targets); |
| 214 | |
| 215 | new_targets = calloc(1, strlen(mode) + env_targets_len + 2 + |
| 216 | bootseq_len); |
| 217 | if (!new_targets) |
| 218 | return -ENOMEM; |
| 219 | |
| 220 | if (bootseq >= 0) |
| 221 | sprintf(new_targets, "%s%x %s", mode, bootseq, |
| 222 | env_targets ? env_targets : ""); |
| 223 | else |
| 224 | sprintf(new_targets, "%s %s", mode, |
| 225 | env_targets ? env_targets : ""); |
| 226 | |
| 227 | env_set("boot_targets", new_targets); |
| 228 | |
Michal Simek | 705d44a | 2020-03-31 12:39:37 +0200 | [diff] [blame] | 229 | return board_late_init_xilinx(); |
Siva Durga Prasad Paladugu | 37c2ff8 | 2019-01-31 17:28:14 +0530 | [diff] [blame] | 230 | } |
| 231 | |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 232 | int dram_init_banksize(void) |
| 233 | { |
Michal Simek | 21eb5cc | 2019-04-29 09:39:09 -0700 | [diff] [blame] | 234 | int ret; |
| 235 | |
| 236 | ret = fdtdec_setup_memory_banksize(); |
| 237 | if (ret) |
| 238 | return ret; |
| 239 | |
| 240 | mem_map_fill(); |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 241 | |
| 242 | return 0; |
| 243 | } |
| 244 | |
| 245 | int dram_init(void) |
| 246 | { |
Michal Simek | 9134d4c | 2020-07-10 12:42:09 +0200 | [diff] [blame] | 247 | if (fdtdec_setup_mem_size_base_lowest() != 0) |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 248 | return -EINVAL; |
| 249 | |
| 250 | return 0; |
| 251 | } |
| 252 | |
Michal Simek | 04e99ce | 2022-03-17 15:25:31 +0100 | [diff] [blame] | 253 | ulong board_get_usable_ram_top(ulong total_size) |
| 254 | { |
| 255 | phys_size_t size; |
| 256 | phys_addr_t reg; |
| 257 | struct lmb lmb; |
| 258 | |
Michal Simek | 1b8da4a | 2022-04-29 11:52:27 +0200 | [diff] [blame] | 259 | if (!total_size) |
| 260 | return gd->ram_top; |
| 261 | |
Michal Simek | 04e99ce | 2022-03-17 15:25:31 +0100 | [diff] [blame] | 262 | /* found enough not-reserved memory to relocated U-Boot */ |
| 263 | lmb_init(&lmb); |
| 264 | lmb_add(&lmb, gd->ram_base, gd->ram_size); |
| 265 | boot_fdt_add_mem_rsv_regions(&lmb, (void *)gd->fdt_blob); |
| 266 | size = ALIGN(CONFIG_SYS_MALLOC_LEN + total_size, MMU_SECTION_SIZE); |
| 267 | reg = lmb_alloc(&lmb, size, MMU_SECTION_SIZE); |
| 268 | |
| 269 | if (!reg) |
| 270 | reg = gd->ram_top - size; |
| 271 | |
| 272 | return reg + size; |
| 273 | } |
| 274 | |
Harald Seiler | 6f14d5f | 2020-12-15 16:47:52 +0100 | [diff] [blame] | 275 | void reset_cpu(void) |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 276 | { |
| 277 | } |
Ashok Reddy Soma | fb6b3cd | 2021-02-23 08:07:46 -0700 | [diff] [blame] | 278 | |
| 279 | enum env_location env_get_location(enum env_operation op, int prio) |
| 280 | { |
| 281 | u32 bootmode = versal_get_bootmode(); |
| 282 | |
| 283 | if (prio) |
| 284 | return ENVL_UNKNOWN; |
| 285 | |
| 286 | switch (bootmode) { |
| 287 | case EMMC_MODE: |
| 288 | case SD_MODE: |
| 289 | case SD1_LSHFT_MODE: |
| 290 | case SD_MODE1: |
| 291 | if (IS_ENABLED(CONFIG_ENV_IS_IN_FAT)) |
| 292 | return ENVL_FAT; |
| 293 | if (IS_ENABLED(CONFIG_ENV_IS_IN_EXT4)) |
| 294 | return ENVL_EXT4; |
T Karthik Reddy | 6f8b205 | 2021-11-24 12:16:55 +0100 | [diff] [blame] | 295 | return ENVL_NOWHERE; |
Ashok Reddy Soma | fb6b3cd | 2021-02-23 08:07:46 -0700 | [diff] [blame] | 296 | case OSPI_MODE: |
| 297 | case QSPI_MODE_24BIT: |
| 298 | case QSPI_MODE_32BIT: |
| 299 | if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH)) |
| 300 | return ENVL_SPI_FLASH; |
T Karthik Reddy | 6f8b205 | 2021-11-24 12:16:55 +0100 | [diff] [blame] | 301 | return ENVL_NOWHERE; |
Ashok Reddy Soma | fb6b3cd | 2021-02-23 08:07:46 -0700 | [diff] [blame] | 302 | case JTAG_MODE: |
| 303 | default: |
| 304 | return ENVL_NOWHERE; |
| 305 | } |
| 306 | } |