Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2014 - 2015 Xilinx, Inc. |
| 3 | * Michal Simek <michal.simek@xilinx.com> |
| 4 | * |
| 5 | * SPDX-License-Identifier: GPL-2.0+ |
| 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Michal Simek | d54b1af | 2015-09-30 17:26:55 +0200 | [diff] [blame] | 9 | #include <sata.h> |
Michal Simek | b216cc1 | 2015-07-23 13:27:40 +0200 | [diff] [blame] | 10 | #include <ahci.h> |
| 11 | #include <scsi.h> |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 12 | #include <malloc.h> |
Michal Simek | c23d3f8 | 2015-11-05 08:34:35 +0100 | [diff] [blame] | 13 | #include <asm/arch/clk.h> |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 14 | #include <asm/arch/hardware.h> |
| 15 | #include <asm/arch/sys_proto.h> |
Michal Simek | f2f0864 | 2018-01-10 09:36:09 +0100 | [diff] [blame] | 16 | #include <asm/arch/psu_init_gpl.h> |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 17 | #include <asm/io.h> |
Siva Durga Prasad Paladugu | ba1f68e | 2015-08-04 13:03:26 +0530 | [diff] [blame] | 18 | #include <usb.h> |
| 19 | #include <dwc3-uboot.h> |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 20 | #include <zynqmppl.h> |
Michal Simek | eec32f6 | 2016-04-22 11:48:49 +0200 | [diff] [blame] | 21 | #include <i2c.h> |
Michal Simek | 76d0a77 | 2016-09-01 11:16:40 +0200 | [diff] [blame] | 22 | #include <g_dnl.h> |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 23 | |
| 24 | DECLARE_GLOBAL_DATA_PTR; |
| 25 | |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 26 | #if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \ |
| 27 | !defined(CONFIG_SPL_BUILD) |
| 28 | static xilinx_desc zynqmppl = XILINX_ZYNQMP_DESC; |
| 29 | |
| 30 | static const struct { |
Michal Simek | 6908b86 | 2017-11-06 12:55:59 +0100 | [diff] [blame] | 31 | u32 id; |
Michal Simek | 50d8cef | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 32 | u32 ver; |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 33 | char *name; |
Siva Durga Prasad Paladugu | ba2622d | 2018-03-02 16:20:10 +0530 | [diff] [blame] | 34 | bool evexists; |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 35 | } zynqmp_devices[] = { |
| 36 | { |
| 37 | .id = 0x10, |
| 38 | .name = "3eg", |
| 39 | }, |
| 40 | { |
Michal Simek | 50d8cef | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 41 | .id = 0x10, |
| 42 | .ver = 0x2c, |
| 43 | .name = "3cg", |
| 44 | }, |
| 45 | { |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 46 | .id = 0x11, |
| 47 | .name = "2eg", |
| 48 | }, |
| 49 | { |
Michal Simek | 50d8cef | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 50 | .id = 0x11, |
| 51 | .ver = 0x2c, |
| 52 | .name = "2cg", |
| 53 | }, |
| 54 | { |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 55 | .id = 0x20, |
| 56 | .name = "5ev", |
Siva Durga Prasad Paladugu | ba2622d | 2018-03-02 16:20:10 +0530 | [diff] [blame] | 57 | .evexists = 1, |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 58 | }, |
| 59 | { |
Michal Simek | 50d8cef | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 60 | .id = 0x20, |
| 61 | .ver = 0x100, |
| 62 | .name = "5eg", |
Siva Durga Prasad Paladugu | ba2622d | 2018-03-02 16:20:10 +0530 | [diff] [blame] | 63 | .evexists = 1, |
Michal Simek | 50d8cef | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 64 | }, |
| 65 | { |
| 66 | .id = 0x20, |
| 67 | .ver = 0x12c, |
| 68 | .name = "5cg", |
| 69 | }, |
| 70 | { |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 71 | .id = 0x21, |
| 72 | .name = "4ev", |
Siva Durga Prasad Paladugu | ba2622d | 2018-03-02 16:20:10 +0530 | [diff] [blame] | 73 | .evexists = 1, |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 74 | }, |
| 75 | { |
Michal Simek | 50d8cef | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 76 | .id = 0x21, |
| 77 | .ver = 0x100, |
| 78 | .name = "4eg", |
Siva Durga Prasad Paladugu | ba2622d | 2018-03-02 16:20:10 +0530 | [diff] [blame] | 79 | .evexists = 1, |
Michal Simek | 50d8cef | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 80 | }, |
| 81 | { |
| 82 | .id = 0x21, |
| 83 | .ver = 0x12c, |
| 84 | .name = "4cg", |
| 85 | }, |
| 86 | { |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 87 | .id = 0x30, |
| 88 | .name = "7ev", |
Siva Durga Prasad Paladugu | ba2622d | 2018-03-02 16:20:10 +0530 | [diff] [blame] | 89 | .evexists = 1, |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 90 | }, |
| 91 | { |
Michal Simek | 50d8cef | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 92 | .id = 0x30, |
| 93 | .ver = 0x100, |
| 94 | .name = "7eg", |
Siva Durga Prasad Paladugu | ba2622d | 2018-03-02 16:20:10 +0530 | [diff] [blame] | 95 | .evexists = 1, |
Michal Simek | 50d8cef | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 96 | }, |
| 97 | { |
| 98 | .id = 0x30, |
| 99 | .ver = 0x12c, |
| 100 | .name = "7cg", |
| 101 | }, |
| 102 | { |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 103 | .id = 0x38, |
| 104 | .name = "9eg", |
| 105 | }, |
| 106 | { |
Michal Simek | 50d8cef | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 107 | .id = 0x38, |
| 108 | .ver = 0x2c, |
| 109 | .name = "9cg", |
| 110 | }, |
| 111 | { |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 112 | .id = 0x39, |
| 113 | .name = "6eg", |
| 114 | }, |
| 115 | { |
Michal Simek | 50d8cef | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 116 | .id = 0x39, |
| 117 | .ver = 0x2c, |
| 118 | .name = "6cg", |
| 119 | }, |
| 120 | { |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 121 | .id = 0x40, |
| 122 | .name = "11eg", |
| 123 | }, |
Michal Simek | 50d8cef | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 124 | { /* For testing purpose only */ |
| 125 | .id = 0x50, |
| 126 | .ver = 0x2c, |
| 127 | .name = "15cg", |
| 128 | }, |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 129 | { |
| 130 | .id = 0x50, |
| 131 | .name = "15eg", |
| 132 | }, |
| 133 | { |
| 134 | .id = 0x58, |
| 135 | .name = "19eg", |
| 136 | }, |
| 137 | { |
| 138 | .id = 0x59, |
| 139 | .name = "17eg", |
| 140 | }, |
Michal Simek | b510e53 | 2017-06-02 08:08:59 +0200 | [diff] [blame] | 141 | { |
| 142 | .id = 0x61, |
| 143 | .name = "21dr", |
| 144 | }, |
| 145 | { |
| 146 | .id = 0x63, |
| 147 | .name = "23dr", |
| 148 | }, |
| 149 | { |
| 150 | .id = 0x65, |
| 151 | .name = "25dr", |
| 152 | }, |
| 153 | { |
| 154 | .id = 0x64, |
| 155 | .name = "27dr", |
| 156 | }, |
| 157 | { |
| 158 | .id = 0x60, |
| 159 | .name = "28dr", |
| 160 | }, |
| 161 | { |
| 162 | .id = 0x62, |
| 163 | .name = "29dr", |
| 164 | }, |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 165 | }; |
Siva Durga Prasad Paladugu | 8d52653 | 2017-07-25 11:51:37 +0530 | [diff] [blame] | 166 | #endif |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 167 | |
Siva Durga Prasad Paladugu | cd35d52 | 2017-07-25 11:51:38 +0530 | [diff] [blame] | 168 | int chip_id(unsigned char id) |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 169 | { |
| 170 | struct pt_regs regs; |
Siva Durga Prasad Paladugu | 9f0a8e9 | 2017-07-25 11:51:36 +0530 | [diff] [blame] | 171 | int val = -EINVAL; |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 172 | |
Siva Durga Prasad Paladugu | 8d52653 | 2017-07-25 11:51:37 +0530 | [diff] [blame] | 173 | if (current_el() != 3) { |
| 174 | regs.regs[0] = ZYNQMP_SIP_SVC_CSU_DMA_CHIPID; |
| 175 | regs.regs[1] = 0; |
| 176 | regs.regs[2] = 0; |
| 177 | regs.regs[3] = 0; |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 178 | |
Siva Durga Prasad Paladugu | 8d52653 | 2017-07-25 11:51:37 +0530 | [diff] [blame] | 179 | smc_call(®s); |
| 180 | |
| 181 | /* |
| 182 | * SMC returns: |
| 183 | * regs[0][31:0] = status of the operation |
| 184 | * regs[0][63:32] = CSU.IDCODE register |
| 185 | * regs[1][31:0] = CSU.version register |
Michal Simek | 50d8cef | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 186 | * regs[1][63:32] = CSU.IDCODE2 register |
Siva Durga Prasad Paladugu | 8d52653 | 2017-07-25 11:51:37 +0530 | [diff] [blame] | 187 | */ |
| 188 | switch (id) { |
| 189 | case IDCODE: |
| 190 | regs.regs[0] = upper_32_bits(regs.regs[0]); |
| 191 | regs.regs[0] &= ZYNQMP_CSU_IDCODE_DEVICE_CODE_MASK | |
| 192 | ZYNQMP_CSU_IDCODE_SVD_MASK; |
| 193 | regs.regs[0] >>= ZYNQMP_CSU_IDCODE_SVD_SHIFT; |
| 194 | val = regs.regs[0]; |
| 195 | break; |
| 196 | case VERSION: |
| 197 | regs.regs[1] = lower_32_bits(regs.regs[1]); |
| 198 | regs.regs[1] &= ZYNQMP_CSU_SILICON_VER_MASK; |
| 199 | val = regs.regs[1]; |
| 200 | break; |
Michal Simek | 50d8cef | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 201 | case IDCODE2: |
| 202 | regs.regs[1] = lower_32_bits(regs.regs[1]); |
| 203 | regs.regs[1] >>= ZYNQMP_CSU_VERSION_EMPTY_SHIFT; |
| 204 | val = regs.regs[1]; |
| 205 | break; |
Siva Durga Prasad Paladugu | 8d52653 | 2017-07-25 11:51:37 +0530 | [diff] [blame] | 206 | default: |
| 207 | printf("%s, Invalid Req:0x%x\n", __func__, id); |
| 208 | } |
| 209 | } else { |
| 210 | switch (id) { |
| 211 | case IDCODE: |
| 212 | val = readl(ZYNQMP_CSU_IDCODE_ADDR); |
| 213 | val &= ZYNQMP_CSU_IDCODE_DEVICE_CODE_MASK | |
| 214 | ZYNQMP_CSU_IDCODE_SVD_MASK; |
| 215 | val >>= ZYNQMP_CSU_IDCODE_SVD_SHIFT; |
| 216 | break; |
| 217 | case VERSION: |
| 218 | val = readl(ZYNQMP_CSU_VER_ADDR); |
| 219 | val &= ZYNQMP_CSU_SILICON_VER_MASK; |
| 220 | break; |
| 221 | default: |
| 222 | printf("%s, Invalid Req:0x%x\n", __func__, id); |
| 223 | } |
Siva Durga Prasad Paladugu | 9f0a8e9 | 2017-07-25 11:51:36 +0530 | [diff] [blame] | 224 | } |
Soren Brinkmann | d7696a5 | 2016-09-29 11:44:41 -0700 | [diff] [blame] | 225 | |
Siva Durga Prasad Paladugu | 9f0a8e9 | 2017-07-25 11:51:36 +0530 | [diff] [blame] | 226 | return val; |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 227 | } |
| 228 | |
Siva Durga Prasad Paladugu | ba2622d | 2018-03-02 16:20:10 +0530 | [diff] [blame] | 229 | #define ZYNQMP_VERSION_SIZE 9 |
| 230 | #define ZYNQMP_PL_STATUS_BIT 9 |
| 231 | #define ZYNQMP_PL_STATUS_MASK BIT(ZYNQMP_PL_STATUS_BIT) |
| 232 | #define ZYNQMP_CSU_VERSION_MASK ~(ZYNQMP_PL_STATUS_MASK) |
| 233 | |
Siva Durga Prasad Paladugu | 8d52653 | 2017-07-25 11:51:37 +0530 | [diff] [blame] | 234 | #if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \ |
| 235 | !defined(CONFIG_SPL_BUILD) |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 236 | static char *zynqmp_get_silicon_idcode_name(void) |
| 237 | { |
Michal Simek | 50d8cef | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 238 | u32 i, id, ver; |
Siva Durga Prasad Paladugu | ba2622d | 2018-03-02 16:20:10 +0530 | [diff] [blame] | 239 | char *buf; |
| 240 | static char name[ZYNQMP_VERSION_SIZE]; |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 241 | |
Siva Durga Prasad Paladugu | 9f0a8e9 | 2017-07-25 11:51:36 +0530 | [diff] [blame] | 242 | id = chip_id(IDCODE); |
Michal Simek | 50d8cef | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 243 | ver = chip_id(IDCODE2); |
| 244 | |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 245 | for (i = 0; i < ARRAY_SIZE(zynqmp_devices); i++) { |
Siva Durga Prasad Paladugu | ba2622d | 2018-03-02 16:20:10 +0530 | [diff] [blame] | 246 | if ((zynqmp_devices[i].id == id) && |
| 247 | (zynqmp_devices[i].ver == (ver & |
| 248 | ZYNQMP_CSU_VERSION_MASK))) { |
| 249 | strncat(name, "zu", 2); |
| 250 | strncat(name, zynqmp_devices[i].name, |
| 251 | ZYNQMP_VERSION_SIZE - 3); |
| 252 | break; |
| 253 | } |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 254 | } |
Siva Durga Prasad Paladugu | ba2622d | 2018-03-02 16:20:10 +0530 | [diff] [blame] | 255 | |
| 256 | if (i >= ARRAY_SIZE(zynqmp_devices)) |
| 257 | return "unknown"; |
| 258 | |
| 259 | if (!zynqmp_devices[i].evexists) |
| 260 | return name; |
| 261 | |
| 262 | if (ver & ZYNQMP_PL_STATUS_MASK) |
| 263 | return name; |
| 264 | |
| 265 | if (strstr(name, "eg") || strstr(name, "ev")) { |
| 266 | buf = strstr(name, "e"); |
| 267 | *buf = '\0'; |
| 268 | } |
| 269 | |
| 270 | return name; |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 271 | } |
| 272 | #endif |
| 273 | |
Michal Simek | 8b35330 | 2017-02-07 14:32:26 +0100 | [diff] [blame] | 274 | int board_early_init_f(void) |
| 275 | { |
Michal Simek | c8785f2 | 2018-01-10 11:48:48 +0100 | [diff] [blame] | 276 | int ret = 0; |
Michal Simek | 8b35330 | 2017-02-07 14:32:26 +0100 | [diff] [blame] | 277 | #if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_CLK_ZYNQMP) |
| 278 | zynqmp_pmufw_version(); |
| 279 | #endif |
Michal Simek | e0f3610 | 2017-07-12 13:08:41 +0200 | [diff] [blame] | 280 | |
Michal Simek | 1a1ab5a | 2018-01-15 12:52:59 +0100 | [diff] [blame] | 281 | #if defined(CONFIG_ZYNQMP_PSU_INIT_ENABLED) |
Michal Simek | c8785f2 | 2018-01-10 11:48:48 +0100 | [diff] [blame] | 282 | ret = psu_init(); |
Michal Simek | e0f3610 | 2017-07-12 13:08:41 +0200 | [diff] [blame] | 283 | #endif |
| 284 | |
Michal Simek | c8785f2 | 2018-01-10 11:48:48 +0100 | [diff] [blame] | 285 | return ret; |
Michal Simek | 8b35330 | 2017-02-07 14:32:26 +0100 | [diff] [blame] | 286 | } |
| 287 | |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 288 | int board_init(void) |
| 289 | { |
Michal Simek | fb7242d | 2015-06-22 14:31:06 +0200 | [diff] [blame] | 290 | printf("EL Level:\tEL%d\n", current_el()); |
| 291 | |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 292 | #if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \ |
| 293 | !defined(CONFIG_SPL_BUILD) || (defined(CONFIG_SPL_FPGA_SUPPORT) && \ |
| 294 | defined(CONFIG_SPL_BUILD)) |
| 295 | if (current_el() != 3) { |
Siva Durga Prasad Paladugu | ba2622d | 2018-03-02 16:20:10 +0530 | [diff] [blame] | 296 | zynqmppl.name = zynqmp_get_silicon_idcode_name(); |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 297 | printf("Chip ID:\t%s\n", zynqmppl.name); |
| 298 | fpga_init(); |
| 299 | fpga_add(fpga_xilinx, &zynqmppl); |
| 300 | } |
| 301 | #endif |
| 302 | |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 303 | return 0; |
| 304 | } |
| 305 | |
| 306 | int board_early_init_r(void) |
| 307 | { |
| 308 | u32 val; |
| 309 | |
Siva Durga Prasad Paladugu | 64d9000 | 2017-12-07 15:05:30 +0530 | [diff] [blame] | 310 | if (current_el() != 3) |
| 311 | return 0; |
| 312 | |
Michal Simek | 245d528 | 2017-07-12 10:32:18 +0200 | [diff] [blame] | 313 | val = readl(&crlapb_base->timestamp_ref_ctrl); |
| 314 | val &= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT; |
| 315 | |
Siva Durga Prasad Paladugu | 64d9000 | 2017-12-07 15:05:30 +0530 | [diff] [blame] | 316 | if (!val) { |
Michal Simek | c23d3f8 | 2015-11-05 08:34:35 +0100 | [diff] [blame] | 317 | val = readl(&crlapb_base->timestamp_ref_ctrl); |
| 318 | val |= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT; |
| 319 | writel(val, &crlapb_base->timestamp_ref_ctrl); |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 320 | |
Michal Simek | c23d3f8 | 2015-11-05 08:34:35 +0100 | [diff] [blame] | 321 | /* Program freq register in System counter */ |
| 322 | writel(zynqmp_get_system_timer_freq(), |
| 323 | &iou_scntr_secure->base_frequency_id_register); |
| 324 | /* And enable system counter */ |
| 325 | writel(ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_EN, |
| 326 | &iou_scntr_secure->counter_control_register); |
| 327 | } |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 328 | return 0; |
| 329 | } |
| 330 | |
Michal Simek | eec32f6 | 2016-04-22 11:48:49 +0200 | [diff] [blame] | 331 | int zynq_board_read_rom_ethaddr(unsigned char *ethaddr) |
| 332 | { |
| 333 | #if defined(CONFIG_ZYNQ_GEM_EEPROM_ADDR) && \ |
| 334 | defined(CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET) && \ |
| 335 | defined(CONFIG_ZYNQ_EEPROM_BUS) |
| 336 | i2c_set_bus_num(CONFIG_ZYNQ_EEPROM_BUS); |
| 337 | |
| 338 | if (eeprom_read(CONFIG_ZYNQ_GEM_EEPROM_ADDR, |
| 339 | CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET, |
| 340 | ethaddr, 6)) |
| 341 | printf("I2C EEPROM MAC address read failed\n"); |
| 342 | #endif |
| 343 | |
| 344 | return 0; |
| 345 | } |
| 346 | |
Nitin Jain | b2eb59b | 2018-02-16 12:56:17 +0530 | [diff] [blame] | 347 | unsigned long do_go_exec(ulong (*entry)(int, char * const []), int argc, |
| 348 | char * const argv[]) |
| 349 | { |
| 350 | int ret = 0; |
| 351 | |
| 352 | if (current_el() > 1) { |
| 353 | smp_kick_all_cpus(); |
| 354 | dcache_disable(); |
| 355 | armv8_switch_to_el1(0x0, 0, 0, 0, (unsigned long)entry, |
| 356 | ES_TO_AARCH64); |
| 357 | } else { |
| 358 | printf("FAIL: current EL is not above EL1\n"); |
| 359 | ret = EINVAL; |
| 360 | } |
| 361 | return ret; |
| 362 | } |
| 363 | |
Michal Simek | 8faa66a | 2016-02-08 09:34:53 +0100 | [diff] [blame] | 364 | #if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE) |
Simon Glass | 2f949c3 | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 365 | int dram_init_banksize(void) |
Michal Simek | 8faa66a | 2016-02-08 09:34:53 +0100 | [diff] [blame] | 366 | { |
Michal Simek | d5b7de6 | 2017-11-03 15:25:51 +0100 | [diff] [blame] | 367 | return fdtdec_setup_memory_banksize(); |
Tom Rini | edcfdbd | 2016-12-09 07:56:54 -0500 | [diff] [blame] | 368 | } |
Michal Simek | 8faa66a | 2016-02-08 09:34:53 +0100 | [diff] [blame] | 369 | |
Tom Rini | edcfdbd | 2016-12-09 07:56:54 -0500 | [diff] [blame] | 370 | int dram_init(void) |
| 371 | { |
Nathan Rossi | ac04bfa | 2016-12-19 00:03:34 +1000 | [diff] [blame] | 372 | if (fdtdec_setup_memory_size() != 0) |
| 373 | return -EINVAL; |
Tom Rini | edcfdbd | 2016-12-09 07:56:54 -0500 | [diff] [blame] | 374 | |
| 375 | return 0; |
Michal Simek | 8faa66a | 2016-02-08 09:34:53 +0100 | [diff] [blame] | 376 | } |
| 377 | #else |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 378 | int dram_init(void) |
| 379 | { |
| 380 | gd->ram_size = CONFIG_SYS_SDRAM_SIZE; |
| 381 | |
| 382 | return 0; |
| 383 | } |
Michal Simek | 8faa66a | 2016-02-08 09:34:53 +0100 | [diff] [blame] | 384 | #endif |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 385 | |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 386 | void reset_cpu(ulong addr) |
| 387 | { |
| 388 | } |
| 389 | |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 390 | int board_late_init(void) |
| 391 | { |
| 392 | u32 reg = 0; |
| 393 | u8 bootmode; |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 394 | const char *mode; |
| 395 | char *new_targets; |
Siva Durga Prasad Paladugu | 245c556 | 2017-12-20 16:35:06 +0530 | [diff] [blame] | 396 | char *env_targets; |
Siva Durga Prasad Paladugu | e6fd3bb | 2017-02-21 17:58:28 +0530 | [diff] [blame] | 397 | int ret; |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 398 | |
| 399 | if (!(gd->flags & GD_FLG_ENV_DEFAULT)) { |
| 400 | debug("Saved variables - Skipping\n"); |
| 401 | return 0; |
| 402 | } |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 403 | |
Siva Durga Prasad Paladugu | e6fd3bb | 2017-02-21 17:58:28 +0530 | [diff] [blame] | 404 | ret = zynqmp_mmio_read((ulong)&crlapb_base->boot_mode, ®); |
| 405 | if (ret) |
| 406 | return -EINVAL; |
| 407 | |
Michal Simek | 833e0c4 | 2016-10-25 11:43:02 +0200 | [diff] [blame] | 408 | if (reg >> BOOT_MODE_ALT_SHIFT) |
| 409 | reg >>= BOOT_MODE_ALT_SHIFT; |
| 410 | |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 411 | bootmode = reg & BOOT_MODES_MASK; |
| 412 | |
Michal Simek | c5d9523 | 2015-09-20 17:20:42 +0200 | [diff] [blame] | 413 | puts("Bootmode: "); |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 414 | switch (bootmode) { |
Michal Simek | 12398ea | 2016-08-19 14:14:52 +0200 | [diff] [blame] | 415 | case USB_MODE: |
| 416 | puts("USB_MODE\n"); |
| 417 | mode = "usb"; |
Michal Simek | 4338035 | 2017-12-01 15:18:24 +0100 | [diff] [blame] | 418 | env_set("modeboot", "usb_dfu_spl"); |
Michal Simek | 12398ea | 2016-08-19 14:14:52 +0200 | [diff] [blame] | 419 | break; |
Siva Durga Prasad Paladugu | 30f0fc7 | 2015-03-13 11:10:26 +0530 | [diff] [blame] | 420 | case JTAG_MODE: |
Michal Simek | c5d9523 | 2015-09-20 17:20:42 +0200 | [diff] [blame] | 421 | puts("JTAG_MODE\n"); |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 422 | mode = "pxe dhcp"; |
Michal Simek | 4338035 | 2017-12-01 15:18:24 +0100 | [diff] [blame] | 423 | env_set("modeboot", "jtagboot"); |
Siva Durga Prasad Paladugu | 30f0fc7 | 2015-03-13 11:10:26 +0530 | [diff] [blame] | 424 | break; |
| 425 | case QSPI_MODE_24BIT: |
| 426 | case QSPI_MODE_32BIT: |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 427 | mode = "qspi0"; |
Michal Simek | c5d9523 | 2015-09-20 17:20:42 +0200 | [diff] [blame] | 428 | puts("QSPI_MODE\n"); |
Michal Simek | 4338035 | 2017-12-01 15:18:24 +0100 | [diff] [blame] | 429 | env_set("modeboot", "qspiboot"); |
Siva Durga Prasad Paladugu | 30f0fc7 | 2015-03-13 11:10:26 +0530 | [diff] [blame] | 430 | break; |
Michal Simek | 02d66cd | 2015-04-15 15:02:28 +0200 | [diff] [blame] | 431 | case EMMC_MODE: |
Michal Simek | df7ff0a | 2015-10-05 15:59:38 +0200 | [diff] [blame] | 432 | puts("EMMC_MODE\n"); |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 433 | mode = "mmc0"; |
Michal Simek | 4338035 | 2017-12-01 15:18:24 +0100 | [diff] [blame] | 434 | env_set("modeboot", "emmcboot"); |
Michal Simek | df7ff0a | 2015-10-05 15:59:38 +0200 | [diff] [blame] | 435 | break; |
| 436 | case SD_MODE: |
Michal Simek | c5d9523 | 2015-09-20 17:20:42 +0200 | [diff] [blame] | 437 | puts("SD_MODE\n"); |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 438 | mode = "mmc0"; |
Michal Simek | 4338035 | 2017-12-01 15:18:24 +0100 | [diff] [blame] | 439 | env_set("modeboot", "sdboot"); |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 440 | break; |
Siva Durga Prasad Paladugu | 29a77d2 | 2016-09-21 11:45:05 +0530 | [diff] [blame] | 441 | case SD1_LSHFT_MODE: |
| 442 | puts("LVL_SHFT_"); |
| 443 | /* fall through */ |
Michal Simek | 108e184 | 2015-10-05 10:51:12 +0200 | [diff] [blame] | 444 | case SD_MODE1: |
Michal Simek | c5d9523 | 2015-09-20 17:20:42 +0200 | [diff] [blame] | 445 | puts("SD_MODE1\n"); |
Michal Simek | 6d90245 | 2015-11-06 10:22:37 +0100 | [diff] [blame] | 446 | #if defined(CONFIG_ZYNQ_SDHCI0) && defined(CONFIG_ZYNQ_SDHCI1) |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 447 | mode = "mmc1"; |
Michal Simek | 4338035 | 2017-12-01 15:18:24 +0100 | [diff] [blame] | 448 | env_set("sdbootdev", "1"); |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 449 | #else |
| 450 | mode = "mmc0"; |
Michal Simek | 6d90245 | 2015-11-06 10:22:37 +0100 | [diff] [blame] | 451 | #endif |
Michal Simek | 4338035 | 2017-12-01 15:18:24 +0100 | [diff] [blame] | 452 | env_set("modeboot", "sdboot"); |
Michal Simek | 108e184 | 2015-10-05 10:51:12 +0200 | [diff] [blame] | 453 | break; |
| 454 | case NAND_MODE: |
Michal Simek | c5d9523 | 2015-09-20 17:20:42 +0200 | [diff] [blame] | 455 | puts("NAND_MODE\n"); |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 456 | mode = "nand0"; |
Michal Simek | 4338035 | 2017-12-01 15:18:24 +0100 | [diff] [blame] | 457 | env_set("modeboot", "nandboot"); |
Michal Simek | 108e184 | 2015-10-05 10:51:12 +0200 | [diff] [blame] | 458 | break; |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 459 | default: |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 460 | mode = ""; |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 461 | printf("Invalid Boot Mode:0x%x\n", bootmode); |
| 462 | break; |
| 463 | } |
| 464 | |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 465 | /* |
| 466 | * One terminating char + one byte for space between mode |
| 467 | * and default boot_targets |
| 468 | */ |
Siva Durga Prasad Paladugu | 245c556 | 2017-12-20 16:35:06 +0530 | [diff] [blame] | 469 | env_targets = env_get("boot_targets"); |
| 470 | if (env_targets) { |
| 471 | new_targets = calloc(1, strlen(mode) + |
| 472 | strlen(env_targets) + 2); |
| 473 | sprintf(new_targets, "%s %s", mode, env_targets); |
| 474 | } else { |
| 475 | new_targets = calloc(1, strlen(mode) + 2); |
| 476 | sprintf(new_targets, "%s", mode); |
| 477 | } |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 478 | |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 479 | env_set("boot_targets", new_targets); |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 480 | |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 481 | return 0; |
| 482 | } |
Siva Durga Prasad Paladugu | 650e0a3 | 2015-08-04 13:01:05 +0530 | [diff] [blame] | 483 | |
| 484 | int checkboard(void) |
| 485 | { |
Michal Simek | 47ce936 | 2016-01-25 11:04:21 +0100 | [diff] [blame] | 486 | puts("Board: Xilinx ZynqMP\n"); |
Siva Durga Prasad Paladugu | 650e0a3 | 2015-08-04 13:01:05 +0530 | [diff] [blame] | 487 | return 0; |
| 488 | } |
Siva Durga Prasad Paladugu | ba1f68e | 2015-08-04 13:03:26 +0530 | [diff] [blame] | 489 | |
| 490 | #ifdef CONFIG_USB_DWC3 |
Michal Simek | ea526be | 2016-08-08 10:11:26 +0200 | [diff] [blame] | 491 | static struct dwc3_device dwc3_device_data0 = { |
Siva Durga Prasad Paladugu | ba1f68e | 2015-08-04 13:03:26 +0530 | [diff] [blame] | 492 | .maximum_speed = USB_SPEED_HIGH, |
| 493 | .base = ZYNQMP_USB0_XHCI_BASEADDR, |
| 494 | .dr_mode = USB_DR_MODE_PERIPHERAL, |
| 495 | .index = 0, |
| 496 | }; |
| 497 | |
Michal Simek | ea526be | 2016-08-08 10:11:26 +0200 | [diff] [blame] | 498 | static struct dwc3_device dwc3_device_data1 = { |
| 499 | .maximum_speed = USB_SPEED_HIGH, |
| 500 | .base = ZYNQMP_USB1_XHCI_BASEADDR, |
| 501 | .dr_mode = USB_DR_MODE_PERIPHERAL, |
| 502 | .index = 1, |
| 503 | }; |
| 504 | |
Michal Simek | 76d0a77 | 2016-09-01 11:16:40 +0200 | [diff] [blame] | 505 | int usb_gadget_handle_interrupts(int index) |
Siva Durga Prasad Paladugu | ba1f68e | 2015-08-04 13:03:26 +0530 | [diff] [blame] | 506 | { |
Michal Simek | 76d0a77 | 2016-09-01 11:16:40 +0200 | [diff] [blame] | 507 | dwc3_uboot_handle_interrupt(index); |
Siva Durga Prasad Paladugu | ba1f68e | 2015-08-04 13:03:26 +0530 | [diff] [blame] | 508 | return 0; |
| 509 | } |
| 510 | |
| 511 | int board_usb_init(int index, enum usb_init_type init) |
| 512 | { |
Michal Simek | ea526be | 2016-08-08 10:11:26 +0200 | [diff] [blame] | 513 | debug("%s: index %x\n", __func__, index); |
| 514 | |
Michal Simek | 7987d2a | 2016-09-01 11:27:32 +0200 | [diff] [blame] | 515 | #if defined(CONFIG_USB_GADGET_DOWNLOAD) |
| 516 | g_dnl_set_serialnumber(CONFIG_SYS_CONFIG_NAME); |
| 517 | #endif |
| 518 | |
Michal Simek | ea526be | 2016-08-08 10:11:26 +0200 | [diff] [blame] | 519 | switch (index) { |
| 520 | case 0: |
| 521 | return dwc3_uboot_init(&dwc3_device_data0); |
| 522 | case 1: |
| 523 | return dwc3_uboot_init(&dwc3_device_data1); |
| 524 | }; |
| 525 | |
| 526 | return -1; |
Siva Durga Prasad Paladugu | ba1f68e | 2015-08-04 13:03:26 +0530 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | int board_usb_cleanup(int index, enum usb_init_type init) |
| 530 | { |
| 531 | dwc3_uboot_exit(index); |
| 532 | return 0; |
| 533 | } |
| 534 | #endif |