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