Michal Simek | 84c7204 | 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 | 679b994 | 2015-09-30 17:26:55 +0200 | [diff] [blame] | 9 | #include <sata.h> |
Michal Simek | 6fe6f13 | 2015-07-23 13:27:40 +0200 | [diff] [blame] | 10 | #include <ahci.h> |
| 11 | #include <scsi.h> |
Michal Simek | b72894f | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 12 | #include <malloc.h> |
Michal Simek | 0785dfd | 2015-11-05 08:34:35 +0100 | [diff] [blame] | 13 | #include <asm/arch/clk.h> |
Michal Simek | 84c7204 | 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 | 16fa00a | 2015-08-04 13:03:26 +0530 | [diff] [blame] | 17 | #include <usb.h> |
| 18 | #include <dwc3-uboot.h> |
Michal Simek | 47e60cb | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 19 | #include <zynqmppl.h> |
Michal Simek | 6919b4b | 2016-04-22 11:48:49 +0200 | [diff] [blame] | 20 | #include <i2c.h> |
Michal Simek | 9feff38 | 2016-09-01 11:16:40 +0200 | [diff] [blame] | 21 | #include <g_dnl.h> |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 22 | |
| 23 | DECLARE_GLOBAL_DATA_PTR; |
| 24 | |
Michal Simek | 47e60cb | 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 { |
| 30 | uint32_t id; |
| 31 | char *name; |
| 32 | } zynqmp_devices[] = { |
| 33 | { |
| 34 | .id = 0x10, |
| 35 | .name = "3eg", |
| 36 | }, |
| 37 | { |
| 38 | .id = 0x11, |
| 39 | .name = "2eg", |
| 40 | }, |
| 41 | { |
| 42 | .id = 0x20, |
| 43 | .name = "5ev", |
| 44 | }, |
| 45 | { |
| 46 | .id = 0x21, |
| 47 | .name = "4ev", |
| 48 | }, |
| 49 | { |
| 50 | .id = 0x30, |
| 51 | .name = "7ev", |
| 52 | }, |
| 53 | { |
| 54 | .id = 0x38, |
| 55 | .name = "9eg", |
| 56 | }, |
| 57 | { |
| 58 | .id = 0x39, |
| 59 | .name = "6eg", |
| 60 | }, |
| 61 | { |
| 62 | .id = 0x40, |
| 63 | .name = "11eg", |
| 64 | }, |
| 65 | { |
| 66 | .id = 0x50, |
| 67 | .name = "15eg", |
| 68 | }, |
| 69 | { |
| 70 | .id = 0x58, |
| 71 | .name = "19eg", |
| 72 | }, |
| 73 | { |
| 74 | .id = 0x59, |
| 75 | .name = "17eg", |
| 76 | }, |
| 77 | }; |
| 78 | |
| 79 | static int chip_id(void) |
| 80 | { |
| 81 | struct pt_regs regs; |
| 82 | regs.regs[0] = ZYNQMP_SIP_SVC_CSU_DMA_CHIPID; |
| 83 | regs.regs[1] = 0; |
| 84 | regs.regs[2] = 0; |
| 85 | regs.regs[3] = 0; |
| 86 | |
| 87 | smc_call(®s); |
| 88 | |
Soren Brinkmann | 0cba6ab | 2016-09-29 11:44:41 -0700 | [diff] [blame] | 89 | /* |
| 90 | * SMC returns: |
| 91 | * regs[0][31:0] = status of the operation |
| 92 | * regs[0][63:32] = CSU.IDCODE register |
| 93 | * regs[1][31:0] = CSU.version register |
| 94 | */ |
| 95 | regs.regs[0] = upper_32_bits(regs.regs[0]); |
| 96 | regs.regs[0] &= ZYNQMP_CSU_IDCODE_DEVICE_CODE_MASK | |
| 97 | ZYNQMP_CSU_IDCODE_SVD_MASK; |
| 98 | regs.regs[0] >>= ZYNQMP_CSU_IDCODE_SVD_SHIFT; |
| 99 | |
Michal Simek | 47e60cb | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 100 | return regs.regs[0]; |
| 101 | } |
| 102 | |
| 103 | static char *zynqmp_get_silicon_idcode_name(void) |
| 104 | { |
| 105 | uint32_t i, id; |
| 106 | |
| 107 | id = chip_id(); |
| 108 | for (i = 0; i < ARRAY_SIZE(zynqmp_devices); i++) { |
| 109 | if (zynqmp_devices[i].id == id) |
| 110 | return zynqmp_devices[i].name; |
| 111 | } |
| 112 | return "unknown"; |
| 113 | } |
| 114 | #endif |
| 115 | |
Michal Simek | fb4000e | 2017-02-07 14:32:26 +0100 | [diff] [blame] | 116 | int board_early_init_f(void) |
| 117 | { |
| 118 | #if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_CLK_ZYNQMP) |
| 119 | zynqmp_pmufw_version(); |
| 120 | #endif |
Michal Simek | 55de092 | 2017-07-12 13:08:41 +0200 | [diff] [blame] | 121 | |
Michal Simek | fd1b635 | 2017-07-12 13:21:27 +0200 | [diff] [blame] | 122 | #if defined(CONFIG_SPL_BUILD) || defined(CONFIG_ZYNQMP_PSU_INIT_ENABLED) |
Michal Simek | 55de092 | 2017-07-12 13:08:41 +0200 | [diff] [blame] | 123 | psu_init(); |
| 124 | #endif |
| 125 | |
Michal Simek | fb4000e | 2017-02-07 14:32:26 +0100 | [diff] [blame] | 126 | return 0; |
| 127 | } |
| 128 | |
Michal Simek | 47e60cb | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 129 | #define ZYNQMP_VERSION_SIZE 9 |
| 130 | |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 131 | int board_init(void) |
| 132 | { |
Michal Simek | a0736ef | 2015-06-22 14:31:06 +0200 | [diff] [blame] | 133 | printf("EL Level:\tEL%d\n", current_el()); |
| 134 | |
Michal Simek | 47e60cb | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 135 | #if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \ |
| 136 | !defined(CONFIG_SPL_BUILD) || (defined(CONFIG_SPL_FPGA_SUPPORT) && \ |
| 137 | defined(CONFIG_SPL_BUILD)) |
| 138 | if (current_el() != 3) { |
| 139 | static char version[ZYNQMP_VERSION_SIZE]; |
| 140 | |
| 141 | strncat(version, "xczu", ZYNQMP_VERSION_SIZE); |
| 142 | zynqmppl.name = strncat(version, |
| 143 | zynqmp_get_silicon_idcode_name(), |
| 144 | ZYNQMP_VERSION_SIZE); |
| 145 | printf("Chip ID:\t%s\n", zynqmppl.name); |
| 146 | fpga_init(); |
| 147 | fpga_add(fpga_xilinx, &zynqmppl); |
| 148 | } |
| 149 | #endif |
| 150 | |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 151 | return 0; |
| 152 | } |
| 153 | |
| 154 | int board_early_init_r(void) |
| 155 | { |
| 156 | u32 val; |
| 157 | |
Michal Simek | 90a35db | 2017-07-12 10:32:18 +0200 | [diff] [blame^] | 158 | val = readl(&crlapb_base->timestamp_ref_ctrl); |
| 159 | val &= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT; |
| 160 | |
| 161 | if (current_el() == 3 && !val) { |
Michal Simek | 0785dfd | 2015-11-05 08:34:35 +0100 | [diff] [blame] | 162 | val = readl(&crlapb_base->timestamp_ref_ctrl); |
| 163 | val |= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT; |
| 164 | writel(val, &crlapb_base->timestamp_ref_ctrl); |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 165 | |
Michal Simek | 0785dfd | 2015-11-05 08:34:35 +0100 | [diff] [blame] | 166 | /* Program freq register in System counter */ |
| 167 | writel(zynqmp_get_system_timer_freq(), |
| 168 | &iou_scntr_secure->base_frequency_id_register); |
| 169 | /* And enable system counter */ |
| 170 | writel(ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_EN, |
| 171 | &iou_scntr_secure->counter_control_register); |
| 172 | } |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 173 | /* Program freq register in System counter and enable system counter */ |
| 174 | writel(gd->cpu_clk, &iou_scntr->base_frequency_id_register); |
| 175 | writel(ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_HDBG | |
| 176 | ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_EN, |
| 177 | &iou_scntr->counter_control_register); |
| 178 | |
| 179 | return 0; |
| 180 | } |
| 181 | |
Michal Simek | 6919b4b | 2016-04-22 11:48:49 +0200 | [diff] [blame] | 182 | int zynq_board_read_rom_ethaddr(unsigned char *ethaddr) |
| 183 | { |
| 184 | #if defined(CONFIG_ZYNQ_GEM_EEPROM_ADDR) && \ |
| 185 | defined(CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET) && \ |
| 186 | defined(CONFIG_ZYNQ_EEPROM_BUS) |
| 187 | i2c_set_bus_num(CONFIG_ZYNQ_EEPROM_BUS); |
| 188 | |
| 189 | if (eeprom_read(CONFIG_ZYNQ_GEM_EEPROM_ADDR, |
| 190 | CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET, |
| 191 | ethaddr, 6)) |
| 192 | printf("I2C EEPROM MAC address read failed\n"); |
| 193 | #endif |
| 194 | |
| 195 | return 0; |
| 196 | } |
| 197 | |
Michal Simek | 8d59d7f | 2016-02-08 09:34:53 +0100 | [diff] [blame] | 198 | #if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE) |
Simon Glass | 76b00ac | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 199 | int dram_init_banksize(void) |
Tom Rini | 361a879 | 2016-12-09 07:56:54 -0500 | [diff] [blame] | 200 | { |
Nathan Rossi | 950f86c | 2016-12-19 00:03:34 +1000 | [diff] [blame] | 201 | fdtdec_setup_memory_banksize(); |
Simon Glass | 76b00ac | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 202 | |
| 203 | return 0; |
Michal Simek | 8d59d7f | 2016-02-08 09:34:53 +0100 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | int dram_init(void) |
| 207 | { |
Nathan Rossi | 950f86c | 2016-12-19 00:03:34 +1000 | [diff] [blame] | 208 | if (fdtdec_setup_memory_size() != 0) |
| 209 | return -EINVAL; |
Michal Simek | 8d59d7f | 2016-02-08 09:34:53 +0100 | [diff] [blame] | 210 | |
| 211 | return 0; |
| 212 | } |
| 213 | #else |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 214 | int dram_init(void) |
| 215 | { |
| 216 | gd->ram_size = CONFIG_SYS_SDRAM_SIZE; |
| 217 | |
| 218 | return 0; |
| 219 | } |
Michal Simek | 8d59d7f | 2016-02-08 09:34:53 +0100 | [diff] [blame] | 220 | #endif |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 221 | |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 222 | void reset_cpu(ulong addr) |
| 223 | { |
| 224 | } |
| 225 | |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 226 | int board_late_init(void) |
| 227 | { |
| 228 | u32 reg = 0; |
| 229 | u8 bootmode; |
Michal Simek | b72894f | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 230 | const char *mode; |
| 231 | char *new_targets; |
| 232 | |
| 233 | if (!(gd->flags & GD_FLG_ENV_DEFAULT)) { |
| 234 | debug("Saved variables - Skipping\n"); |
| 235 | return 0; |
| 236 | } |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 237 | |
| 238 | reg = readl(&crlapb_base->boot_mode); |
Michal Simek | 47359a0 | 2016-10-25 11:43:02 +0200 | [diff] [blame] | 239 | if (reg >> BOOT_MODE_ALT_SHIFT) |
| 240 | reg >>= BOOT_MODE_ALT_SHIFT; |
| 241 | |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 242 | bootmode = reg & BOOT_MODES_MASK; |
| 243 | |
Michal Simek | fb90917 | 2015-09-20 17:20:42 +0200 | [diff] [blame] | 244 | puts("Bootmode: "); |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 245 | switch (bootmode) { |
Michal Simek | d58fc12 | 2016-08-19 14:14:52 +0200 | [diff] [blame] | 246 | case USB_MODE: |
| 247 | puts("USB_MODE\n"); |
| 248 | mode = "usb"; |
| 249 | break; |
Siva Durga Prasad Paladugu | 0a5bcc8 | 2015-03-13 11:10:26 +0530 | [diff] [blame] | 250 | case JTAG_MODE: |
Michal Simek | fb90917 | 2015-09-20 17:20:42 +0200 | [diff] [blame] | 251 | puts("JTAG_MODE\n"); |
Michal Simek | b72894f | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 252 | mode = "pxe dhcp"; |
Siva Durga Prasad Paladugu | 0a5bcc8 | 2015-03-13 11:10:26 +0530 | [diff] [blame] | 253 | break; |
| 254 | case QSPI_MODE_24BIT: |
| 255 | case QSPI_MODE_32BIT: |
Michal Simek | b72894f | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 256 | mode = "qspi0"; |
Michal Simek | fb90917 | 2015-09-20 17:20:42 +0200 | [diff] [blame] | 257 | puts("QSPI_MODE\n"); |
Siva Durga Prasad Paladugu | 0a5bcc8 | 2015-03-13 11:10:26 +0530 | [diff] [blame] | 258 | break; |
Michal Simek | 39c56f5 | 2015-04-15 15:02:28 +0200 | [diff] [blame] | 259 | case EMMC_MODE: |
Michal Simek | 78678fe | 2015-10-05 15:59:38 +0200 | [diff] [blame] | 260 | puts("EMMC_MODE\n"); |
Michal Simek | b72894f | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 261 | mode = "mmc0"; |
Michal Simek | 78678fe | 2015-10-05 15:59:38 +0200 | [diff] [blame] | 262 | break; |
| 263 | case SD_MODE: |
Michal Simek | fb90917 | 2015-09-20 17:20:42 +0200 | [diff] [blame] | 264 | puts("SD_MODE\n"); |
Michal Simek | b72894f | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 265 | mode = "mmc0"; |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 266 | break; |
Siva Durga Prasad Paladugu | e199227 | 2016-09-21 11:45:05 +0530 | [diff] [blame] | 267 | case SD1_LSHFT_MODE: |
| 268 | puts("LVL_SHFT_"); |
| 269 | /* fall through */ |
Michal Simek | af813ac | 2015-10-05 10:51:12 +0200 | [diff] [blame] | 270 | case SD_MODE1: |
Michal Simek | fb90917 | 2015-09-20 17:20:42 +0200 | [diff] [blame] | 271 | puts("SD_MODE1\n"); |
Michal Simek | 2d9925b | 2015-11-06 10:22:37 +0100 | [diff] [blame] | 272 | #if defined(CONFIG_ZYNQ_SDHCI0) && defined(CONFIG_ZYNQ_SDHCI1) |
Michal Simek | b72894f | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 273 | mode = "mmc1"; |
| 274 | #else |
| 275 | mode = "mmc0"; |
Michal Simek | 2d9925b | 2015-11-06 10:22:37 +0100 | [diff] [blame] | 276 | #endif |
Michal Simek | af813ac | 2015-10-05 10:51:12 +0200 | [diff] [blame] | 277 | break; |
| 278 | case NAND_MODE: |
Michal Simek | fb90917 | 2015-09-20 17:20:42 +0200 | [diff] [blame] | 279 | puts("NAND_MODE\n"); |
Michal Simek | b72894f | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 280 | mode = "nand0"; |
Michal Simek | af813ac | 2015-10-05 10:51:12 +0200 | [diff] [blame] | 281 | break; |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 282 | default: |
Michal Simek | b72894f | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 283 | mode = ""; |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 284 | printf("Invalid Boot Mode:0x%x\n", bootmode); |
| 285 | break; |
| 286 | } |
| 287 | |
Michal Simek | b72894f | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 288 | /* |
| 289 | * One terminating char + one byte for space between mode |
| 290 | * and default boot_targets |
| 291 | */ |
| 292 | new_targets = calloc(1, strlen(mode) + |
| 293 | strlen(getenv("boot_targets")) + 2); |
| 294 | |
| 295 | sprintf(new_targets, "%s %s", mode, getenv("boot_targets")); |
| 296 | setenv("boot_targets", new_targets); |
| 297 | |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 298 | return 0; |
| 299 | } |
Siva Durga Prasad Paladugu | 84696ff | 2015-08-04 13:01:05 +0530 | [diff] [blame] | 300 | |
| 301 | int checkboard(void) |
| 302 | { |
Michal Simek | 5af0855 | 2016-01-25 11:04:21 +0100 | [diff] [blame] | 303 | puts("Board: Xilinx ZynqMP\n"); |
Siva Durga Prasad Paladugu | 84696ff | 2015-08-04 13:01:05 +0530 | [diff] [blame] | 304 | return 0; |
| 305 | } |
Siva Durga Prasad Paladugu | 16fa00a | 2015-08-04 13:03:26 +0530 | [diff] [blame] | 306 | |
| 307 | #ifdef CONFIG_USB_DWC3 |
Michal Simek | 275bd6d | 2016-08-08 10:11:26 +0200 | [diff] [blame] | 308 | static struct dwc3_device dwc3_device_data0 = { |
Siva Durga Prasad Paladugu | 16fa00a | 2015-08-04 13:03:26 +0530 | [diff] [blame] | 309 | .maximum_speed = USB_SPEED_HIGH, |
| 310 | .base = ZYNQMP_USB0_XHCI_BASEADDR, |
| 311 | .dr_mode = USB_DR_MODE_PERIPHERAL, |
| 312 | .index = 0, |
| 313 | }; |
| 314 | |
Michal Simek | 275bd6d | 2016-08-08 10:11:26 +0200 | [diff] [blame] | 315 | static struct dwc3_device dwc3_device_data1 = { |
| 316 | .maximum_speed = USB_SPEED_HIGH, |
| 317 | .base = ZYNQMP_USB1_XHCI_BASEADDR, |
| 318 | .dr_mode = USB_DR_MODE_PERIPHERAL, |
| 319 | .index = 1, |
| 320 | }; |
| 321 | |
Michal Simek | 9feff38 | 2016-09-01 11:16:40 +0200 | [diff] [blame] | 322 | int usb_gadget_handle_interrupts(int index) |
Siva Durga Prasad Paladugu | 16fa00a | 2015-08-04 13:03:26 +0530 | [diff] [blame] | 323 | { |
Michal Simek | 9feff38 | 2016-09-01 11:16:40 +0200 | [diff] [blame] | 324 | dwc3_uboot_handle_interrupt(index); |
Siva Durga Prasad Paladugu | 16fa00a | 2015-08-04 13:03:26 +0530 | [diff] [blame] | 325 | return 0; |
| 326 | } |
| 327 | |
| 328 | int board_usb_init(int index, enum usb_init_type init) |
| 329 | { |
Michal Simek | 275bd6d | 2016-08-08 10:11:26 +0200 | [diff] [blame] | 330 | debug("%s: index %x\n", __func__, index); |
| 331 | |
Michal Simek | 8ecd50c | 2016-09-01 11:27:32 +0200 | [diff] [blame] | 332 | #if defined(CONFIG_USB_GADGET_DOWNLOAD) |
| 333 | g_dnl_set_serialnumber(CONFIG_SYS_CONFIG_NAME); |
| 334 | #endif |
| 335 | |
Michal Simek | 275bd6d | 2016-08-08 10:11:26 +0200 | [diff] [blame] | 336 | switch (index) { |
| 337 | case 0: |
| 338 | return dwc3_uboot_init(&dwc3_device_data0); |
| 339 | case 1: |
| 340 | return dwc3_uboot_init(&dwc3_device_data1); |
| 341 | }; |
| 342 | |
| 343 | return -1; |
Siva Durga Prasad Paladugu | 16fa00a | 2015-08-04 13:03:26 +0530 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | int board_usb_cleanup(int index, enum usb_init_type init) |
| 347 | { |
| 348 | dwc3_uboot_exit(index); |
| 349 | return 0; |
| 350 | } |
| 351 | #endif |