Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2014 - 2015 Xilinx, Inc. |
| 4 | * Michal Simek <michal.simek@xilinx.com> |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Michal Simek | d54b1af | 2015-09-30 17:26:55 +0200 | [diff] [blame] | 8 | #include <sata.h> |
Michal Simek | b216cc1 | 2015-07-23 13:27:40 +0200 | [diff] [blame] | 9 | #include <ahci.h> |
| 10 | #include <scsi.h> |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 11 | #include <malloc.h> |
Michal Simek | bf0f9ca | 2018-04-19 15:43:38 +0200 | [diff] [blame] | 12 | #include <wdt.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> |
Michal Simek | f183a98 | 2018-04-25 11:20:43 +0200 | [diff] [blame] | 18 | #include <dm/device.h> |
Michal Simek | bf0f9ca | 2018-04-19 15:43:38 +0200 | [diff] [blame] | 19 | #include <dm/uclass.h> |
Siva Durga Prasad Paladugu | ba1f68e | 2015-08-04 13:03:26 +0530 | [diff] [blame] | 20 | #include <usb.h> |
| 21 | #include <dwc3-uboot.h> |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 22 | #include <zynqmppl.h> |
Michal Simek | eec32f6 | 2016-04-22 11:48:49 +0200 | [diff] [blame] | 23 | #include <i2c.h> |
Michal Simek | 76d0a77 | 2016-09-01 11:16:40 +0200 | [diff] [blame] | 24 | #include <g_dnl.h> |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 25 | |
| 26 | DECLARE_GLOBAL_DATA_PTR; |
| 27 | |
Michal Simek | bf0f9ca | 2018-04-19 15:43:38 +0200 | [diff] [blame] | 28 | #if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_WDT) |
| 29 | static struct udevice *watchdog_dev; |
| 30 | #endif |
| 31 | |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 32 | #if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \ |
| 33 | !defined(CONFIG_SPL_BUILD) |
| 34 | static xilinx_desc zynqmppl = XILINX_ZYNQMP_DESC; |
| 35 | |
| 36 | static const struct { |
Michal Simek | 6908b86 | 2017-11-06 12:55:59 +0100 | [diff] [blame] | 37 | u32 id; |
Michal Simek | 50d8cef | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 38 | u32 ver; |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 39 | char *name; |
Siva Durga Prasad Paladugu | ba2622d | 2018-03-02 16:20:10 +0530 | [diff] [blame] | 40 | bool evexists; |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 41 | } zynqmp_devices[] = { |
| 42 | { |
| 43 | .id = 0x10, |
| 44 | .name = "3eg", |
| 45 | }, |
| 46 | { |
Michal Simek | 50d8cef | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 47 | .id = 0x10, |
| 48 | .ver = 0x2c, |
| 49 | .name = "3cg", |
| 50 | }, |
| 51 | { |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 52 | .id = 0x11, |
| 53 | .name = "2eg", |
| 54 | }, |
| 55 | { |
Michal Simek | 50d8cef | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 56 | .id = 0x11, |
| 57 | .ver = 0x2c, |
| 58 | .name = "2cg", |
| 59 | }, |
| 60 | { |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 61 | .id = 0x20, |
| 62 | .name = "5ev", |
Siva Durga Prasad Paladugu | ba2622d | 2018-03-02 16:20:10 +0530 | [diff] [blame] | 63 | .evexists = 1, |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 64 | }, |
| 65 | { |
Michal Simek | 50d8cef | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 66 | .id = 0x20, |
| 67 | .ver = 0x100, |
| 68 | .name = "5eg", |
Siva Durga Prasad Paladugu | ba2622d | 2018-03-02 16:20:10 +0530 | [diff] [blame] | 69 | .evexists = 1, |
Michal Simek | 50d8cef | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 70 | }, |
| 71 | { |
| 72 | .id = 0x20, |
| 73 | .ver = 0x12c, |
| 74 | .name = "5cg", |
| 75 | }, |
| 76 | { |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 77 | .id = 0x21, |
| 78 | .name = "4ev", |
Siva Durga Prasad Paladugu | ba2622d | 2018-03-02 16:20:10 +0530 | [diff] [blame] | 79 | .evexists = 1, |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 80 | }, |
| 81 | { |
Michal Simek | 50d8cef | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 82 | .id = 0x21, |
| 83 | .ver = 0x100, |
| 84 | .name = "4eg", |
Siva Durga Prasad Paladugu | ba2622d | 2018-03-02 16:20:10 +0530 | [diff] [blame] | 85 | .evexists = 1, |
Michal Simek | 50d8cef | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 86 | }, |
| 87 | { |
| 88 | .id = 0x21, |
| 89 | .ver = 0x12c, |
| 90 | .name = "4cg", |
| 91 | }, |
| 92 | { |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 93 | .id = 0x30, |
| 94 | .name = "7ev", |
Siva Durga Prasad Paladugu | ba2622d | 2018-03-02 16:20:10 +0530 | [diff] [blame] | 95 | .evexists = 1, |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 96 | }, |
| 97 | { |
Michal Simek | 50d8cef | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 98 | .id = 0x30, |
| 99 | .ver = 0x100, |
| 100 | .name = "7eg", |
Siva Durga Prasad Paladugu | ba2622d | 2018-03-02 16:20:10 +0530 | [diff] [blame] | 101 | .evexists = 1, |
Michal Simek | 50d8cef | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 102 | }, |
| 103 | { |
| 104 | .id = 0x30, |
| 105 | .ver = 0x12c, |
| 106 | .name = "7cg", |
| 107 | }, |
| 108 | { |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 109 | .id = 0x38, |
| 110 | .name = "9eg", |
| 111 | }, |
| 112 | { |
Michal Simek | 50d8cef | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 113 | .id = 0x38, |
| 114 | .ver = 0x2c, |
| 115 | .name = "9cg", |
| 116 | }, |
| 117 | { |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 118 | .id = 0x39, |
| 119 | .name = "6eg", |
| 120 | }, |
| 121 | { |
Michal Simek | 50d8cef | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 122 | .id = 0x39, |
| 123 | .ver = 0x2c, |
| 124 | .name = "6cg", |
| 125 | }, |
| 126 | { |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 127 | .id = 0x40, |
| 128 | .name = "11eg", |
| 129 | }, |
Michal Simek | 50d8cef | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 130 | { /* For testing purpose only */ |
| 131 | .id = 0x50, |
| 132 | .ver = 0x2c, |
| 133 | .name = "15cg", |
| 134 | }, |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 135 | { |
| 136 | .id = 0x50, |
| 137 | .name = "15eg", |
| 138 | }, |
| 139 | { |
| 140 | .id = 0x58, |
| 141 | .name = "19eg", |
| 142 | }, |
| 143 | { |
| 144 | .id = 0x59, |
| 145 | .name = "17eg", |
| 146 | }, |
Michal Simek | b510e53 | 2017-06-02 08:08:59 +0200 | [diff] [blame] | 147 | { |
| 148 | .id = 0x61, |
| 149 | .name = "21dr", |
| 150 | }, |
| 151 | { |
| 152 | .id = 0x63, |
| 153 | .name = "23dr", |
| 154 | }, |
| 155 | { |
| 156 | .id = 0x65, |
| 157 | .name = "25dr", |
| 158 | }, |
| 159 | { |
| 160 | .id = 0x64, |
| 161 | .name = "27dr", |
| 162 | }, |
| 163 | { |
| 164 | .id = 0x60, |
| 165 | .name = "28dr", |
| 166 | }, |
| 167 | { |
| 168 | .id = 0x62, |
| 169 | .name = "29dr", |
| 170 | }, |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 171 | }; |
Siva Durga Prasad Paladugu | 8d52653 | 2017-07-25 11:51:37 +0530 | [diff] [blame] | 172 | #endif |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 173 | |
Siva Durga Prasad Paladugu | cd35d52 | 2017-07-25 11:51:38 +0530 | [diff] [blame] | 174 | int chip_id(unsigned char id) |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 175 | { |
| 176 | struct pt_regs regs; |
Siva Durga Prasad Paladugu | 9f0a8e9 | 2017-07-25 11:51:36 +0530 | [diff] [blame] | 177 | int val = -EINVAL; |
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 | if (current_el() != 3) { |
| 180 | regs.regs[0] = ZYNQMP_SIP_SVC_CSU_DMA_CHIPID; |
| 181 | regs.regs[1] = 0; |
| 182 | regs.regs[2] = 0; |
| 183 | regs.regs[3] = 0; |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 184 | |
Siva Durga Prasad Paladugu | 8d52653 | 2017-07-25 11:51:37 +0530 | [diff] [blame] | 185 | smc_call(®s); |
| 186 | |
| 187 | /* |
| 188 | * SMC returns: |
| 189 | * regs[0][31:0] = status of the operation |
| 190 | * regs[0][63:32] = CSU.IDCODE register |
| 191 | * regs[1][31:0] = CSU.version register |
Michal Simek | 50d8cef | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 192 | * regs[1][63:32] = CSU.IDCODE2 register |
Siva Durga Prasad Paladugu | 8d52653 | 2017-07-25 11:51:37 +0530 | [diff] [blame] | 193 | */ |
| 194 | switch (id) { |
| 195 | case IDCODE: |
| 196 | regs.regs[0] = upper_32_bits(regs.regs[0]); |
| 197 | regs.regs[0] &= ZYNQMP_CSU_IDCODE_DEVICE_CODE_MASK | |
| 198 | ZYNQMP_CSU_IDCODE_SVD_MASK; |
| 199 | regs.regs[0] >>= ZYNQMP_CSU_IDCODE_SVD_SHIFT; |
| 200 | val = regs.regs[0]; |
| 201 | break; |
| 202 | case VERSION: |
| 203 | regs.regs[1] = lower_32_bits(regs.regs[1]); |
| 204 | regs.regs[1] &= ZYNQMP_CSU_SILICON_VER_MASK; |
| 205 | val = regs.regs[1]; |
| 206 | break; |
Michal Simek | 50d8cef | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 207 | case IDCODE2: |
| 208 | regs.regs[1] = lower_32_bits(regs.regs[1]); |
| 209 | regs.regs[1] >>= ZYNQMP_CSU_VERSION_EMPTY_SHIFT; |
| 210 | val = regs.regs[1]; |
| 211 | break; |
Siva Durga Prasad Paladugu | 8d52653 | 2017-07-25 11:51:37 +0530 | [diff] [blame] | 212 | default: |
| 213 | printf("%s, Invalid Req:0x%x\n", __func__, id); |
| 214 | } |
| 215 | } else { |
| 216 | switch (id) { |
| 217 | case IDCODE: |
| 218 | val = readl(ZYNQMP_CSU_IDCODE_ADDR); |
| 219 | val &= ZYNQMP_CSU_IDCODE_DEVICE_CODE_MASK | |
| 220 | ZYNQMP_CSU_IDCODE_SVD_MASK; |
| 221 | val >>= ZYNQMP_CSU_IDCODE_SVD_SHIFT; |
| 222 | break; |
| 223 | case VERSION: |
| 224 | val = readl(ZYNQMP_CSU_VER_ADDR); |
| 225 | val &= ZYNQMP_CSU_SILICON_VER_MASK; |
| 226 | break; |
| 227 | default: |
| 228 | printf("%s, Invalid Req:0x%x\n", __func__, id); |
| 229 | } |
Siva Durga Prasad Paladugu | 9f0a8e9 | 2017-07-25 11:51:36 +0530 | [diff] [blame] | 230 | } |
Soren Brinkmann | d7696a5 | 2016-09-29 11:44:41 -0700 | [diff] [blame] | 231 | |
Siva Durga Prasad Paladugu | 9f0a8e9 | 2017-07-25 11:51:36 +0530 | [diff] [blame] | 232 | return val; |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 233 | } |
| 234 | |
Siva Durga Prasad Paladugu | ba2622d | 2018-03-02 16:20:10 +0530 | [diff] [blame] | 235 | #define ZYNQMP_VERSION_SIZE 9 |
| 236 | #define ZYNQMP_PL_STATUS_BIT 9 |
| 237 | #define ZYNQMP_PL_STATUS_MASK BIT(ZYNQMP_PL_STATUS_BIT) |
| 238 | #define ZYNQMP_CSU_VERSION_MASK ~(ZYNQMP_PL_STATUS_MASK) |
| 239 | |
Siva Durga Prasad Paladugu | 8d52653 | 2017-07-25 11:51:37 +0530 | [diff] [blame] | 240 | #if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \ |
| 241 | !defined(CONFIG_SPL_BUILD) |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 242 | static char *zynqmp_get_silicon_idcode_name(void) |
| 243 | { |
Michal Simek | 50d8cef | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 244 | u32 i, id, ver; |
Siva Durga Prasad Paladugu | ba2622d | 2018-03-02 16:20:10 +0530 | [diff] [blame] | 245 | char *buf; |
| 246 | static char name[ZYNQMP_VERSION_SIZE]; |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 247 | |
Siva Durga Prasad Paladugu | 9f0a8e9 | 2017-07-25 11:51:36 +0530 | [diff] [blame] | 248 | id = chip_id(IDCODE); |
Michal Simek | 50d8cef | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 249 | ver = chip_id(IDCODE2); |
| 250 | |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 251 | for (i = 0; i < ARRAY_SIZE(zynqmp_devices); i++) { |
Siva Durga Prasad Paladugu | ba2622d | 2018-03-02 16:20:10 +0530 | [diff] [blame] | 252 | if ((zynqmp_devices[i].id == id) && |
| 253 | (zynqmp_devices[i].ver == (ver & |
| 254 | ZYNQMP_CSU_VERSION_MASK))) { |
| 255 | strncat(name, "zu", 2); |
| 256 | strncat(name, zynqmp_devices[i].name, |
| 257 | ZYNQMP_VERSION_SIZE - 3); |
| 258 | break; |
| 259 | } |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 260 | } |
Siva Durga Prasad Paladugu | ba2622d | 2018-03-02 16:20:10 +0530 | [diff] [blame] | 261 | |
| 262 | if (i >= ARRAY_SIZE(zynqmp_devices)) |
| 263 | return "unknown"; |
| 264 | |
| 265 | if (!zynqmp_devices[i].evexists) |
| 266 | return name; |
| 267 | |
| 268 | if (ver & ZYNQMP_PL_STATUS_MASK) |
| 269 | return name; |
| 270 | |
| 271 | if (strstr(name, "eg") || strstr(name, "ev")) { |
| 272 | buf = strstr(name, "e"); |
| 273 | *buf = '\0'; |
| 274 | } |
| 275 | |
| 276 | return name; |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 277 | } |
| 278 | #endif |
| 279 | |
Michal Simek | 8b35330 | 2017-02-07 14:32:26 +0100 | [diff] [blame] | 280 | int board_early_init_f(void) |
| 281 | { |
Michal Simek | c8785f2 | 2018-01-10 11:48:48 +0100 | [diff] [blame] | 282 | int ret = 0; |
Michal Simek | 8b35330 | 2017-02-07 14:32:26 +0100 | [diff] [blame] | 283 | #if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_CLK_ZYNQMP) |
Siva Durga Prasad Paladugu | 8406d47 | 2018-08-21 15:44:49 +0530 | [diff] [blame] | 284 | u32 pm_api_version; |
| 285 | |
| 286 | pm_api_version = zynqmp_pmufw_version(); |
| 287 | printf("PMUFW:\tv%d.%d\n", |
| 288 | pm_api_version >> ZYNQMP_PM_VERSION_MAJOR_SHIFT, |
| 289 | pm_api_version & ZYNQMP_PM_VERSION_MINOR_MASK); |
| 290 | |
| 291 | if (pm_api_version < ZYNQMP_PM_VERSION) |
| 292 | panic("PMUFW version error. Expected: v%d.%d\n", |
| 293 | ZYNQMP_PM_VERSION_MAJOR, ZYNQMP_PM_VERSION_MINOR); |
Michal Simek | 8b35330 | 2017-02-07 14:32:26 +0100 | [diff] [blame] | 294 | #endif |
Michal Simek | e0f3610 | 2017-07-12 13:08:41 +0200 | [diff] [blame] | 295 | |
Michal Simek | 1a1ab5a | 2018-01-15 12:52:59 +0100 | [diff] [blame] | 296 | #if defined(CONFIG_ZYNQMP_PSU_INIT_ENABLED) |
Michal Simek | c8785f2 | 2018-01-10 11:48:48 +0100 | [diff] [blame] | 297 | ret = psu_init(); |
Michal Simek | e0f3610 | 2017-07-12 13:08:41 +0200 | [diff] [blame] | 298 | #endif |
| 299 | |
Michal Simek | bf0f9ca | 2018-04-19 15:43:38 +0200 | [diff] [blame] | 300 | #if defined(CONFIG_WDT) && !defined(CONFIG_SPL_BUILD) |
| 301 | /* bss is not cleared at time when watchdog_reset() is called */ |
| 302 | watchdog_dev = NULL; |
| 303 | #endif |
| 304 | |
Michal Simek | c8785f2 | 2018-01-10 11:48:48 +0100 | [diff] [blame] | 305 | return ret; |
Michal Simek | 8b35330 | 2017-02-07 14:32:26 +0100 | [diff] [blame] | 306 | } |
| 307 | |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 308 | int board_init(void) |
| 309 | { |
Michal Simek | fb7242d | 2015-06-22 14:31:06 +0200 | [diff] [blame] | 310 | printf("EL Level:\tEL%d\n", current_el()); |
| 311 | |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 312 | #if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \ |
| 313 | !defined(CONFIG_SPL_BUILD) || (defined(CONFIG_SPL_FPGA_SUPPORT) && \ |
| 314 | defined(CONFIG_SPL_BUILD)) |
| 315 | if (current_el() != 3) { |
Siva Durga Prasad Paladugu | ba2622d | 2018-03-02 16:20:10 +0530 | [diff] [blame] | 316 | zynqmppl.name = zynqmp_get_silicon_idcode_name(); |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 317 | printf("Chip ID:\t%s\n", zynqmppl.name); |
| 318 | fpga_init(); |
| 319 | fpga_add(fpga_xilinx, &zynqmppl); |
| 320 | } |
| 321 | #endif |
| 322 | |
Michal Simek | bf0f9ca | 2018-04-19 15:43:38 +0200 | [diff] [blame] | 323 | #if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_WDT) |
Michal Simek | 169d34b | 2018-07-11 08:30:07 +0200 | [diff] [blame] | 324 | if (uclass_get_device_by_seq(UCLASS_WDT, 0, &watchdog_dev)) { |
| 325 | debug("Watchdog: Not found by seq!\n"); |
| 326 | if (uclass_get_device(UCLASS_WDT, 0, &watchdog_dev)) { |
| 327 | puts("Watchdog: Not found!\n"); |
| 328 | return 0; |
| 329 | } |
Michal Simek | bf0f9ca | 2018-04-19 15:43:38 +0200 | [diff] [blame] | 330 | } |
Michal Simek | 169d34b | 2018-07-11 08:30:07 +0200 | [diff] [blame] | 331 | |
| 332 | wdt_start(watchdog_dev, 0, 0); |
| 333 | puts("Watchdog: Started\n"); |
Michal Simek | bf0f9ca | 2018-04-19 15:43:38 +0200 | [diff] [blame] | 334 | #endif |
| 335 | |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 336 | return 0; |
| 337 | } |
| 338 | |
Michal Simek | bf0f9ca | 2018-04-19 15:43:38 +0200 | [diff] [blame] | 339 | #ifdef CONFIG_WATCHDOG |
| 340 | /* Called by macro WATCHDOG_RESET */ |
| 341 | void watchdog_reset(void) |
| 342 | { |
| 343 | # if !defined(CONFIG_SPL_BUILD) |
| 344 | static ulong next_reset; |
| 345 | ulong now; |
| 346 | |
| 347 | if (!watchdog_dev) |
| 348 | return; |
| 349 | |
| 350 | now = timer_get_us(); |
| 351 | |
| 352 | /* Do not reset the watchdog too often */ |
| 353 | if (now > next_reset) { |
| 354 | wdt_reset(watchdog_dev); |
| 355 | next_reset = now + 1000; |
| 356 | } |
| 357 | # endif |
| 358 | } |
| 359 | #endif |
| 360 | |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 361 | int board_early_init_r(void) |
| 362 | { |
| 363 | u32 val; |
| 364 | |
Siva Durga Prasad Paladugu | 64d9000 | 2017-12-07 15:05:30 +0530 | [diff] [blame] | 365 | if (current_el() != 3) |
| 366 | return 0; |
| 367 | |
Michal Simek | 245d528 | 2017-07-12 10:32:18 +0200 | [diff] [blame] | 368 | val = readl(&crlapb_base->timestamp_ref_ctrl); |
| 369 | val &= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT; |
| 370 | |
Siva Durga Prasad Paladugu | 64d9000 | 2017-12-07 15:05:30 +0530 | [diff] [blame] | 371 | if (!val) { |
Michal Simek | c23d3f8 | 2015-11-05 08:34:35 +0100 | [diff] [blame] | 372 | val = readl(&crlapb_base->timestamp_ref_ctrl); |
| 373 | val |= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT; |
| 374 | writel(val, &crlapb_base->timestamp_ref_ctrl); |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 375 | |
Michal Simek | c23d3f8 | 2015-11-05 08:34:35 +0100 | [diff] [blame] | 376 | /* Program freq register in System counter */ |
| 377 | writel(zynqmp_get_system_timer_freq(), |
| 378 | &iou_scntr_secure->base_frequency_id_register); |
| 379 | /* And enable system counter */ |
| 380 | writel(ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_EN, |
| 381 | &iou_scntr_secure->counter_control_register); |
| 382 | } |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 383 | return 0; |
| 384 | } |
| 385 | |
Michal Simek | eec32f6 | 2016-04-22 11:48:49 +0200 | [diff] [blame] | 386 | int zynq_board_read_rom_ethaddr(unsigned char *ethaddr) |
| 387 | { |
| 388 | #if defined(CONFIG_ZYNQ_GEM_EEPROM_ADDR) && \ |
| 389 | defined(CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET) && \ |
| 390 | defined(CONFIG_ZYNQ_EEPROM_BUS) |
| 391 | i2c_set_bus_num(CONFIG_ZYNQ_EEPROM_BUS); |
| 392 | |
| 393 | if (eeprom_read(CONFIG_ZYNQ_GEM_EEPROM_ADDR, |
| 394 | CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET, |
| 395 | ethaddr, 6)) |
| 396 | printf("I2C EEPROM MAC address read failed\n"); |
| 397 | #endif |
| 398 | |
| 399 | return 0; |
| 400 | } |
| 401 | |
Nitin Jain | b2eb59b | 2018-02-16 12:56:17 +0530 | [diff] [blame] | 402 | unsigned long do_go_exec(ulong (*entry)(int, char * const []), int argc, |
| 403 | char * const argv[]) |
| 404 | { |
| 405 | int ret = 0; |
| 406 | |
| 407 | if (current_el() > 1) { |
| 408 | smp_kick_all_cpus(); |
| 409 | dcache_disable(); |
| 410 | armv8_switch_to_el1(0x0, 0, 0, 0, (unsigned long)entry, |
| 411 | ES_TO_AARCH64); |
| 412 | } else { |
| 413 | printf("FAIL: current EL is not above EL1\n"); |
| 414 | ret = EINVAL; |
| 415 | } |
| 416 | return ret; |
| 417 | } |
| 418 | |
Michal Simek | 8faa66a | 2016-02-08 09:34:53 +0100 | [diff] [blame] | 419 | #if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE) |
Simon Glass | 2f949c3 | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 420 | int dram_init_banksize(void) |
Michal Simek | 8faa66a | 2016-02-08 09:34:53 +0100 | [diff] [blame] | 421 | { |
Nitin Jain | 9bcc76f | 2018-04-20 12:30:40 +0530 | [diff] [blame] | 422 | int ret; |
| 423 | |
| 424 | ret = fdtdec_setup_memory_banksize(); |
| 425 | if (ret) |
| 426 | return ret; |
| 427 | |
| 428 | mem_map_fill(); |
| 429 | |
| 430 | return 0; |
Tom Rini | edcfdbd | 2016-12-09 07:56:54 -0500 | [diff] [blame] | 431 | } |
Michal Simek | 8faa66a | 2016-02-08 09:34:53 +0100 | [diff] [blame] | 432 | |
Tom Rini | edcfdbd | 2016-12-09 07:56:54 -0500 | [diff] [blame] | 433 | int dram_init(void) |
| 434 | { |
Siva Durga Prasad Paladugu | b3d55ea | 2018-07-16 15:56:11 +0530 | [diff] [blame] | 435 | if (fdtdec_setup_mem_size_base() != 0) |
Nathan Rossi | ac04bfa | 2016-12-19 00:03:34 +1000 | [diff] [blame] | 436 | return -EINVAL; |
Tom Rini | edcfdbd | 2016-12-09 07:56:54 -0500 | [diff] [blame] | 437 | |
| 438 | return 0; |
Michal Simek | 8faa66a | 2016-02-08 09:34:53 +0100 | [diff] [blame] | 439 | } |
| 440 | #else |
Nitin Jain | 9bcc76f | 2018-04-20 12:30:40 +0530 | [diff] [blame] | 441 | int dram_init_banksize(void) |
| 442 | { |
| 443 | #if defined(CONFIG_NR_DRAM_BANKS) |
| 444 | gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE; |
| 445 | gd->bd->bi_dram[0].size = get_effective_memsize(); |
| 446 | #endif |
| 447 | |
| 448 | mem_map_fill(); |
| 449 | |
| 450 | return 0; |
| 451 | } |
| 452 | |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 453 | int dram_init(void) |
| 454 | { |
Michal Simek | 1b84621 | 2018-04-11 16:12:28 +0200 | [diff] [blame] | 455 | gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE, |
| 456 | CONFIG_SYS_SDRAM_SIZE); |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 457 | |
| 458 | return 0; |
| 459 | } |
Michal Simek | 8faa66a | 2016-02-08 09:34:53 +0100 | [diff] [blame] | 460 | #endif |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 461 | |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 462 | void reset_cpu(ulong addr) |
| 463 | { |
| 464 | } |
| 465 | |
Michal Simek | 29b9b71 | 2018-05-17 14:06:06 +0200 | [diff] [blame] | 466 | static const struct { |
| 467 | u32 bit; |
| 468 | const char *name; |
| 469 | } reset_reasons[] = { |
| 470 | { RESET_REASON_DEBUG_SYS, "DEBUG" }, |
| 471 | { RESET_REASON_SOFT, "SOFT" }, |
| 472 | { RESET_REASON_SRST, "SRST" }, |
| 473 | { RESET_REASON_PSONLY, "PS-ONLY" }, |
| 474 | { RESET_REASON_PMU, "PMU" }, |
| 475 | { RESET_REASON_INTERNAL, "INTERNAL" }, |
| 476 | { RESET_REASON_EXTERNAL, "EXTERNAL" }, |
| 477 | {} |
| 478 | }; |
| 479 | |
| 480 | static u32 reset_reason(void) |
| 481 | { |
| 482 | u32 ret; |
| 483 | int i; |
| 484 | const char *reason = NULL; |
| 485 | |
| 486 | ret = readl(&crlapb_base->reset_reason); |
| 487 | |
| 488 | puts("Reset reason:\t"); |
| 489 | |
| 490 | for (i = 0; i < ARRAY_SIZE(reset_reasons); i++) { |
| 491 | if (ret & reset_reasons[i].bit) { |
| 492 | reason = reset_reasons[i].name; |
| 493 | printf("%s ", reset_reasons[i].name); |
| 494 | break; |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | puts("\n"); |
| 499 | |
| 500 | env_set("reset_reason", reason); |
| 501 | |
| 502 | writel(~0, &crlapb_base->reset_reason); |
| 503 | |
| 504 | return ret; |
| 505 | } |
| 506 | |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 507 | int board_late_init(void) |
| 508 | { |
| 509 | u32 reg = 0; |
| 510 | u8 bootmode; |
Michal Simek | f183a98 | 2018-04-25 11:20:43 +0200 | [diff] [blame] | 511 | struct udevice *dev; |
| 512 | int bootseq = -1; |
| 513 | int bootseq_len = 0; |
Michal Simek | 7410b14 | 2018-04-25 11:10:34 +0200 | [diff] [blame] | 514 | int env_targets_len = 0; |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 515 | const char *mode; |
| 516 | char *new_targets; |
Siva Durga Prasad Paladugu | 245c556 | 2017-12-20 16:35:06 +0530 | [diff] [blame] | 517 | char *env_targets; |
Siva Durga Prasad Paladugu | e6fd3bb | 2017-02-21 17:58:28 +0530 | [diff] [blame] | 518 | int ret; |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 519 | |
| 520 | if (!(gd->flags & GD_FLG_ENV_DEFAULT)) { |
| 521 | debug("Saved variables - Skipping\n"); |
| 522 | return 0; |
| 523 | } |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 524 | |
Siva Durga Prasad Paladugu | e6fd3bb | 2017-02-21 17:58:28 +0530 | [diff] [blame] | 525 | ret = zynqmp_mmio_read((ulong)&crlapb_base->boot_mode, ®); |
| 526 | if (ret) |
| 527 | return -EINVAL; |
| 528 | |
Michal Simek | 833e0c4 | 2016-10-25 11:43:02 +0200 | [diff] [blame] | 529 | if (reg >> BOOT_MODE_ALT_SHIFT) |
| 530 | reg >>= BOOT_MODE_ALT_SHIFT; |
| 531 | |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 532 | bootmode = reg & BOOT_MODES_MASK; |
| 533 | |
Michal Simek | c5d9523 | 2015-09-20 17:20:42 +0200 | [diff] [blame] | 534 | puts("Bootmode: "); |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 535 | switch (bootmode) { |
Michal Simek | 12398ea | 2016-08-19 14:14:52 +0200 | [diff] [blame] | 536 | case USB_MODE: |
| 537 | puts("USB_MODE\n"); |
| 538 | mode = "usb"; |
Michal Simek | 4338035 | 2017-12-01 15:18:24 +0100 | [diff] [blame] | 539 | env_set("modeboot", "usb_dfu_spl"); |
Michal Simek | 12398ea | 2016-08-19 14:14:52 +0200 | [diff] [blame] | 540 | break; |
Siva Durga Prasad Paladugu | 30f0fc7 | 2015-03-13 11:10:26 +0530 | [diff] [blame] | 541 | case JTAG_MODE: |
Michal Simek | c5d9523 | 2015-09-20 17:20:42 +0200 | [diff] [blame] | 542 | puts("JTAG_MODE\n"); |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 543 | mode = "pxe dhcp"; |
Michal Simek | 4338035 | 2017-12-01 15:18:24 +0100 | [diff] [blame] | 544 | env_set("modeboot", "jtagboot"); |
Siva Durga Prasad Paladugu | 30f0fc7 | 2015-03-13 11:10:26 +0530 | [diff] [blame] | 545 | break; |
| 546 | case QSPI_MODE_24BIT: |
| 547 | case QSPI_MODE_32BIT: |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 548 | mode = "qspi0"; |
Michal Simek | c5d9523 | 2015-09-20 17:20:42 +0200 | [diff] [blame] | 549 | puts("QSPI_MODE\n"); |
Michal Simek | 4338035 | 2017-12-01 15:18:24 +0100 | [diff] [blame] | 550 | env_set("modeboot", "qspiboot"); |
Siva Durga Prasad Paladugu | 30f0fc7 | 2015-03-13 11:10:26 +0530 | [diff] [blame] | 551 | break; |
Michal Simek | 02d66cd | 2015-04-15 15:02:28 +0200 | [diff] [blame] | 552 | case EMMC_MODE: |
Michal Simek | df7ff0a | 2015-10-05 15:59:38 +0200 | [diff] [blame] | 553 | puts("EMMC_MODE\n"); |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 554 | mode = "mmc0"; |
Michal Simek | 4338035 | 2017-12-01 15:18:24 +0100 | [diff] [blame] | 555 | env_set("modeboot", "emmcboot"); |
Michal Simek | df7ff0a | 2015-10-05 15:59:38 +0200 | [diff] [blame] | 556 | break; |
| 557 | case SD_MODE: |
Michal Simek | c5d9523 | 2015-09-20 17:20:42 +0200 | [diff] [blame] | 558 | puts("SD_MODE\n"); |
Michal Simek | f183a98 | 2018-04-25 11:20:43 +0200 | [diff] [blame] | 559 | if (uclass_get_device_by_name(UCLASS_MMC, |
| 560 | "sdhci@ff160000", &dev)) { |
| 561 | puts("Boot from SD0 but without SD0 enabled!\n"); |
| 562 | return -1; |
| 563 | } |
| 564 | debug("mmc0 device found at %p, seq %d\n", dev, dev->seq); |
| 565 | |
| 566 | mode = "mmc"; |
| 567 | bootseq = dev->seq; |
Michal Simek | 4338035 | 2017-12-01 15:18:24 +0100 | [diff] [blame] | 568 | env_set("modeboot", "sdboot"); |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 569 | break; |
Siva Durga Prasad Paladugu | 29a77d2 | 2016-09-21 11:45:05 +0530 | [diff] [blame] | 570 | case SD1_LSHFT_MODE: |
| 571 | puts("LVL_SHFT_"); |
| 572 | /* fall through */ |
Michal Simek | 108e184 | 2015-10-05 10:51:12 +0200 | [diff] [blame] | 573 | case SD_MODE1: |
Michal Simek | c5d9523 | 2015-09-20 17:20:42 +0200 | [diff] [blame] | 574 | puts("SD_MODE1\n"); |
Michal Simek | f183a98 | 2018-04-25 11:20:43 +0200 | [diff] [blame] | 575 | if (uclass_get_device_by_name(UCLASS_MMC, |
| 576 | "sdhci@ff170000", &dev)) { |
| 577 | puts("Boot from SD1 but without SD1 enabled!\n"); |
| 578 | return -1; |
| 579 | } |
| 580 | debug("mmc1 device found at %p, seq %d\n", dev, dev->seq); |
| 581 | |
| 582 | mode = "mmc"; |
| 583 | bootseq = dev->seq; |
Michal Simek | 4338035 | 2017-12-01 15:18:24 +0100 | [diff] [blame] | 584 | env_set("modeboot", "sdboot"); |
Michal Simek | 108e184 | 2015-10-05 10:51:12 +0200 | [diff] [blame] | 585 | break; |
| 586 | case NAND_MODE: |
Michal Simek | c5d9523 | 2015-09-20 17:20:42 +0200 | [diff] [blame] | 587 | puts("NAND_MODE\n"); |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 588 | mode = "nand0"; |
Michal Simek | 4338035 | 2017-12-01 15:18:24 +0100 | [diff] [blame] | 589 | env_set("modeboot", "nandboot"); |
Michal Simek | 108e184 | 2015-10-05 10:51:12 +0200 | [diff] [blame] | 590 | break; |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 591 | default: |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 592 | mode = ""; |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 593 | printf("Invalid Boot Mode:0x%x\n", bootmode); |
| 594 | break; |
| 595 | } |
| 596 | |
Michal Simek | f183a98 | 2018-04-25 11:20:43 +0200 | [diff] [blame] | 597 | if (bootseq >= 0) { |
| 598 | bootseq_len = snprintf(NULL, 0, "%i", bootseq); |
| 599 | debug("Bootseq len: %x\n", bootseq_len); |
| 600 | } |
| 601 | |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 602 | /* |
| 603 | * One terminating char + one byte for space between mode |
| 604 | * and default boot_targets |
| 605 | */ |
Siva Durga Prasad Paladugu | 245c556 | 2017-12-20 16:35:06 +0530 | [diff] [blame] | 606 | env_targets = env_get("boot_targets"); |
Michal Simek | 7410b14 | 2018-04-25 11:10:34 +0200 | [diff] [blame] | 607 | if (env_targets) |
| 608 | env_targets_len = strlen(env_targets); |
| 609 | |
Michal Simek | f183a98 | 2018-04-25 11:20:43 +0200 | [diff] [blame] | 610 | new_targets = calloc(1, strlen(mode) + env_targets_len + 2 + |
| 611 | bootseq_len); |
Michal Simek | 089b84d | 2018-06-13 09:42:41 +0200 | [diff] [blame] | 612 | if (!new_targets) |
| 613 | return -ENOMEM; |
Michal Simek | 7410b14 | 2018-04-25 11:10:34 +0200 | [diff] [blame] | 614 | |
Michal Simek | f183a98 | 2018-04-25 11:20:43 +0200 | [diff] [blame] | 615 | if (bootseq >= 0) |
| 616 | sprintf(new_targets, "%s%x %s", mode, bootseq, |
| 617 | env_targets ? env_targets : ""); |
| 618 | else |
| 619 | sprintf(new_targets, "%s %s", mode, |
| 620 | env_targets ? env_targets : ""); |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 621 | |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 622 | env_set("boot_targets", new_targets); |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 623 | |
Michal Simek | 29b9b71 | 2018-05-17 14:06:06 +0200 | [diff] [blame] | 624 | reset_reason(); |
| 625 | |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 626 | return 0; |
| 627 | } |
Siva Durga Prasad Paladugu | 650e0a3 | 2015-08-04 13:01:05 +0530 | [diff] [blame] | 628 | |
| 629 | int checkboard(void) |
| 630 | { |
Michal Simek | 47ce936 | 2016-01-25 11:04:21 +0100 | [diff] [blame] | 631 | puts("Board: Xilinx ZynqMP\n"); |
Siva Durga Prasad Paladugu | 650e0a3 | 2015-08-04 13:01:05 +0530 | [diff] [blame] | 632 | return 0; |
| 633 | } |