Dinh Nguyen | ad51f7c | 2012-10-04 06:46:02 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 Altera Corporation <www.altera.com> |
| 3 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0+ |
Dinh Nguyen | ad51f7c | 2012-10-04 06:46:02 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <asm/io.h> |
Dinh Nguyen | 8ed6661 | 2015-08-01 03:42:10 +0200 | [diff] [blame] | 9 | #include <errno.h> |
Marek Vasut | f3f8fe2 | 2015-07-25 19:33:56 +0200 | [diff] [blame] | 10 | #include <fdtdec.h> |
| 11 | #include <libfdt.h> |
Pavel Machek | c721380 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 12 | #include <altera.h> |
Pavel Machek | ce340e9 | 2014-07-14 14:14:17 +0200 | [diff] [blame] | 13 | #include <miiphy.h> |
| 14 | #include <netdev.h> |
Stefan Roese | 3bfb591 | 2014-12-19 13:49:10 +0100 | [diff] [blame] | 15 | #include <watchdog.h> |
Pavel Machek | 56a00ab | 2014-09-09 14:03:28 +0200 | [diff] [blame] | 16 | #include <asm/arch/reset_manager.h> |
Dinh Nguyen | 8ed6661 | 2015-08-01 03:42:10 +0200 | [diff] [blame] | 17 | #include <asm/arch/scan_manager.h> |
Pavel Machek | 57d75eb | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 18 | #include <asm/arch/system_manager.h> |
Marek Vasut | 56916e4 | 2014-09-15 03:58:22 +0200 | [diff] [blame] | 19 | #include <asm/arch/nic301.h> |
Pavel Machek | e918e33 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 20 | #include <asm/arch/scu.h> |
Marek Vasut | 56916e4 | 2014-09-15 03:58:22 +0200 | [diff] [blame] | 21 | #include <asm/pl310.h> |
Dinh Nguyen | ad51f7c | 2012-10-04 06:46:02 +0000 | [diff] [blame] | 22 | |
Marek Vasut | f3f8fe2 | 2015-07-25 19:33:56 +0200 | [diff] [blame] | 23 | #include <dt-bindings/reset/altr,rst-mgr.h> |
| 24 | |
Dinh Nguyen | ad51f7c | 2012-10-04 06:46:02 +0000 | [diff] [blame] | 25 | DECLARE_GLOBAL_DATA_PTR; |
| 26 | |
Marek Vasut | 56916e4 | 2014-09-15 03:58:22 +0200 | [diff] [blame] | 27 | static struct pl310_regs *const pl310 = |
| 28 | (struct pl310_regs *)CONFIG_SYS_PL310_BASE; |
Pavel Machek | 57d75eb | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 29 | static struct socfpga_system_manager *sysmgr_regs = |
| 30 | (struct socfpga_system_manager *)SOCFPGA_SYSMGR_ADDRESS; |
Marek Vasut | 46fbdf6 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 31 | static struct socfpga_reset_manager *reset_manager_base = |
| 32 | (struct socfpga_reset_manager *)SOCFPGA_RSTMGR_ADDRESS; |
Marek Vasut | 56916e4 | 2014-09-15 03:58:22 +0200 | [diff] [blame] | 33 | static struct nic301_registers *nic301_regs = |
| 34 | (struct nic301_registers *)SOCFPGA_L3REGS_ADDRESS; |
Pavel Machek | e918e33 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 35 | static struct scu_registers *scu_regs = |
| 36 | (struct scu_registers *)SOCFPGA_MPUSCU_ADDRESS; |
Pavel Machek | 57d75eb | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 37 | |
Dinh Nguyen | ad51f7c | 2012-10-04 06:46:02 +0000 | [diff] [blame] | 38 | int dram_init(void) |
| 39 | { |
| 40 | gd->ram_size = get_ram_size((long *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE); |
| 41 | return 0; |
| 42 | } |
Pavel Machek | 57d75eb | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 43 | |
Marek Vasut | d515794 | 2014-09-21 13:57:40 +0200 | [diff] [blame] | 44 | void enable_caches(void) |
| 45 | { |
| 46 | #ifndef CONFIG_SYS_ICACHE_OFF |
| 47 | icache_enable(); |
| 48 | #endif |
| 49 | #ifndef CONFIG_SYS_DCACHE_OFF |
| 50 | dcache_enable(); |
| 51 | #endif |
| 52 | } |
| 53 | |
Dinh Nguyen | e89ff70 | 2015-10-15 10:13:36 -0500 | [diff] [blame] | 54 | void v7_outer_cache_enable(void) |
| 55 | { |
Marek Vasut | 9f7b30d | 2015-12-20 04:00:09 +0100 | [diff] [blame] | 56 | /* Disable the L2 cache */ |
| 57 | clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN); |
Dinh Nguyen | e89ff70 | 2015-10-15 10:13:36 -0500 | [diff] [blame] | 58 | |
| 59 | /* enable BRESP, instruction and data prefetch, full line of zeroes */ |
| 60 | setbits_le32(&pl310->pl310_aux_ctrl, |
| 61 | L310_AUX_CTRL_DATA_PREFETCH_MASK | |
| 62 | L310_AUX_CTRL_INST_PREFETCH_MASK | |
| 63 | L310_SHARED_ATT_OVERRIDE_ENABLE); |
Marek Vasut | 9f7b30d | 2015-12-20 04:00:09 +0100 | [diff] [blame] | 64 | |
| 65 | /* Enable the L2 cache */ |
| 66 | setbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN); |
| 67 | } |
| 68 | |
| 69 | void v7_outer_cache_disable(void) |
| 70 | { |
| 71 | /* Disable the L2 cache */ |
| 72 | clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN); |
Dinh Nguyen | e89ff70 | 2015-10-15 10:13:36 -0500 | [diff] [blame] | 73 | } |
| 74 | |
Pavel Machek | 57d75eb | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 75 | /* |
| 76 | * DesignWare Ethernet initialization |
| 77 | */ |
Simon Glass | 6e37874 | 2015-04-05 16:07:34 -0600 | [diff] [blame] | 78 | #ifdef CONFIG_ETH_DESIGNWARE |
Marek Vasut | 559c28a | 2016-03-21 13:38:11 +0100 | [diff] [blame] | 79 | static void dwmac_deassert_reset(const unsigned int of_reset_id, |
| 80 | const u32 phymode) |
Pavel Machek | 57d75eb | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 81 | { |
Marek Vasut | f3f8fe2 | 2015-07-25 19:33:56 +0200 | [diff] [blame] | 82 | u32 physhift, reset; |
Pavel Machek | 57d75eb | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 83 | |
Marek Vasut | f3f8fe2 | 2015-07-25 19:33:56 +0200 | [diff] [blame] | 84 | if (of_reset_id == EMAC0_RESET) { |
| 85 | physhift = SYSMGR_EMACGRP_CTRL_PHYSEL0_LSB; |
| 86 | reset = SOCFPGA_RESET(EMAC0); |
| 87 | } else if (of_reset_id == EMAC1_RESET) { |
| 88 | physhift = SYSMGR_EMACGRP_CTRL_PHYSEL1_LSB; |
| 89 | reset = SOCFPGA_RESET(EMAC1); |
| 90 | } else { |
| 91 | printf("GMAC: Invalid reset ID (%i)!\n", of_reset_id); |
| 92 | return; |
| 93 | } |
Pavel Machek | 57d75eb | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 94 | |
| 95 | /* Clearing emac0 PHY interface select to 0 */ |
| 96 | clrbits_le32(&sysmgr_regs->emacgrp_ctrl, |
| 97 | SYSMGR_EMACGRP_CTRL_PHYSEL_MASK << physhift); |
| 98 | |
| 99 | /* configure to PHY interface select choosed */ |
| 100 | setbits_le32(&sysmgr_regs->emacgrp_ctrl, |
Marek Vasut | 559c28a | 2016-03-21 13:38:11 +0100 | [diff] [blame] | 101 | phymode << physhift); |
Pavel Machek | 57d75eb | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 102 | |
| 103 | /* Release the EMAC controller from reset */ |
Marek Vasut | 75f6b5c | 2015-07-09 02:51:56 +0200 | [diff] [blame] | 104 | socfpga_per_reset(reset, 0); |
Marek Vasut | f3f8fe2 | 2015-07-25 19:33:56 +0200 | [diff] [blame] | 105 | } |
| 106 | |
Marek Vasut | 559c28a | 2016-03-21 13:38:11 +0100 | [diff] [blame] | 107 | static u32 dwmac_phymode_to_modereg(const char *phymode, u32 *modereg) |
| 108 | { |
| 109 | if (!phymode) |
| 110 | return -EINVAL; |
| 111 | |
| 112 | if (!strcmp(phymode, "mii") || !strcmp(phymode, "gmii")) { |
| 113 | *modereg = SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_GMII_MII; |
| 114 | return 0; |
| 115 | } |
| 116 | |
| 117 | if (!strcmp(phymode, "rgmii")) { |
| 118 | *modereg = SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_RGMII; |
| 119 | return 0; |
| 120 | } |
| 121 | |
| 122 | if (!strcmp(phymode, "rmii")) { |
| 123 | *modereg = SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_RMII; |
| 124 | return 0; |
| 125 | } |
| 126 | |
| 127 | return -EINVAL; |
| 128 | } |
| 129 | |
Marek Vasut | e089d4d | 2016-02-11 16:36:43 +0100 | [diff] [blame] | 130 | static int socfpga_eth_reset(void) |
Marek Vasut | f3f8fe2 | 2015-07-25 19:33:56 +0200 | [diff] [blame] | 131 | { |
| 132 | const void *fdt = gd->fdt_blob; |
| 133 | struct fdtdec_phandle_args args; |
Marek Vasut | 559c28a | 2016-03-21 13:38:11 +0100 | [diff] [blame] | 134 | const char *phy_mode; |
| 135 | u32 phy_modereg; |
Marek Vasut | f3f8fe2 | 2015-07-25 19:33:56 +0200 | [diff] [blame] | 136 | int nodes[2]; /* Max. two GMACs */ |
| 137 | int ret, count; |
| 138 | int i, node; |
| 139 | |
| 140 | /* Put both GMACs into RESET state. */ |
| 141 | socfpga_per_reset(SOCFPGA_RESET(EMAC0), 1); |
| 142 | socfpga_per_reset(SOCFPGA_RESET(EMAC1), 1); |
| 143 | |
| 144 | count = fdtdec_find_aliases_for_id(fdt, "ethernet", |
| 145 | COMPAT_ALTERA_SOCFPGA_DWMAC, |
| 146 | nodes, ARRAY_SIZE(nodes)); |
| 147 | for (i = 0; i < count; i++) { |
| 148 | node = nodes[i]; |
| 149 | if (node <= 0) |
| 150 | continue; |
| 151 | |
| 152 | ret = fdtdec_parse_phandle_with_args(fdt, node, "resets", |
| 153 | "#reset-cells", 1, 0, |
| 154 | &args); |
| 155 | if (ret || (args.args_count != 1)) { |
| 156 | debug("GMAC%i: Failed to parse DT 'resets'!\n", i); |
| 157 | continue; |
| 158 | } |
| 159 | |
Marek Vasut | 559c28a | 2016-03-21 13:38:11 +0100 | [diff] [blame] | 160 | phy_mode = fdt_getprop(fdt, node, "phy-mode", NULL); |
| 161 | ret = dwmac_phymode_to_modereg(phy_mode, &phy_modereg); |
| 162 | if (ret) { |
| 163 | debug("GMAC%i: Failed to parse DT 'phy-mode'!\n", i); |
| 164 | continue; |
| 165 | } |
| 166 | |
| 167 | dwmac_deassert_reset(args.args[0], phy_modereg); |
Marek Vasut | f3f8fe2 | 2015-07-25 19:33:56 +0200 | [diff] [blame] | 168 | } |
Pavel Machek | 57d75eb | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 169 | |
Marek Vasut | 5ca9954 | 2015-07-25 18:47:02 +0200 | [diff] [blame] | 170 | return 0; |
Pavel Machek | 57d75eb | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 171 | } |
Marek Vasut | e089d4d | 2016-02-11 16:36:43 +0100 | [diff] [blame] | 172 | #else |
| 173 | static int socfpga_eth_reset(void) |
| 174 | { |
Anatolij Gustschin | 4f70c38 | 2016-05-06 17:16:31 +0200 | [diff] [blame] | 175 | return 0; |
Marek Vasut | e089d4d | 2016-02-11 16:36:43 +0100 | [diff] [blame] | 176 | }; |
Pavel Machek | 57d75eb | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 177 | #endif |
Chin Liang See | bff262c | 2014-06-10 02:23:45 -0500 | [diff] [blame] | 178 | |
Marek Vasut | dc495ae | 2015-07-22 05:40:12 +0200 | [diff] [blame] | 179 | struct { |
| 180 | const char *mode; |
| 181 | const char *name; |
| 182 | } bsel_str[] = { |
| 183 | { "rsvd", "Reserved", }, |
| 184 | { "fpga", "FPGA (HPS2FPGA Bridge)", }, |
| 185 | { "nand", "NAND Flash (1.8V)", }, |
| 186 | { "nand", "NAND Flash (3.0V)", }, |
| 187 | { "sd", "SD/MMC External Transceiver (1.8V)", }, |
| 188 | { "sd", "SD/MMC Internal Transceiver (3.0V)", }, |
| 189 | { "qspi", "QSPI Flash (1.8V)", }, |
| 190 | { "qspi", "QSPI Flash (3.0V)", }, |
Marek Vasut | f568865 | 2015-07-21 16:10:13 +0200 | [diff] [blame] | 191 | }; |
| 192 | |
Dinh Nguyen | 8ed6661 | 2015-08-01 03:42:10 +0200 | [diff] [blame] | 193 | static const struct { |
| 194 | const u16 pn; |
| 195 | const char *name; |
| 196 | const char *var; |
| 197 | } const socfpga_fpga_model[] = { |
| 198 | /* Cyclone V E */ |
| 199 | { 0x2b15, "Cyclone V, E/A2", "cv_e_a2" }, |
| 200 | { 0x2b05, "Cyclone V, E/A4", "cv_e_a4" }, |
| 201 | { 0x2b22, "Cyclone V, E/A5", "cv_e_a5" }, |
| 202 | { 0x2b13, "Cyclone V, E/A7", "cv_e_a7" }, |
| 203 | { 0x2b14, "Cyclone V, E/A9", "cv_e_a9" }, |
| 204 | /* Cyclone V GX/GT */ |
| 205 | { 0x2b01, "Cyclone V, GX/C3", "cv_gx_c3" }, |
| 206 | { 0x2b12, "Cyclone V, GX/C4", "cv_gx_c4" }, |
| 207 | { 0x2b02, "Cyclone V, GX/C5 or GT/D5", "cv_gx_c5" }, |
| 208 | { 0x2b03, "Cyclone V, GX/C7 or GT/D7", "cv_gx_c7" }, |
| 209 | { 0x2b04, "Cyclone V, GX/C9 or GT/D9", "cv_gx_c9" }, |
| 210 | /* Cyclone V SE/SX/ST */ |
| 211 | { 0x2d11, "Cyclone V, SE/A2 or SX/C2", "cv_se_a2" }, |
| 212 | { 0x2d01, "Cyclone V, SE/A4 or SX/C4", "cv_se_a4" }, |
| 213 | { 0x2d12, "Cyclone V, SE/A5 or SX/C5 or ST/D5", "cv_se_a5" }, |
| 214 | { 0x2d02, "Cyclone V, SE/A6 or SX/C6 or ST/D6", "cv_se_a6" }, |
| 215 | /* Arria V */ |
| 216 | { 0x2d03, "Arria V, D5", "av_d5" }, |
| 217 | }; |
| 218 | |
| 219 | static int socfpga_fpga_id(const bool print_id) |
| 220 | { |
| 221 | const u32 altera_mi = 0x6e; |
| 222 | const u32 id = scan_mgr_get_fpga_id(); |
| 223 | |
| 224 | const u32 lsb = id & 0x00000001; |
| 225 | const u32 mi = (id >> 1) & 0x000007ff; |
| 226 | const u32 pn = (id >> 12) & 0x0000ffff; |
| 227 | const u32 version = (id >> 28) & 0x0000000f; |
| 228 | int i; |
| 229 | |
| 230 | if ((mi != altera_mi) || (lsb != 1)) { |
| 231 | printf("FPGA: Not Altera chip ID\n"); |
| 232 | return -EINVAL; |
| 233 | } |
| 234 | |
| 235 | for (i = 0; i < ARRAY_SIZE(socfpga_fpga_model); i++) |
| 236 | if (pn == socfpga_fpga_model[i].pn) |
| 237 | break; |
| 238 | |
| 239 | if (i == ARRAY_SIZE(socfpga_fpga_model)) { |
| 240 | printf("FPGA: Unknown Altera chip, ID 0x%08x\n", id); |
| 241 | return -EINVAL; |
| 242 | } |
| 243 | |
| 244 | if (print_id) |
| 245 | printf("FPGA: Altera %s, version 0x%01x\n", |
| 246 | socfpga_fpga_model[i].name, version); |
| 247 | return i; |
| 248 | } |
| 249 | |
Chin Liang See | bff262c | 2014-06-10 02:23:45 -0500 | [diff] [blame] | 250 | /* |
| 251 | * Print CPU information |
| 252 | */ |
Marek Vasut | dc495ae | 2015-07-22 05:40:12 +0200 | [diff] [blame] | 253 | #if defined(CONFIG_DISPLAY_CPUINFO) |
Chin Liang See | bff262c | 2014-06-10 02:23:45 -0500 | [diff] [blame] | 254 | int print_cpuinfo(void) |
| 255 | { |
Marek Vasut | f568865 | 2015-07-21 16:10:13 +0200 | [diff] [blame] | 256 | const u32 bsel = readl(&sysmgr_regs->bootinfo) & 0x7; |
Pavel Machek | 2f98347 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 257 | puts("CPU: Altera SoCFPGA Platform\n"); |
Dinh Nguyen | 8ed6661 | 2015-08-01 03:42:10 +0200 | [diff] [blame] | 258 | socfpga_fpga_id(1); |
Marek Vasut | dc495ae | 2015-07-22 05:40:12 +0200 | [diff] [blame] | 259 | printf("BOOT: %s\n", bsel_str[bsel].name); |
| 260 | return 0; |
| 261 | } |
| 262 | #endif |
| 263 | |
| 264 | #ifdef CONFIG_ARCH_MISC_INIT |
| 265 | int arch_misc_init(void) |
| 266 | { |
| 267 | const u32 bsel = readl(&sysmgr_regs->bootinfo) & 0x7; |
Dinh Nguyen | 8ed6661 | 2015-08-01 03:42:10 +0200 | [diff] [blame] | 268 | const int fpga_id = socfpga_fpga_id(0); |
Marek Vasut | dc495ae | 2015-07-22 05:40:12 +0200 | [diff] [blame] | 269 | setenv("bootmode", bsel_str[bsel].mode); |
Dinh Nguyen | 8ed6661 | 2015-08-01 03:42:10 +0200 | [diff] [blame] | 270 | if (fpga_id >= 0) |
| 271 | setenv("fpgatype", socfpga_fpga_model[fpga_id].var); |
Marek Vasut | e089d4d | 2016-02-11 16:36:43 +0100 | [diff] [blame] | 272 | return socfpga_eth_reset(); |
Chin Liang See | bff262c | 2014-06-10 02:23:45 -0500 | [diff] [blame] | 273 | } |
| 274 | #endif |
| 275 | |
| 276 | #if defined(CONFIG_SYS_CONSOLE_IS_IN_ENV) && \ |
| 277 | defined(CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE) |
| 278 | int overwrite_console(void) |
| 279 | { |
| 280 | return 0; |
| 281 | } |
| 282 | #endif |
| 283 | |
Pavel Machek | c721380 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 284 | #ifdef CONFIG_FPGA |
| 285 | /* |
| 286 | * FPGA programming support for SoC FPGA Cyclone V |
| 287 | */ |
| 288 | static Altera_desc altera_fpga[] = { |
| 289 | { |
| 290 | /* Family */ |
| 291 | Altera_SoCFPGA, |
| 292 | /* Interface type */ |
| 293 | fast_passive_parallel, |
| 294 | /* No limitation as additional data will be ignored */ |
| 295 | -1, |
| 296 | /* No device function table */ |
| 297 | NULL, |
| 298 | /* Base interface address specified in driver */ |
| 299 | NULL, |
| 300 | /* No cookie implementation */ |
| 301 | 0 |
| 302 | }, |
| 303 | }; |
| 304 | |
| 305 | /* add device descriptor to FPGA device table */ |
| 306 | static void socfpga_fpga_add(void) |
| 307 | { |
| 308 | int i; |
| 309 | fpga_init(); |
| 310 | for (i = 0; i < ARRAY_SIZE(altera_fpga); i++) |
| 311 | fpga_add(fpga_altera, &altera_fpga[i]); |
| 312 | } |
| 313 | #else |
| 314 | static inline void socfpga_fpga_add(void) {} |
| 315 | #endif |
| 316 | |
Pavel Machek | 56a00ab | 2014-09-09 14:03:28 +0200 | [diff] [blame] | 317 | int arch_cpu_init(void) |
| 318 | { |
Stefan Roese | 3bfb591 | 2014-12-19 13:49:10 +0100 | [diff] [blame] | 319 | #ifdef CONFIG_HW_WATCHDOG |
| 320 | /* |
| 321 | * In case the watchdog is enabled, make sure to (re-)configure it |
| 322 | * so that the defined timeout is valid. Otherwise the SPL (Perloader) |
| 323 | * timeout value is still active which might too short for Linux |
| 324 | * booting. |
| 325 | */ |
| 326 | hw_watchdog_init(); |
| 327 | #else |
Pavel Machek | 56a00ab | 2014-09-09 14:03:28 +0200 | [diff] [blame] | 328 | /* |
| 329 | * If the HW watchdog is NOT enabled, make sure it is not running, |
| 330 | * for example because it was enabled in the preloader. This might |
| 331 | * trigger a watchdog-triggered reboot of Linux kernel later. |
Marek Vasut | 75f6b5c | 2015-07-09 02:51:56 +0200 | [diff] [blame] | 332 | * Toggle watchdog reset, so watchdog in not running state. |
Pavel Machek | 56a00ab | 2014-09-09 14:03:28 +0200 | [diff] [blame] | 333 | */ |
Marek Vasut | 75f6b5c | 2015-07-09 02:51:56 +0200 | [diff] [blame] | 334 | socfpga_per_reset(SOCFPGA_RESET(L4WD0), 1); |
| 335 | socfpga_per_reset(SOCFPGA_RESET(L4WD0), 0); |
Pavel Machek | 56a00ab | 2014-09-09 14:03:28 +0200 | [diff] [blame] | 336 | #endif |
Stefan Roese | 3bfb591 | 2014-12-19 13:49:10 +0100 | [diff] [blame] | 337 | |
Pavel Machek | 56a00ab | 2014-09-09 14:03:28 +0200 | [diff] [blame] | 338 | return 0; |
| 339 | } |
| 340 | |
Pavel Machek | e918e33 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 341 | /* |
| 342 | * Convert all NIC-301 AMBA slaves from secure to non-secure |
| 343 | */ |
| 344 | static void socfpga_nic301_slave_ns(void) |
| 345 | { |
| 346 | writel(0x1, &nic301_regs->lwhps2fpgaregs); |
| 347 | writel(0x1, &nic301_regs->hps2fpgaregs); |
| 348 | writel(0x1, &nic301_regs->acp); |
| 349 | writel(0x1, &nic301_regs->rom); |
| 350 | writel(0x1, &nic301_regs->ocram); |
| 351 | writel(0x1, &nic301_regs->sdrdata); |
| 352 | } |
| 353 | |
Marek Vasut | 46fbdf6 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 354 | static uint32_t iswgrp_handoff[8]; |
| 355 | |
Marek Vasut | 54c282e | 2014-10-18 03:52:36 +0200 | [diff] [blame] | 356 | int arch_early_init_r(void) |
Chin Liang See | bff262c | 2014-06-10 02:23:45 -0500 | [diff] [blame] | 357 | { |
Marek Vasut | 46fbdf6 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 358 | int i; |
Marek Vasut | b7e7738 | 2015-07-12 15:11:03 +0200 | [diff] [blame] | 359 | |
| 360 | /* |
| 361 | * Write magic value into magic register to unlock support for |
| 362 | * issuing warm reset. The ancient kernel code expects this |
| 363 | * value to be written into the register by the bootloader, so |
| 364 | * to support that old code, we write it here instead of in the |
Vagrant Cascadian | 259b1fb | 2016-10-23 20:45:19 -0700 | [diff] [blame] | 365 | * reset_cpu() function just before resetting the CPU. |
Marek Vasut | b7e7738 | 2015-07-12 15:11:03 +0200 | [diff] [blame] | 366 | */ |
| 367 | writel(0xae9efebc, &sysmgr_regs->romcodegrp_warmramgrp_enable); |
| 368 | |
Marek Vasut | 46fbdf6 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 369 | for (i = 0; i < 8; i++) /* Cache initial SW setting regs */ |
| 370 | iswgrp_handoff[i] = readl(&sysmgr_regs->iswgrp_handoff[i]); |
| 371 | |
Pavel Machek | e918e33 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 372 | socfpga_bridges_reset(1); |
| 373 | socfpga_nic301_slave_ns(); |
| 374 | |
| 375 | /* |
| 376 | * Private components security: |
| 377 | * U-Boot : configure private timer, global timer and cpu component |
| 378 | * access as non secure for kernel stage (as required by Linux) |
| 379 | */ |
| 380 | setbits_le32(&scu_regs->sacr, 0xfff); |
| 381 | |
Marek Vasut | 56916e4 | 2014-09-15 03:58:22 +0200 | [diff] [blame] | 382 | /* Configure the L2 controller to make SDRAM start at 0 */ |
| 383 | #ifdef CONFIG_SOCFPGA_VIRTUAL_TARGET |
| 384 | writel(0x2, &nic301_regs->remap); |
| 385 | #else |
| 386 | writel(0x1, &nic301_regs->remap); /* remap.mpuzero */ |
| 387 | writel(0x1, &pl310->pl310_addr_filter_start); |
| 388 | #endif |
| 389 | |
Pavel Machek | c721380 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 390 | /* Add device descriptor to FPGA device table */ |
| 391 | socfpga_fpga_add(); |
Stefan Roese | ca6b8fb | 2014-11-07 13:50:30 +0100 | [diff] [blame] | 392 | |
| 393 | #ifdef CONFIG_DESIGNWARE_SPI |
| 394 | /* Get Designware SPI controller out of reset */ |
Marek Vasut | 75f6b5c | 2015-07-09 02:51:56 +0200 | [diff] [blame] | 395 | socfpga_per_reset(SOCFPGA_RESET(SPIM0), 0); |
| 396 | socfpga_per_reset(SOCFPGA_RESET(SPIM1), 0); |
Stefan Roese | ca6b8fb | 2014-11-07 13:50:30 +0100 | [diff] [blame] | 397 | #endif |
| 398 | |
Marek Vasut | 70c0412 | 2015-12-20 04:00:43 +0100 | [diff] [blame] | 399 | #ifdef CONFIG_NAND_DENALI |
| 400 | socfpga_per_reset(SOCFPGA_RESET(NAND), 0); |
| 401 | #endif |
| 402 | |
Chin Liang See | bff262c | 2014-06-10 02:23:45 -0500 | [diff] [blame] | 403 | return 0; |
| 404 | } |
Marek Vasut | 46fbdf6 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 405 | |
| 406 | static void socfpga_sdram_apply_static_cfg(void) |
| 407 | { |
| 408 | const uint32_t staticcfg = SOCFPGA_SDR_ADDRESS + 0x505c; |
| 409 | const uint32_t applymask = 0x8; |
| 410 | uint32_t val = readl(staticcfg) | applymask; |
| 411 | |
| 412 | /* |
| 413 | * SDRAM staticcfg register specific: |
| 414 | * When applying the register setting, the CPU must not access |
| 415 | * SDRAM. Luckily for us, we can abuse i-cache here to help us |
| 416 | * circumvent the SDRAM access issue. The idea is to make sure |
| 417 | * that the code is in one full i-cache line by branching past |
| 418 | * it and back. Once it is in the i-cache, we execute the core |
| 419 | * of the code and apply the register settings. |
| 420 | * |
| 421 | * The code below uses 7 instructions, while the Cortex-A9 has |
| 422 | * 32-byte cachelines, thus the limit is 8 instructions total. |
| 423 | */ |
| 424 | asm volatile( |
| 425 | ".align 5 \n" |
| 426 | " b 2f \n" |
| 427 | "1: str %0, [%1] \n" |
| 428 | " dsb \n" |
| 429 | " isb \n" |
| 430 | " b 3f \n" |
| 431 | "2: b 1b \n" |
| 432 | "3: nop \n" |
| 433 | : : "r"(val), "r"(staticcfg) : "memory", "cc"); |
| 434 | } |
| 435 | |
| 436 | int do_bridge(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 437 | { |
| 438 | if (argc != 2) |
| 439 | return CMD_RET_USAGE; |
| 440 | |
| 441 | argv++; |
| 442 | |
| 443 | switch (*argv[0]) { |
| 444 | case 'e': /* Enable */ |
| 445 | writel(iswgrp_handoff[2], &sysmgr_regs->fpgaintfgrp_module); |
| 446 | socfpga_sdram_apply_static_cfg(); |
| 447 | writel(iswgrp_handoff[3], SOCFPGA_SDR_ADDRESS + 0x5080); |
| 448 | writel(iswgrp_handoff[0], &reset_manager_base->brg_mod_reset); |
| 449 | writel(iswgrp_handoff[1], &nic301_regs->remap); |
| 450 | break; |
| 451 | case 'd': /* Disable */ |
| 452 | writel(0, &sysmgr_regs->fpgaintfgrp_module); |
| 453 | writel(0, SOCFPGA_SDR_ADDRESS + 0x5080); |
| 454 | socfpga_sdram_apply_static_cfg(); |
| 455 | writel(0, &reset_manager_base->brg_mod_reset); |
| 456 | writel(1, &nic301_regs->remap); |
| 457 | break; |
| 458 | default: |
| 459 | return CMD_RET_USAGE; |
| 460 | } |
| 461 | |
| 462 | return 0; |
| 463 | } |
| 464 | |
| 465 | U_BOOT_CMD( |
| 466 | bridge, 2, 1, do_bridge, |
| 467 | "SoCFPGA HPS FPGA bridge control", |
| 468 | "enable - Enable HPS-to-FPGA, FPGA-to-HPS, LWHPS-to-FPGA bridges\n" |
| 469 | "bridge disable - Enable HPS-to-FPGA, FPGA-to-HPS, LWHPS-to-FPGA bridges\n" |
| 470 | "" |
| 471 | ); |