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> |
| 9 | #include <netdev.h> |
Michal Simek | 6fe6f13 | 2015-07-23 13:27:40 +0200 | [diff] [blame] | 10 | #include <ahci.h> |
| 11 | #include <scsi.h> |
Michal Simek | 0785dfd | 2015-11-05 08:34:35 +0100 | [diff] [blame] | 12 | #include <asm/arch/clk.h> |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 13 | #include <asm/arch/hardware.h> |
| 14 | #include <asm/arch/sys_proto.h> |
| 15 | #include <asm/io.h> |
Siva Durga Prasad Paladugu | 16fa00a | 2015-08-04 13:03:26 +0530 | [diff] [blame] | 16 | #include <usb.h> |
| 17 | #include <dwc3-uboot.h> |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 18 | |
| 19 | DECLARE_GLOBAL_DATA_PTR; |
| 20 | |
| 21 | int board_init(void) |
| 22 | { |
Michal Simek | a0736ef | 2015-06-22 14:31:06 +0200 | [diff] [blame] | 23 | printf("EL Level:\tEL%d\n", current_el()); |
| 24 | |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 25 | return 0; |
| 26 | } |
| 27 | |
| 28 | int board_early_init_r(void) |
| 29 | { |
| 30 | u32 val; |
| 31 | |
Michal Simek | 0785dfd | 2015-11-05 08:34:35 +0100 | [diff] [blame] | 32 | if (current_el() == 3) { |
| 33 | val = readl(&crlapb_base->timestamp_ref_ctrl); |
| 34 | val |= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT; |
| 35 | writel(val, &crlapb_base->timestamp_ref_ctrl); |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 36 | |
Michal Simek | 0785dfd | 2015-11-05 08:34:35 +0100 | [diff] [blame] | 37 | /* Program freq register in System counter */ |
| 38 | writel(zynqmp_get_system_timer_freq(), |
| 39 | &iou_scntr_secure->base_frequency_id_register); |
| 40 | /* And enable system counter */ |
| 41 | writel(ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_EN, |
| 42 | &iou_scntr_secure->counter_control_register); |
| 43 | } |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 44 | /* Program freq register in System counter and enable system counter */ |
| 45 | writel(gd->cpu_clk, &iou_scntr->base_frequency_id_register); |
| 46 | writel(ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_HDBG | |
| 47 | ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_EN, |
| 48 | &iou_scntr->counter_control_register); |
| 49 | |
| 50 | return 0; |
| 51 | } |
| 52 | |
Michal Simek | 8d59d7f | 2016-02-08 09:34:53 +0100 | [diff] [blame^] | 53 | #if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE) |
| 54 | /* |
| 55 | * fdt_get_reg - Fill buffer by information from DT |
| 56 | */ |
| 57 | static phys_size_t fdt_get_reg(const void *fdt, int nodeoffset, void *buf, |
| 58 | const u32 *cell, int n) |
| 59 | { |
| 60 | int i = 0, b, banks; |
| 61 | int parent_offset = fdt_parent_offset(fdt, nodeoffset); |
| 62 | int address_cells = fdt_address_cells(fdt, parent_offset); |
| 63 | int size_cells = fdt_size_cells(fdt, parent_offset); |
| 64 | char *p = buf; |
| 65 | phys_addr_t val; |
| 66 | phys_size_t vals; |
| 67 | |
| 68 | debug("%s: addr_cells=%x, size_cell=%x, buf=%p, cell=%p\n", |
| 69 | __func__, address_cells, size_cells, buf, cell); |
| 70 | |
| 71 | /* Check memory bank setup */ |
| 72 | banks = n % (address_cells + size_cells); |
| 73 | if (banks) |
| 74 | panic("Incorrect memory setup cells=%d, ac=%d, sc=%d\n", |
| 75 | n, address_cells, size_cells); |
| 76 | |
| 77 | banks = n / (address_cells + size_cells); |
| 78 | |
| 79 | for (b = 0; b < banks; b++) { |
| 80 | debug("%s: Bank #%d:\n", __func__, b); |
| 81 | if (address_cells == 2) { |
| 82 | val = cell[i + 1]; |
| 83 | val <<= 32; |
| 84 | val |= cell[i]; |
| 85 | val = fdt64_to_cpu(val); |
| 86 | debug("%s: addr64=%llx, ptr=%p, cell=%p\n", |
| 87 | __func__, val, p, &cell[i]); |
| 88 | *(phys_addr_t *)p = val; |
| 89 | } else { |
| 90 | debug("%s: addr32=%x, ptr=%p\n", |
| 91 | __func__, fdt32_to_cpu(cell[i]), p); |
| 92 | *(phys_addr_t *)p = fdt32_to_cpu(cell[i]); |
| 93 | } |
| 94 | p += sizeof(phys_addr_t); |
| 95 | i += address_cells; |
| 96 | |
| 97 | debug("%s: pa=%p, i=%x, size=%zu\n", __func__, p, i, |
| 98 | sizeof(phys_addr_t)); |
| 99 | |
| 100 | if (size_cells == 2) { |
| 101 | vals = cell[i + 1]; |
| 102 | vals <<= 32; |
| 103 | vals |= cell[i]; |
| 104 | vals = fdt64_to_cpu(vals); |
| 105 | |
| 106 | debug("%s: size64=%llx, ptr=%p, cell=%p\n", |
| 107 | __func__, vals, p, &cell[i]); |
| 108 | *(phys_size_t *)p = vals; |
| 109 | } else { |
| 110 | debug("%s: size32=%x, ptr=%p\n", |
| 111 | __func__, fdt32_to_cpu(cell[i]), p); |
| 112 | *(phys_size_t *)p = fdt32_to_cpu(cell[i]); |
| 113 | } |
| 114 | p += sizeof(phys_size_t); |
| 115 | i += size_cells; |
| 116 | |
| 117 | debug("%s: ps=%p, i=%x, size=%zu\n", |
| 118 | __func__, p, i, sizeof(phys_size_t)); |
| 119 | } |
| 120 | |
| 121 | /* Return the first address size */ |
| 122 | return *(phys_size_t *)((char *)buf + sizeof(phys_addr_t)); |
| 123 | } |
| 124 | |
| 125 | #define FDT_REG_SIZE sizeof(u32) |
| 126 | /* Temp location for sharing data for storing */ |
| 127 | /* Up to 64-bit address + 64-bit size */ |
| 128 | static u8 tmp[CONFIG_NR_DRAM_BANKS * 16]; |
| 129 | |
| 130 | void dram_init_banksize(void) |
| 131 | { |
| 132 | int bank; |
| 133 | |
| 134 | memcpy(&gd->bd->bi_dram[0], &tmp, sizeof(tmp)); |
| 135 | |
| 136 | for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) { |
| 137 | debug("Bank #%d: start %llx\n", bank, |
| 138 | (unsigned long long)gd->bd->bi_dram[bank].start); |
| 139 | debug("Bank #%d: size %llx\n", bank, |
| 140 | (unsigned long long)gd->bd->bi_dram[bank].size); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | int dram_init(void) |
| 145 | { |
| 146 | int node, len; |
| 147 | const void *blob = gd->fdt_blob; |
| 148 | const u32 *cell; |
| 149 | |
| 150 | memset(&tmp, 0, sizeof(tmp)); |
| 151 | |
| 152 | /* find or create "/memory" node. */ |
| 153 | node = fdt_subnode_offset(blob, 0, "memory"); |
| 154 | if (node < 0) { |
| 155 | printf("%s: Can't get memory node\n", __func__); |
| 156 | return node; |
| 157 | } |
| 158 | |
| 159 | /* Get pointer to cells and lenght of it */ |
| 160 | cell = fdt_getprop(blob, node, "reg", &len); |
| 161 | if (!cell) { |
| 162 | printf("%s: Can't get reg property\n", __func__); |
| 163 | return -1; |
| 164 | } |
| 165 | |
| 166 | gd->ram_size = fdt_get_reg(blob, node, &tmp, cell, len / FDT_REG_SIZE); |
| 167 | |
| 168 | debug("%s: Initial DRAM size %llx\n", __func__, gd->ram_size); |
| 169 | |
| 170 | return 0; |
| 171 | } |
| 172 | #else |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 173 | int dram_init(void) |
| 174 | { |
| 175 | gd->ram_size = CONFIG_SYS_SDRAM_SIZE; |
| 176 | |
| 177 | return 0; |
| 178 | } |
Michal Simek | 8d59d7f | 2016-02-08 09:34:53 +0100 | [diff] [blame^] | 179 | #endif |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 180 | |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 181 | void reset_cpu(ulong addr) |
| 182 | { |
| 183 | } |
| 184 | |
Michal Simek | 6fe6f13 | 2015-07-23 13:27:40 +0200 | [diff] [blame] | 185 | #ifdef CONFIG_SCSI_AHCI_PLAT |
| 186 | void scsi_init(void) |
| 187 | { |
| 188 | ahci_init((void __iomem *)ZYNQMP_SATA_BASEADDR); |
| 189 | scsi_scan(1); |
| 190 | } |
| 191 | #endif |
| 192 | |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 193 | int board_late_init(void) |
| 194 | { |
| 195 | u32 reg = 0; |
| 196 | u8 bootmode; |
| 197 | |
| 198 | reg = readl(&crlapb_base->boot_mode); |
| 199 | bootmode = reg & BOOT_MODES_MASK; |
| 200 | |
Michal Simek | fb90917 | 2015-09-20 17:20:42 +0200 | [diff] [blame] | 201 | puts("Bootmode: "); |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 202 | switch (bootmode) { |
Siva Durga Prasad Paladugu | 0a5bcc8 | 2015-03-13 11:10:26 +0530 | [diff] [blame] | 203 | case JTAG_MODE: |
Michal Simek | fb90917 | 2015-09-20 17:20:42 +0200 | [diff] [blame] | 204 | puts("JTAG_MODE\n"); |
| 205 | setenv("modeboot", "jtagboot"); |
Siva Durga Prasad Paladugu | 0a5bcc8 | 2015-03-13 11:10:26 +0530 | [diff] [blame] | 206 | break; |
| 207 | case QSPI_MODE_24BIT: |
| 208 | case QSPI_MODE_32BIT: |
| 209 | setenv("modeboot", "qspiboot"); |
Michal Simek | fb90917 | 2015-09-20 17:20:42 +0200 | [diff] [blame] | 210 | puts("QSPI_MODE\n"); |
Siva Durga Prasad Paladugu | 0a5bcc8 | 2015-03-13 11:10:26 +0530 | [diff] [blame] | 211 | break; |
Michal Simek | 39c56f5 | 2015-04-15 15:02:28 +0200 | [diff] [blame] | 212 | case EMMC_MODE: |
Michal Simek | 78678fe | 2015-10-05 15:59:38 +0200 | [diff] [blame] | 213 | puts("EMMC_MODE\n"); |
| 214 | setenv("modeboot", "sdboot"); |
| 215 | break; |
| 216 | case SD_MODE: |
Michal Simek | fb90917 | 2015-09-20 17:20:42 +0200 | [diff] [blame] | 217 | puts("SD_MODE\n"); |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 218 | setenv("modeboot", "sdboot"); |
| 219 | break; |
Michal Simek | af813ac | 2015-10-05 10:51:12 +0200 | [diff] [blame] | 220 | case SD_MODE1: |
Michal Simek | fb90917 | 2015-09-20 17:20:42 +0200 | [diff] [blame] | 221 | puts("SD_MODE1\n"); |
Michal Simek | 2d9925b | 2015-11-06 10:22:37 +0100 | [diff] [blame] | 222 | #if defined(CONFIG_ZYNQ_SDHCI0) && defined(CONFIG_ZYNQ_SDHCI1) |
| 223 | setenv("sdbootdev", "1"); |
| 224 | #endif |
| 225 | setenv("modeboot", "sdboot"); |
Michal Simek | af813ac | 2015-10-05 10:51:12 +0200 | [diff] [blame] | 226 | break; |
| 227 | case NAND_MODE: |
Michal Simek | fb90917 | 2015-09-20 17:20:42 +0200 | [diff] [blame] | 228 | puts("NAND_MODE\n"); |
Michal Simek | af813ac | 2015-10-05 10:51:12 +0200 | [diff] [blame] | 229 | setenv("modeboot", "nandboot"); |
| 230 | break; |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 231 | default: |
| 232 | printf("Invalid Boot Mode:0x%x\n", bootmode); |
| 233 | break; |
| 234 | } |
| 235 | |
| 236 | return 0; |
| 237 | } |
Siva Durga Prasad Paladugu | 84696ff | 2015-08-04 13:01:05 +0530 | [diff] [blame] | 238 | |
| 239 | int checkboard(void) |
| 240 | { |
Michal Simek | 5af0855 | 2016-01-25 11:04:21 +0100 | [diff] [blame] | 241 | puts("Board: Xilinx ZynqMP\n"); |
Siva Durga Prasad Paladugu | 84696ff | 2015-08-04 13:01:05 +0530 | [diff] [blame] | 242 | return 0; |
| 243 | } |
Siva Durga Prasad Paladugu | 16fa00a | 2015-08-04 13:03:26 +0530 | [diff] [blame] | 244 | |
| 245 | #ifdef CONFIG_USB_DWC3 |
| 246 | static struct dwc3_device dwc3_device_data = { |
| 247 | .maximum_speed = USB_SPEED_HIGH, |
| 248 | .base = ZYNQMP_USB0_XHCI_BASEADDR, |
| 249 | .dr_mode = USB_DR_MODE_PERIPHERAL, |
| 250 | .index = 0, |
| 251 | }; |
| 252 | |
| 253 | int usb_gadget_handle_interrupts(void) |
| 254 | { |
| 255 | dwc3_uboot_handle_interrupt(0); |
| 256 | return 0; |
| 257 | } |
| 258 | |
| 259 | int board_usb_init(int index, enum usb_init_type init) |
| 260 | { |
| 261 | return dwc3_uboot_init(&dwc3_device_data); |
| 262 | } |
| 263 | |
| 264 | int board_usb_cleanup(int index, enum usb_init_type init) |
| 265 | { |
| 266 | dwc3_uboot_exit(index); |
| 267 | return 0; |
| 268 | } |
| 269 | #endif |