Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Dinh Nguyen | ad51f7c | 2012-10-04 06:46:02 +0000 | [diff] [blame] | 2 | /* |
Ley Foon Tan | b149f2b | 2017-04-26 02:44:36 +0800 | [diff] [blame] | 3 | * Copyright (C) 2012-2017 Altera Corporation <www.altera.com> |
Dinh Nguyen | ad51f7c | 2012-10-04 06:46:02 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <asm/io.h> |
Dinh Nguyen | 8ed6661 | 2015-08-01 03:42:10 +0200 | [diff] [blame] | 8 | #include <errno.h> |
Marek Vasut | f3f8fe2 | 2015-07-25 19:33:56 +0200 | [diff] [blame] | 9 | #include <fdtdec.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 10 | #include <linux/libfdt.h> |
Pavel Machek | c721380 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 11 | #include <altera.h> |
Pavel Machek | ce340e9 | 2014-07-14 14:14:17 +0200 | [diff] [blame] | 12 | #include <miiphy.h> |
| 13 | #include <netdev.h> |
Stefan Roese | 3bfb591 | 2014-12-19 13:49:10 +0100 | [diff] [blame] | 14 | #include <watchdog.h> |
Ley Foon Tan | b149f2b | 2017-04-26 02:44:36 +0800 | [diff] [blame] | 15 | #include <asm/arch/misc.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 | |
| 23 | DECLARE_GLOBAL_DATA_PTR; |
| 24 | |
Ley Foon Tan | b149f2b | 2017-04-26 02:44:36 +0800 | [diff] [blame] | 25 | static const struct pl310_regs *const pl310 = |
Marek Vasut | 56916e4 | 2014-09-15 03:58:22 +0200 | [diff] [blame] | 26 | (struct pl310_regs *)CONFIG_SYS_PL310_BASE; |
Ley Foon Tan | b149f2b | 2017-04-26 02:44:36 +0800 | [diff] [blame] | 27 | |
| 28 | struct bsel bsel_str[] = { |
| 29 | { "rsvd", "Reserved", }, |
| 30 | { "fpga", "FPGA (HPS2FPGA Bridge)", }, |
| 31 | { "nand", "NAND Flash (1.8V)", }, |
| 32 | { "nand", "NAND Flash (3.0V)", }, |
| 33 | { "sd", "SD/MMC External Transceiver (1.8V)", }, |
| 34 | { "sd", "SD/MMC Internal Transceiver (3.0V)", }, |
| 35 | { "qspi", "QSPI Flash (1.8V)", }, |
| 36 | { "qspi", "QSPI Flash (3.0V)", }, |
| 37 | }; |
Pavel Machek | 57d75eb | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 38 | |
Dinh Nguyen | ad51f7c | 2012-10-04 06:46:02 +0000 | [diff] [blame] | 39 | int dram_init(void) |
| 40 | { |
| 41 | gd->ram_size = get_ram_size((long *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE); |
| 42 | return 0; |
| 43 | } |
Pavel Machek | 57d75eb | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 44 | |
Marek Vasut | d515794 | 2014-09-21 13:57:40 +0200 | [diff] [blame] | 45 | void enable_caches(void) |
| 46 | { |
| 47 | #ifndef CONFIG_SYS_ICACHE_OFF |
| 48 | icache_enable(); |
| 49 | #endif |
| 50 | #ifndef CONFIG_SYS_DCACHE_OFF |
| 51 | dcache_enable(); |
| 52 | #endif |
| 53 | } |
| 54 | |
Dinh Nguyen | e89ff70 | 2015-10-15 10:13:36 -0500 | [diff] [blame] | 55 | void v7_outer_cache_enable(void) |
| 56 | { |
Marek Vasut | 9f7b30d | 2015-12-20 04:00:09 +0100 | [diff] [blame] | 57 | /* Disable the L2 cache */ |
| 58 | clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN); |
Dinh Nguyen | e89ff70 | 2015-10-15 10:13:36 -0500 | [diff] [blame] | 59 | |
| 60 | /* enable BRESP, instruction and data prefetch, full line of zeroes */ |
| 61 | setbits_le32(&pl310->pl310_aux_ctrl, |
| 62 | L310_AUX_CTRL_DATA_PREFETCH_MASK | |
| 63 | L310_AUX_CTRL_INST_PREFETCH_MASK | |
| 64 | L310_SHARED_ATT_OVERRIDE_ENABLE); |
Marek Vasut | 9f7b30d | 2015-12-20 04:00:09 +0100 | [diff] [blame] | 65 | |
| 66 | /* Enable the L2 cache */ |
| 67 | setbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN); |
| 68 | } |
| 69 | |
| 70 | void v7_outer_cache_disable(void) |
| 71 | { |
| 72 | /* Disable the L2 cache */ |
| 73 | clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN); |
Dinh Nguyen | e89ff70 | 2015-10-15 10:13:36 -0500 | [diff] [blame] | 74 | } |
| 75 | |
Chin Liang See | bff262c | 2014-06-10 02:23:45 -0500 | [diff] [blame] | 76 | #if defined(CONFIG_SYS_CONSOLE_IS_IN_ENV) && \ |
| 77 | defined(CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE) |
| 78 | int overwrite_console(void) |
| 79 | { |
| 80 | return 0; |
| 81 | } |
| 82 | #endif |
| 83 | |
Pavel Machek | c721380 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 84 | #ifdef CONFIG_FPGA |
| 85 | /* |
| 86 | * FPGA programming support for SoC FPGA Cyclone V |
| 87 | */ |
| 88 | static Altera_desc altera_fpga[] = { |
| 89 | { |
| 90 | /* Family */ |
| 91 | Altera_SoCFPGA, |
| 92 | /* Interface type */ |
| 93 | fast_passive_parallel, |
| 94 | /* No limitation as additional data will be ignored */ |
| 95 | -1, |
| 96 | /* No device function table */ |
| 97 | NULL, |
| 98 | /* Base interface address specified in driver */ |
| 99 | NULL, |
| 100 | /* No cookie implementation */ |
| 101 | 0 |
| 102 | }, |
| 103 | }; |
| 104 | |
| 105 | /* add device descriptor to FPGA device table */ |
Ley Foon Tan | b149f2b | 2017-04-26 02:44:36 +0800 | [diff] [blame] | 106 | void socfpga_fpga_add(void) |
Pavel Machek | c721380 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 107 | { |
| 108 | int i; |
| 109 | fpga_init(); |
| 110 | for (i = 0; i < ARRAY_SIZE(altera_fpga); i++) |
| 111 | fpga_add(fpga_altera, &altera_fpga[i]); |
| 112 | } |
Pavel Machek | c721380 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 113 | #endif |
| 114 | |
Pavel Machek | 56a00ab | 2014-09-09 14:03:28 +0200 | [diff] [blame] | 115 | int arch_cpu_init(void) |
| 116 | { |
Stefan Roese | 3bfb591 | 2014-12-19 13:49:10 +0100 | [diff] [blame] | 117 | #ifdef CONFIG_HW_WATCHDOG |
| 118 | /* |
| 119 | * In case the watchdog is enabled, make sure to (re-)configure it |
| 120 | * so that the defined timeout is valid. Otherwise the SPL (Perloader) |
| 121 | * timeout value is still active which might too short for Linux |
| 122 | * booting. |
| 123 | */ |
| 124 | hw_watchdog_init(); |
| 125 | #else |
Pavel Machek | 56a00ab | 2014-09-09 14:03:28 +0200 | [diff] [blame] | 126 | /* |
| 127 | * If the HW watchdog is NOT enabled, make sure it is not running, |
| 128 | * for example because it was enabled in the preloader. This might |
| 129 | * trigger a watchdog-triggered reboot of Linux kernel later. |
Marek Vasut | 75f6b5c | 2015-07-09 02:51:56 +0200 | [diff] [blame] | 130 | * Toggle watchdog reset, so watchdog in not running state. |
Pavel Machek | 56a00ab | 2014-09-09 14:03:28 +0200 | [diff] [blame] | 131 | */ |
Marek Vasut | 75f6b5c | 2015-07-09 02:51:56 +0200 | [diff] [blame] | 132 | socfpga_per_reset(SOCFPGA_RESET(L4WD0), 1); |
| 133 | socfpga_per_reset(SOCFPGA_RESET(L4WD0), 0); |
Pavel Machek | 56a00ab | 2014-09-09 14:03:28 +0200 | [diff] [blame] | 134 | #endif |
Stefan Roese | 3bfb591 | 2014-12-19 13:49:10 +0100 | [diff] [blame] | 135 | |
Pavel Machek | 56a00ab | 2014-09-09 14:03:28 +0200 | [diff] [blame] | 136 | return 0; |
| 137 | } |
Marek Vasut | 3386c85 | 2018-04-23 22:49:31 +0200 | [diff] [blame^] | 138 | |
| 139 | #ifdef CONFIG_ETH_DESIGNWARE |
| 140 | static int dwmac_phymode_to_modereg(const char *phymode, u32 *modereg) |
| 141 | { |
| 142 | if (!phymode) |
| 143 | return -EINVAL; |
| 144 | |
| 145 | if (!strcmp(phymode, "mii") || !strcmp(phymode, "gmii")) { |
| 146 | *modereg = SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_GMII_MII; |
| 147 | return 0; |
| 148 | } |
| 149 | |
| 150 | if (!strcmp(phymode, "rgmii")) { |
| 151 | *modereg = SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_RGMII; |
| 152 | return 0; |
| 153 | } |
| 154 | |
| 155 | if (!strcmp(phymode, "rmii")) { |
| 156 | *modereg = SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_RMII; |
| 157 | return 0; |
| 158 | } |
| 159 | |
| 160 | return -EINVAL; |
| 161 | } |
| 162 | |
| 163 | int socfpga_eth_reset_common(void (*resetfn)(const u8 of_reset_id, |
| 164 | const u8 phymode)) |
| 165 | { |
| 166 | const void *fdt = gd->fdt_blob; |
| 167 | struct fdtdec_phandle_args args; |
| 168 | const char *phy_mode; |
| 169 | u32 phy_modereg; |
| 170 | int nodes[2]; /* Max. two GMACs */ |
| 171 | int ret, count; |
| 172 | int i, node; |
| 173 | |
| 174 | count = fdtdec_find_aliases_for_id(fdt, "ethernet", |
| 175 | COMPAT_ALTERA_SOCFPGA_DWMAC, |
| 176 | nodes, ARRAY_SIZE(nodes)); |
| 177 | for (i = 0; i < count; i++) { |
| 178 | node = nodes[i]; |
| 179 | if (node <= 0) |
| 180 | continue; |
| 181 | |
| 182 | ret = fdtdec_parse_phandle_with_args(fdt, node, "resets", |
| 183 | "#reset-cells", 1, 0, |
| 184 | &args); |
| 185 | if (ret || (args.args_count != 1)) { |
| 186 | debug("GMAC%i: Failed to parse DT 'resets'!\n", i); |
| 187 | continue; |
| 188 | } |
| 189 | |
| 190 | phy_mode = fdt_getprop(fdt, node, "phy-mode", NULL); |
| 191 | ret = dwmac_phymode_to_modereg(phy_mode, &phy_modereg); |
| 192 | if (ret) { |
| 193 | debug("GMAC%i: Failed to parse DT 'phy-mode'!\n", i); |
| 194 | continue; |
| 195 | } |
| 196 | |
| 197 | resetfn(args.args[0], phy_modereg); |
| 198 | } |
| 199 | |
| 200 | return 0; |
| 201 | } |
| 202 | #endif |