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