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