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