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