Dinh Nguyen | 7775440 | 2012-10-04 06:46:02 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 Altera Corporation <www.altera.com> |
| 3 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0+ |
Dinh Nguyen | 7775440 | 2012-10-04 06:46:02 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <asm/io.h> |
Pavel Machek | 230fe9b | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 9 | #include <altera.h> |
Pavel Machek | 99b9710 | 2014-07-14 14:14:17 +0200 | [diff] [blame] | 10 | #include <miiphy.h> |
| 11 | #include <netdev.h> |
Stefan Roese | d0e932d | 2014-12-19 13:49:10 +0100 | [diff] [blame] | 12 | #include <watchdog.h> |
Pavel Machek | de6da92 | 2014-09-09 14:03:28 +0200 | [diff] [blame] | 13 | #include <asm/arch/reset_manager.h> |
Pavel Machek | 45d6e67 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 14 | #include <asm/arch/system_manager.h> |
Pavel Machek | 4e73686 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 15 | #include <asm/arch/dwmmc.h> |
Marek Vasut | 60d804c | 2014-09-15 03:58:22 +0200 | [diff] [blame] | 16 | #include <asm/arch/nic301.h> |
Pavel Machek | 13e81d4 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 17 | #include <asm/arch/scu.h> |
Marek Vasut | 60d804c | 2014-09-15 03:58:22 +0200 | [diff] [blame] | 18 | #include <asm/pl310.h> |
Dinh Nguyen | 7775440 | 2012-10-04 06:46:02 +0000 | [diff] [blame] | 19 | |
| 20 | DECLARE_GLOBAL_DATA_PTR; |
| 21 | |
Marek Vasut | 60d804c | 2014-09-15 03:58:22 +0200 | [diff] [blame] | 22 | static struct pl310_regs *const pl310 = |
| 23 | (struct pl310_regs *)CONFIG_SYS_PL310_BASE; |
Pavel Machek | 45d6e67 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 24 | static struct socfpga_system_manager *sysmgr_regs = |
| 25 | (struct socfpga_system_manager *)SOCFPGA_SYSMGR_ADDRESS; |
Marek Vasut | 7249faf | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 26 | static struct socfpga_reset_manager *reset_manager_base = |
| 27 | (struct socfpga_reset_manager *)SOCFPGA_RSTMGR_ADDRESS; |
Marek Vasut | 60d804c | 2014-09-15 03:58:22 +0200 | [diff] [blame] | 28 | static struct nic301_registers *nic301_regs = |
| 29 | (struct nic301_registers *)SOCFPGA_L3REGS_ADDRESS; |
Pavel Machek | 13e81d4 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 30 | static struct scu_registers *scu_regs = |
| 31 | (struct scu_registers *)SOCFPGA_MPUSCU_ADDRESS; |
Pavel Machek | 45d6e67 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 32 | |
Dinh Nguyen | 7775440 | 2012-10-04 06:46:02 +0000 | [diff] [blame] | 33 | int dram_init(void) |
| 34 | { |
| 35 | gd->ram_size = get_ram_size((long *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE); |
| 36 | return 0; |
| 37 | } |
Chin Liang See | 23f23f2 | 2014-06-10 02:23:45 -0500 | [diff] [blame] | 38 | |
Marek Vasut | 4ab333b | 2014-09-21 13:57:40 +0200 | [diff] [blame] | 39 | void enable_caches(void) |
| 40 | { |
| 41 | #ifndef CONFIG_SYS_ICACHE_OFF |
| 42 | icache_enable(); |
| 43 | #endif |
| 44 | #ifndef CONFIG_SYS_DCACHE_OFF |
| 45 | dcache_enable(); |
| 46 | #endif |
| 47 | } |
| 48 | |
Pavel Machek | 45d6e67 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 49 | /* |
| 50 | * DesignWare Ethernet initialization |
| 51 | */ |
Simon Glass | ef48f6d | 2015-04-05 16:07:34 -0600 | [diff] [blame] | 52 | #ifdef CONFIG_ETH_DESIGNWARE |
Pavel Machek | 45d6e67 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 53 | int cpu_eth_init(bd_t *bis) |
| 54 | { |
| 55 | #if CONFIG_EMAC_BASE == SOCFPGA_EMAC0_ADDRESS |
| 56 | const int physhift = SYSMGR_EMACGRP_CTRL_PHYSEL0_LSB; |
Marek Vasut | a71df7a | 2015-07-09 02:51:56 +0200 | [diff] [blame] | 57 | const u32 reset = SOCFPGA_RESET(EMAC0); |
Pavel Machek | 45d6e67 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 58 | #elif CONFIG_EMAC_BASE == SOCFPGA_EMAC1_ADDRESS |
| 59 | const int physhift = SYSMGR_EMACGRP_CTRL_PHYSEL1_LSB; |
Marek Vasut | a71df7a | 2015-07-09 02:51:56 +0200 | [diff] [blame] | 60 | const u32 reset = SOCFPGA_RESET(EMAC1); |
Pavel Machek | 45d6e67 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 61 | #else |
| 62 | #error "Incorrect CONFIG_EMAC_BASE value!" |
| 63 | #endif |
| 64 | |
| 65 | /* Initialize EMAC. This needs to be done at least once per boot. */ |
| 66 | |
| 67 | /* |
| 68 | * Putting the EMAC controller to reset when configuring the PHY |
| 69 | * interface select at System Manager |
| 70 | */ |
Marek Vasut | a71df7a | 2015-07-09 02:51:56 +0200 | [diff] [blame] | 71 | socfpga_per_reset(SOCFPGA_RESET(EMAC0), 1); |
| 72 | socfpga_per_reset(SOCFPGA_RESET(EMAC1), 1); |
Pavel Machek | 45d6e67 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 73 | |
| 74 | /* Clearing emac0 PHY interface select to 0 */ |
| 75 | clrbits_le32(&sysmgr_regs->emacgrp_ctrl, |
| 76 | SYSMGR_EMACGRP_CTRL_PHYSEL_MASK << physhift); |
| 77 | |
| 78 | /* configure to PHY interface select choosed */ |
| 79 | setbits_le32(&sysmgr_regs->emacgrp_ctrl, |
| 80 | SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_RGMII << physhift); |
| 81 | |
| 82 | /* Release the EMAC controller from reset */ |
Marek Vasut | a71df7a | 2015-07-09 02:51:56 +0200 | [diff] [blame] | 83 | socfpga_per_reset(reset, 0); |
Pavel Machek | 45d6e67 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 84 | |
| 85 | /* initialize and register the emac */ |
| 86 | return designware_initialize(CONFIG_EMAC_BASE, |
| 87 | CONFIG_PHY_INTERFACE_MODE); |
| 88 | } |
| 89 | #endif |
| 90 | |
Pavel Machek | 4e73686 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 91 | #ifdef CONFIG_DWMMC |
| 92 | /* |
| 93 | * Initializes MMC controllers. |
| 94 | * to override, implement board_mmc_init() |
| 95 | */ |
| 96 | int cpu_mmc_init(bd_t *bis) |
| 97 | { |
| 98 | return socfpga_dwmmc_init(SOCFPGA_SDMMC_ADDRESS, |
| 99 | CONFIG_HPS_SDMMC_BUSWIDTH, 0); |
| 100 | } |
| 101 | #endif |
| 102 | |
Chin Liang See | 23f23f2 | 2014-06-10 02:23:45 -0500 | [diff] [blame] | 103 | #if defined(CONFIG_DISPLAY_CPUINFO) |
| 104 | /* |
| 105 | * Print CPU information |
| 106 | */ |
| 107 | int print_cpuinfo(void) |
| 108 | { |
Pavel Machek | d5a3d3c | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 109 | puts("CPU: Altera SoCFPGA Platform\n"); |
Chin Liang See | 23f23f2 | 2014-06-10 02:23:45 -0500 | [diff] [blame] | 110 | return 0; |
| 111 | } |
| 112 | #endif |
| 113 | |
| 114 | #if defined(CONFIG_SYS_CONSOLE_IS_IN_ENV) && \ |
| 115 | defined(CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE) |
| 116 | int overwrite_console(void) |
| 117 | { |
| 118 | return 0; |
| 119 | } |
| 120 | #endif |
| 121 | |
Pavel Machek | 230fe9b | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 122 | #ifdef CONFIG_FPGA |
| 123 | /* |
| 124 | * FPGA programming support for SoC FPGA Cyclone V |
| 125 | */ |
| 126 | static Altera_desc altera_fpga[] = { |
| 127 | { |
| 128 | /* Family */ |
| 129 | Altera_SoCFPGA, |
| 130 | /* Interface type */ |
| 131 | fast_passive_parallel, |
| 132 | /* No limitation as additional data will be ignored */ |
| 133 | -1, |
| 134 | /* No device function table */ |
| 135 | NULL, |
| 136 | /* Base interface address specified in driver */ |
| 137 | NULL, |
| 138 | /* No cookie implementation */ |
| 139 | 0 |
| 140 | }, |
| 141 | }; |
| 142 | |
| 143 | /* add device descriptor to FPGA device table */ |
| 144 | static void socfpga_fpga_add(void) |
| 145 | { |
| 146 | int i; |
| 147 | fpga_init(); |
| 148 | for (i = 0; i < ARRAY_SIZE(altera_fpga); i++) |
| 149 | fpga_add(fpga_altera, &altera_fpga[i]); |
| 150 | } |
| 151 | #else |
| 152 | static inline void socfpga_fpga_add(void) {} |
| 153 | #endif |
| 154 | |
Pavel Machek | de6da92 | 2014-09-09 14:03:28 +0200 | [diff] [blame] | 155 | int arch_cpu_init(void) |
| 156 | { |
Stefan Roese | d0e932d | 2014-12-19 13:49:10 +0100 | [diff] [blame] | 157 | #ifdef CONFIG_HW_WATCHDOG |
| 158 | /* |
| 159 | * In case the watchdog is enabled, make sure to (re-)configure it |
| 160 | * so that the defined timeout is valid. Otherwise the SPL (Perloader) |
| 161 | * timeout value is still active which might too short for Linux |
| 162 | * booting. |
| 163 | */ |
| 164 | hw_watchdog_init(); |
| 165 | #else |
Pavel Machek | de6da92 | 2014-09-09 14:03:28 +0200 | [diff] [blame] | 166 | /* |
| 167 | * If the HW watchdog is NOT enabled, make sure it is not running, |
| 168 | * for example because it was enabled in the preloader. This might |
| 169 | * trigger a watchdog-triggered reboot of Linux kernel later. |
Marek Vasut | a71df7a | 2015-07-09 02:51:56 +0200 | [diff] [blame] | 170 | * Toggle watchdog reset, so watchdog in not running state. |
Pavel Machek | de6da92 | 2014-09-09 14:03:28 +0200 | [diff] [blame] | 171 | */ |
Marek Vasut | a71df7a | 2015-07-09 02:51:56 +0200 | [diff] [blame] | 172 | socfpga_per_reset(SOCFPGA_RESET(L4WD0), 1); |
| 173 | socfpga_per_reset(SOCFPGA_RESET(L4WD0), 0); |
Pavel Machek | de6da92 | 2014-09-09 14:03:28 +0200 | [diff] [blame] | 174 | #endif |
Stefan Roese | d0e932d | 2014-12-19 13:49:10 +0100 | [diff] [blame] | 175 | |
Pavel Machek | de6da92 | 2014-09-09 14:03:28 +0200 | [diff] [blame] | 176 | return 0; |
| 177 | } |
| 178 | |
Pavel Machek | 13e81d4 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 179 | /* |
| 180 | * Convert all NIC-301 AMBA slaves from secure to non-secure |
| 181 | */ |
| 182 | static void socfpga_nic301_slave_ns(void) |
| 183 | { |
| 184 | writel(0x1, &nic301_regs->lwhps2fpgaregs); |
| 185 | writel(0x1, &nic301_regs->hps2fpgaregs); |
| 186 | writel(0x1, &nic301_regs->acp); |
| 187 | writel(0x1, &nic301_regs->rom); |
| 188 | writel(0x1, &nic301_regs->ocram); |
| 189 | writel(0x1, &nic301_regs->sdrdata); |
| 190 | } |
| 191 | |
Marek Vasut | 7249faf | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 192 | static uint32_t iswgrp_handoff[8]; |
| 193 | |
Marek Vasut | fc52089 | 2014-10-18 03:52:36 +0200 | [diff] [blame] | 194 | int arch_early_init_r(void) |
Chin Liang See | 23f23f2 | 2014-06-10 02:23:45 -0500 | [diff] [blame] | 195 | { |
Marek Vasut | 7249faf | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 196 | int i; |
Marek Vasut | ef84861 | 2015-07-12 15:11:03 +0200 | [diff] [blame^] | 197 | |
| 198 | /* |
| 199 | * Write magic value into magic register to unlock support for |
| 200 | * issuing warm reset. The ancient kernel code expects this |
| 201 | * value to be written into the register by the bootloader, so |
| 202 | * to support that old code, we write it here instead of in the |
| 203 | * reset_cpu() function just before reseting the CPU. |
| 204 | */ |
| 205 | writel(0xae9efebc, &sysmgr_regs->romcodegrp_warmramgrp_enable); |
| 206 | |
Marek Vasut | 7249faf | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 207 | for (i = 0; i < 8; i++) /* Cache initial SW setting regs */ |
| 208 | iswgrp_handoff[i] = readl(&sysmgr_regs->iswgrp_handoff[i]); |
| 209 | |
Pavel Machek | 13e81d4 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 210 | socfpga_bridges_reset(1); |
| 211 | socfpga_nic301_slave_ns(); |
| 212 | |
| 213 | /* |
| 214 | * Private components security: |
| 215 | * U-Boot : configure private timer, global timer and cpu component |
| 216 | * access as non secure for kernel stage (as required by Linux) |
| 217 | */ |
| 218 | setbits_le32(&scu_regs->sacr, 0xfff); |
| 219 | |
Marek Vasut | 60d804c | 2014-09-15 03:58:22 +0200 | [diff] [blame] | 220 | /* Configure the L2 controller to make SDRAM start at 0 */ |
| 221 | #ifdef CONFIG_SOCFPGA_VIRTUAL_TARGET |
| 222 | writel(0x2, &nic301_regs->remap); |
| 223 | #else |
| 224 | writel(0x1, &nic301_regs->remap); /* remap.mpuzero */ |
| 225 | writel(0x1, &pl310->pl310_addr_filter_start); |
| 226 | #endif |
| 227 | |
Pavel Machek | 230fe9b | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 228 | /* Add device descriptor to FPGA device table */ |
| 229 | socfpga_fpga_add(); |
Stefan Roese | a877bec | 2014-11-07 13:50:30 +0100 | [diff] [blame] | 230 | |
| 231 | #ifdef CONFIG_DESIGNWARE_SPI |
| 232 | /* Get Designware SPI controller out of reset */ |
Marek Vasut | a71df7a | 2015-07-09 02:51:56 +0200 | [diff] [blame] | 233 | socfpga_per_reset(SOCFPGA_RESET(SPIM0), 0); |
| 234 | socfpga_per_reset(SOCFPGA_RESET(SPIM1), 0); |
Stefan Roese | a877bec | 2014-11-07 13:50:30 +0100 | [diff] [blame] | 235 | #endif |
| 236 | |
Chin Liang See | 23f23f2 | 2014-06-10 02:23:45 -0500 | [diff] [blame] | 237 | return 0; |
| 238 | } |
Marek Vasut | 7249faf | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 239 | |
| 240 | static void socfpga_sdram_apply_static_cfg(void) |
| 241 | { |
| 242 | const uint32_t staticcfg = SOCFPGA_SDR_ADDRESS + 0x505c; |
| 243 | const uint32_t applymask = 0x8; |
| 244 | uint32_t val = readl(staticcfg) | applymask; |
| 245 | |
| 246 | /* |
| 247 | * SDRAM staticcfg register specific: |
| 248 | * When applying the register setting, the CPU must not access |
| 249 | * SDRAM. Luckily for us, we can abuse i-cache here to help us |
| 250 | * circumvent the SDRAM access issue. The idea is to make sure |
| 251 | * that the code is in one full i-cache line by branching past |
| 252 | * it and back. Once it is in the i-cache, we execute the core |
| 253 | * of the code and apply the register settings. |
| 254 | * |
| 255 | * The code below uses 7 instructions, while the Cortex-A9 has |
| 256 | * 32-byte cachelines, thus the limit is 8 instructions total. |
| 257 | */ |
| 258 | asm volatile( |
| 259 | ".align 5 \n" |
| 260 | " b 2f \n" |
| 261 | "1: str %0, [%1] \n" |
| 262 | " dsb \n" |
| 263 | " isb \n" |
| 264 | " b 3f \n" |
| 265 | "2: b 1b \n" |
| 266 | "3: nop \n" |
| 267 | : : "r"(val), "r"(staticcfg) : "memory", "cc"); |
| 268 | } |
| 269 | |
| 270 | int do_bridge(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 271 | { |
| 272 | if (argc != 2) |
| 273 | return CMD_RET_USAGE; |
| 274 | |
| 275 | argv++; |
| 276 | |
| 277 | switch (*argv[0]) { |
| 278 | case 'e': /* Enable */ |
| 279 | writel(iswgrp_handoff[2], &sysmgr_regs->fpgaintfgrp_module); |
| 280 | socfpga_sdram_apply_static_cfg(); |
| 281 | writel(iswgrp_handoff[3], SOCFPGA_SDR_ADDRESS + 0x5080); |
| 282 | writel(iswgrp_handoff[0], &reset_manager_base->brg_mod_reset); |
| 283 | writel(iswgrp_handoff[1], &nic301_regs->remap); |
| 284 | break; |
| 285 | case 'd': /* Disable */ |
| 286 | writel(0, &sysmgr_regs->fpgaintfgrp_module); |
| 287 | writel(0, SOCFPGA_SDR_ADDRESS + 0x5080); |
| 288 | socfpga_sdram_apply_static_cfg(); |
| 289 | writel(0, &reset_manager_base->brg_mod_reset); |
| 290 | writel(1, &nic301_regs->remap); |
| 291 | break; |
| 292 | default: |
| 293 | return CMD_RET_USAGE; |
| 294 | } |
| 295 | |
| 296 | return 0; |
| 297 | } |
| 298 | |
| 299 | U_BOOT_CMD( |
| 300 | bridge, 2, 1, do_bridge, |
| 301 | "SoCFPGA HPS FPGA bridge control", |
| 302 | "enable - Enable HPS-to-FPGA, FPGA-to-HPS, LWHPS-to-FPGA bridges\n" |
| 303 | "bridge disable - Enable HPS-to-FPGA, FPGA-to-HPS, LWHPS-to-FPGA bridges\n" |
| 304 | "" |
| 305 | ); |