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