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