Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2009 |
| 4 | * Marvell Semiconductor <www.marvell.com> |
| 5 | * Written-by: Prafulla Wadaskar <prafulla@marvell.com> |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Simon Glass | 0af6e2d | 2019-08-01 09:46:52 -0600 | [diff] [blame] | 9 | #include <env.h> |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 10 | #include <netdev.h> |
| 11 | #include <asm/cache.h> |
Lei Wen | 298ae91 | 2011-10-18 20:11:42 +0530 | [diff] [blame] | 12 | #include <asm/io.h> |
| 13 | #include <asm/arch/cpu.h> |
Stefan Roese | c243784 | 2014-10-22 12:13:06 +0200 | [diff] [blame] | 14 | #include <asm/arch/soc.h> |
DrEagle | ad88174 | 2014-07-25 21:07:30 +0200 | [diff] [blame] | 15 | #include <mvebu_mmc.h> |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 16 | |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 17 | void reset_cpu(unsigned long ignored) |
| 18 | { |
| 19 | struct kwcpu_registers *cpureg = |
| 20 | (struct kwcpu_registers *)KW_CPU_REG_BASE; |
| 21 | |
| 22 | writel(readl(&cpureg->rstoutn_mask) | (1 << 2), |
| 23 | &cpureg->rstoutn_mask); |
| 24 | writel(readl(&cpureg->sys_soft_rst) | 1, |
| 25 | &cpureg->sys_soft_rst); |
| 26 | while (1) ; |
| 27 | } |
| 28 | |
| 29 | /* |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 30 | * Window Size |
| 31 | * Used with the Base register to set the address window size and location. |
| 32 | * Must be programmed from LSB to MSB as sequence of ones followed by |
| 33 | * sequence of zeros. The number of ones specifies the size of the window in |
| 34 | * 64 KByte granularity (e.g., a value of 0x00FF specifies 256 = 16 MByte). |
| 35 | * NOTE: A value of 0x0 specifies 64-KByte size. |
| 36 | */ |
Prafulla Wadaskar | ecb1b02 | 2009-06-29 20:55:54 +0530 | [diff] [blame] | 37 | unsigned int kw_winctrl_calcsize(unsigned int sizeval) |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 38 | { |
| 39 | int i; |
| 40 | unsigned int j = 0; |
| 41 | u32 val = sizeval >> 1; |
| 42 | |
Prafulla Wadaskar | f9c72f6 | 2010-08-26 14:43:55 +0530 | [diff] [blame] | 43 | for (i = 0; val >= 0x10000; i++) { |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 44 | j |= (1 << i); |
| 45 | val = val >> 1; |
| 46 | } |
| 47 | return (0x0000ffff & j); |
| 48 | } |
| 49 | |
Chris Packham | 968856c | 2019-03-13 20:47:03 +1300 | [diff] [blame] | 50 | static struct mbus_win windows[] = { |
| 51 | /* Window 0: PCIE MEM address space */ |
| 52 | { KW_DEFADR_PCI_MEM, 1024 * 1024 * 256, |
| 53 | KWCPU_TARGET_PCIE, KWCPU_ATTR_PCIE_MEM }, |
| 54 | |
| 55 | /* Window 1: PCIE IO address space */ |
| 56 | { KW_DEFADR_PCI_IO, 1024 * 64, |
| 57 | KWCPU_TARGET_PCIE, KWCPU_ATTR_PCIE_IO }, |
| 58 | |
| 59 | /* Window 2: NAND Flash address space */ |
| 60 | { KW_DEFADR_NANDF, 1024 * 1024 * 128, |
| 61 | KWCPU_TARGET_MEMORY, KWCPU_ATTR_NANDFLASH }, |
| 62 | |
| 63 | /* Window 3: SPI Flash address space */ |
| 64 | { KW_DEFADR_SPIF, 1024 * 1024 * 128, |
| 65 | KWCPU_TARGET_MEMORY, KWCPU_ATTR_SPIFLASH }, |
| 66 | |
| 67 | /* Window 4: BOOT Memory address space */ |
| 68 | { KW_DEFADR_BOOTROM, 1024 * 1024 * 128, |
| 69 | KWCPU_TARGET_MEMORY, KWCPU_ATTR_BOOTROM }, |
| 70 | |
| 71 | /* Window 5: Security SRAM address space */ |
| 72 | { KW_DEFADR_SASRAM, 1024 * 64, |
| 73 | KWCPU_TARGET_SASRAM, KWCPU_ATTR_SASRAM }, |
| 74 | }; |
| 75 | |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 76 | /* |
Prafulla Wadaskar | 2906d77 | 2009-08-20 20:59:28 +0530 | [diff] [blame] | 77 | * SYSRSTn Duration Counter Support |
| 78 | * |
| 79 | * Kirkwood SoC implements a hardware-based SYSRSTn duration counter. |
| 80 | * When SYSRSTn is asserted low, a SYSRSTn duration counter is running. |
| 81 | * The SYSRSTn duration counter is useful for implementing a manufacturer |
| 82 | * or factory reset. Upon a long reset assertion that is greater than a |
| 83 | * pre-configured environment variable value for sysrstdelay, |
| 84 | * The counter value is stored in the SYSRSTn Length Counter Register |
| 85 | * The counter is based on the 25-MHz reference clock (40ns) |
| 86 | * It is a 29-bit counter, yielding a maximum counting duration of |
| 87 | * 2^29/25 MHz (21.4 seconds). When the counter reach its maximum value, |
| 88 | * it remains at this value until counter reset is triggered by setting |
| 89 | * bit 31 of KW_REG_SYSRST_CNT |
| 90 | */ |
| 91 | static void kw_sysrst_action(void) |
| 92 | { |
| 93 | int ret; |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 94 | char *s = env_get("sysrstcmd"); |
Prafulla Wadaskar | 2906d77 | 2009-08-20 20:59:28 +0530 | [diff] [blame] | 95 | |
| 96 | if (!s) { |
| 97 | debug("Error.. %s failed, check sysrstcmd\n", |
| 98 | __FUNCTION__); |
| 99 | return; |
| 100 | } |
| 101 | |
| 102 | debug("Starting %s process...\n", __FUNCTION__); |
Simon Glass | bf8c5b0 | 2012-02-14 19:59:21 +0000 | [diff] [blame] | 103 | ret = run_command(s, 0); |
Thomas Betker | 5ac0026 | 2014-06-05 20:07:56 +0200 | [diff] [blame] | 104 | if (ret != 0) |
Prafulla Wadaskar | 2906d77 | 2009-08-20 20:59:28 +0530 | [diff] [blame] | 105 | debug("Error.. %s failed\n", __FUNCTION__); |
| 106 | else |
| 107 | debug("%s process finished\n", __FUNCTION__); |
| 108 | } |
| 109 | |
| 110 | static void kw_sysrst_check(void) |
| 111 | { |
| 112 | u32 sysrst_cnt, sysrst_dly; |
| 113 | char *s; |
| 114 | |
| 115 | /* |
| 116 | * no action if sysrstdelay environment variable is not defined |
| 117 | */ |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 118 | s = env_get("sysrstdelay"); |
Prafulla Wadaskar | 2906d77 | 2009-08-20 20:59:28 +0530 | [diff] [blame] | 119 | if (s == NULL) |
| 120 | return; |
| 121 | |
| 122 | /* read sysrstdelay value */ |
| 123 | sysrst_dly = (u32) simple_strtoul(s, NULL, 10); |
| 124 | |
| 125 | /* read SysRst Length counter register (bits 28:0) */ |
| 126 | sysrst_cnt = (0x1fffffff & readl(KW_REG_SYSRST_CNT)); |
| 127 | debug("H/w Rst hold time: %d.%d secs\n", |
| 128 | sysrst_cnt / SYSRST_CNT_1SEC_VAL, |
| 129 | sysrst_cnt % SYSRST_CNT_1SEC_VAL); |
| 130 | |
| 131 | /* clear the counter for next valid read*/ |
| 132 | writel(1 << 31, KW_REG_SYSRST_CNT); |
| 133 | |
| 134 | /* |
| 135 | * sysrst_action: |
| 136 | * if H/w Reset key is pressed and hold for time |
| 137 | * more than sysrst_dly in seconds |
| 138 | */ |
| 139 | if (sysrst_cnt >= SYSRST_CNT_1SEC_VAL * sysrst_dly) |
| 140 | kw_sysrst_action(); |
| 141 | } |
| 142 | |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 143 | #if defined(CONFIG_DISPLAY_CPUINFO) |
| 144 | int print_cpuinfo(void) |
| 145 | { |
Luka Perkov | f680edb | 2013-12-23 01:23:07 +0100 | [diff] [blame] | 146 | char *rev = "??"; |
Prafulla Wadaskar | 3149629 | 2010-09-20 17:19:42 +0530 | [diff] [blame] | 147 | u16 devid = (readl(KW_REG_PCIE_DEVID) >> 16) & 0xffff; |
| 148 | u8 revid = readl(KW_REG_PCIE_REVID) & 0xff; |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 149 | |
Prafulla Wadaskar | 3149629 | 2010-09-20 17:19:42 +0530 | [diff] [blame] | 150 | if ((readl(KW_REG_DEVICE_ID) & 0x03) > 2) { |
| 151 | printf("Error.. %s:Unsupported Kirkwood SoC 88F%04x\n", __FUNCTION__, devid); |
| 152 | return -1; |
| 153 | } |
| 154 | |
| 155 | switch (revid) { |
| 156 | case 0: |
Luka Perkov | f680edb | 2013-12-23 01:23:07 +0100 | [diff] [blame] | 157 | if (devid == 0x6281) |
| 158 | rev = "Z0"; |
| 159 | else if (devid == 0x6282) |
| 160 | rev = "A0"; |
| 161 | break; |
| 162 | case 1: |
| 163 | rev = "A1"; |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 164 | break; |
| 165 | case 2: |
Prafulla Wadaskar | 3149629 | 2010-09-20 17:19:42 +0530 | [diff] [blame] | 166 | rev = "A0"; |
| 167 | break; |
| 168 | case 3: |
| 169 | rev = "A1"; |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 170 | break; |
| 171 | default: |
Prafulla Wadaskar | 3149629 | 2010-09-20 17:19:42 +0530 | [diff] [blame] | 172 | break; |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 173 | } |
Prafulla Wadaskar | 3149629 | 2010-09-20 17:19:42 +0530 | [diff] [blame] | 174 | |
| 175 | printf("SoC: Kirkwood 88F%04x_%s\n", devid, rev); |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 176 | return 0; |
| 177 | } |
| 178 | #endif /* CONFIG_DISPLAY_CPUINFO */ |
| 179 | |
| 180 | #ifdef CONFIG_ARCH_CPU_INIT |
| 181 | int arch_cpu_init(void) |
| 182 | { |
| 183 | u32 reg; |
| 184 | struct kwcpu_registers *cpureg = |
| 185 | (struct kwcpu_registers *)KW_CPU_REG_BASE; |
| 186 | |
Chris Packham | 968856c | 2019-03-13 20:47:03 +1300 | [diff] [blame] | 187 | /* Linux expects the internal registers to be at 0xf1000000 */ |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 188 | writel(KW_REGS_PHY_BASE, KW_OFFSET_REG); |
| 189 | |
| 190 | /* Enable and invalidate L2 cache in write through mode */ |
| 191 | writel(readl(&cpureg->l2_cfg) | 0x18, &cpureg->l2_cfg); |
| 192 | invalidate_l2_cache(); |
| 193 | |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 194 | #ifdef CONFIG_KIRKWOOD_RGMII_PAD_1V8 |
| 195 | /* |
| 196 | * Configures the I/O voltage of the pads connected to Egigabit |
| 197 | * Ethernet interface to 1.8V |
Robert P. J. Day | 832d36e | 2013-09-16 07:15:45 -0400 | [diff] [blame] | 198 | * By default it is set to 3.3V |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 199 | */ |
| 200 | reg = readl(KW_REG_MPP_OUT_DRV_REG); |
| 201 | reg |= (1 << 7); |
| 202 | writel(reg, KW_REG_MPP_OUT_DRV_REG); |
| 203 | #endif |
| 204 | #ifdef CONFIG_KIRKWOOD_EGIGA_INIT |
| 205 | /* |
| 206 | * Set egiga port0/1 in normal functional mode |
| 207 | * This is required becasue on kirkwood by default ports are in reset mode |
| 208 | * OS egiga driver may not have provision to set them in normal mode |
| 209 | * and if u-boot is build without network support, network may fail at OS level |
| 210 | */ |
| 211 | reg = readl(KWGBE_PORT_SERIAL_CONTROL1_REG(0)); |
| 212 | reg &= ~(1 << 4); /* Clear PortReset Bit */ |
| 213 | writel(reg, (KWGBE_PORT_SERIAL_CONTROL1_REG(0))); |
| 214 | reg = readl(KWGBE_PORT_SERIAL_CONTROL1_REG(1)); |
| 215 | reg &= ~(1 << 4); /* Clear PortReset Bit */ |
| 216 | writel(reg, (KWGBE_PORT_SERIAL_CONTROL1_REG(1))); |
| 217 | #endif |
| 218 | #ifdef CONFIG_KIRKWOOD_PCIE_INIT |
| 219 | /* |
| 220 | * Enable PCI Express Port0 |
| 221 | */ |
| 222 | reg = readl(&cpureg->ctrl_stat); |
| 223 | reg |= (1 << 0); /* Set PEX0En Bit */ |
| 224 | writel(reg, &cpureg->ctrl_stat); |
| 225 | #endif |
| 226 | return 0; |
| 227 | } |
| 228 | #endif /* CONFIG_ARCH_CPU_INIT */ |
| 229 | |
| 230 | /* |
| 231 | * SOC specific misc init |
| 232 | */ |
| 233 | #if defined(CONFIG_ARCH_MISC_INIT) |
| 234 | int arch_misc_init(void) |
| 235 | { |
| 236 | volatile u32 temp; |
| 237 | |
| 238 | /*CPU streaming & write allocate */ |
| 239 | temp = readfr_extra_feature_reg(); |
| 240 | temp &= ~(1 << 28); /* disable wr alloc */ |
| 241 | writefr_extra_feature_reg(temp); |
| 242 | |
| 243 | temp = readfr_extra_feature_reg(); |
| 244 | temp &= ~(1 << 29); /* streaming disabled */ |
| 245 | writefr_extra_feature_reg(temp); |
| 246 | |
| 247 | /* L2Cache settings */ |
| 248 | temp = readfr_extra_feature_reg(); |
| 249 | /* Disable L2C pre fetch - Set bit 24 */ |
| 250 | temp |= (1 << 24); |
| 251 | /* enable L2C - Set bit 22 */ |
| 252 | temp |= (1 << 22); |
| 253 | writefr_extra_feature_reg(temp); |
| 254 | |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 255 | /* Change reset vector to address 0x0 */ |
| 256 | temp = get_cr(); |
| 257 | set_cr(temp & ~CR_V); |
| 258 | |
Chris Packham | 968856c | 2019-03-13 20:47:03 +1300 | [diff] [blame] | 259 | /* Configure mbus windows */ |
| 260 | mvebu_mbus_probe(windows, ARRAY_SIZE(windows)); |
| 261 | |
Prafulla Wadaskar | 2906d77 | 2009-08-20 20:59:28 +0530 | [diff] [blame] | 262 | /* checks and execute resset to factory event */ |
| 263 | kw_sysrst_check(); |
| 264 | |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 265 | return 0; |
| 266 | } |
| 267 | #endif /* CONFIG_ARCH_MISC_INIT */ |
| 268 | |
Albert Aribaud | e91d7d3 | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 269 | #ifdef CONFIG_MVGBE |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 270 | int cpu_eth_init(bd_t *bis) |
| 271 | { |
Albert Aribaud | e91d7d3 | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 272 | mvgbe_initialize(bis); |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 273 | return 0; |
| 274 | } |
| 275 | #endif |
DrEagle | ad88174 | 2014-07-25 21:07:30 +0200 | [diff] [blame] | 276 | |
| 277 | #ifdef CONFIG_MVEBU_MMC |
| 278 | int board_mmc_init(bd_t *bis) |
| 279 | { |
| 280 | mvebu_mmc_init(bis); |
| 281 | return 0; |
| 282 | } |
| 283 | #endif /* CONFIG_MVEBU_MMC */ |