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